From 68d862b3c2ff97cc58d3265fc720551e750d5a73 Mon Sep 17 00:00:00 2001 From: Jehan Date: Sun, 5 Feb 2023 22:55:37 +0100 Subject: [PATCH] app: fully get rid of gimp_action_get_accel_closure(). All the remaining pieces of code where the deprecated concept of accelerator closure was still used have now been replaced by proper GimpAction API using the newer GAction API. --- app/actions/debug-commands.c | 68 ++++++--------- app/widgets/gimpaction.c | 6 -- app/widgets/gimpaction.h | 2 - app/widgets/gimpsearchpopup.c | 101 +++++------------------ app/widgets/gimptoolbox-color-area.c | 19 +---- app/widgets/gimpwidgets-utils.c | 118 ++++++++++----------------- 6 files changed, 90 insertions(+), 224 deletions(-) diff --git a/app/actions/debug-commands.c b/app/actions/debug-commands.c index fbcd24f80a..9f15512676 100644 --- a/app/actions/debug-commands.c +++ b/app/actions/debug-commands.c @@ -64,10 +64,6 @@ static void debug_print_qdata_foreach (GQuark key_id, gpointer data, gpointer user_data); -static gboolean debug_accel_find_func (GtkAccelKey *key, - GClosure *closure, - gpointer data); - /* public functions */ @@ -193,19 +189,16 @@ debug_dump_keyboard_shortcuts_cmd_callback (GimpAction *action, GVariant *value, gpointer data) { - GimpDisplay *display; - GimpImageWindow *window; - GimpUIManager *manager; - GtkAccelGroup *accel_group; - GList *group_it; - GList *strings = NULL; + GimpDisplay *display; + GimpImageWindow *window; + GimpUIManager *manager; + GList *group_it; + GList *strings = NULL; return_if_no_display (display, data); window = gimp_display_shell_get_window (gimp_display_get_shell (display)); manager = gimp_image_window_get_ui_manager (window); - accel_group = gimp_ui_manager_get_accel_group (manager); - /* Gather formatted strings of keyboard shortcuts */ for (group_it = gimp_ui_manager_get_action_groups (manager); group_it; @@ -220,43 +213,36 @@ debug_dump_keyboard_shortcuts_cmd_callback (GimpAction *action, for (action_it = actions; action_it; action_it = g_list_next (action_it)) { - GimpAction *action = action_it->data; - const gchar *name = gimp_action_get_name (action); - GClosure *accel_closure = NULL; + gchar **accels; + GimpAction *action = action_it->data; + const gchar *name = gimp_action_get_name (action); if (strstr (name, "-menu") || strstr (name, "-popup") || name[0] == '<') continue; - accel_closure = gimp_action_get_accel_closure (action); + accels = gimp_action_get_display_accels (action); - if (accel_closure) + if (accels && accels[0]) { - GtkAccelKey *key = gtk_accel_group_find (accel_group, - debug_accel_find_func, - accel_closure); - if (key && - key->accel_key && - key->accel_flags & GTK_ACCEL_VISIBLE) - { - const gchar *label_tmp; - gchar *label; - gchar *key_string; + const gchar *label_tmp; + gchar *label; - label_tmp = gimp_action_get_label (action); - label = gimp_strip_uline (label_tmp); - key_string = gtk_accelerator_get_label (key->accel_key, - key->accel_mods); + label_tmp = gimp_action_get_label (action); + label = gimp_strip_uline (label_tmp); - strings = g_list_prepend (strings, - g_strdup_printf ("%-20s %s", - key_string, label)); + strings = g_list_prepend (strings, + g_strdup_printf ("%-20s %s", + accels[0], label)); - g_free (key_string); - g_free (label); - } + g_free (label); + + for (gint i = 1; accels[i] != NULL; i++) + strings = g_list_prepend (strings, g_strdup (accels[i])); } + + g_strfreev (accels); } g_list_free (actions); @@ -436,11 +422,3 @@ debug_print_qdata_foreach (GQuark key_id, { g_print ("%s: %p\n", g_quark_to_string (key_id), data); } - -static gboolean -debug_accel_find_func (GtkAccelKey *key, - GClosure *closure, - gpointer data) -{ - return (GClosure *) data == closure; -} diff --git a/app/widgets/gimpaction.c b/app/widgets/gimpaction.c index 35a78dd78d..8691b6d8e3 100644 --- a/app/widgets/gimpaction.c +++ b/app/widgets/gimpaction.c @@ -385,12 +385,6 @@ gimp_action_is_sensitive (GimpAction *action, return sensitive; } -GClosure * -gimp_action_get_accel_closure (GimpAction *action) -{ - return gtk_action_get_accel_closure ((GtkAction *) action); -} - void gimp_action_set_accel_path (GimpAction *action, const gchar *accel_path) diff --git a/app/widgets/gimpaction.h b/app/widgets/gimpaction.h index 6aca00a652..c15d5e2ff9 100644 --- a/app/widgets/gimpaction.h +++ b/app/widgets/gimpaction.h @@ -103,8 +103,6 @@ gboolean gimp_action_get_sensitive (GimpAction *action, gboolean gimp_action_is_sensitive (GimpAction *action, const gchar **reason); -GClosure * gimp_action_get_accel_closure (GimpAction *action); - void gimp_action_set_accel_path (GimpAction *action, const gchar *accel_path); const gchar * gimp_action_get_accel_path (GimpAction *action); diff --git a/app/widgets/gimpsearchpopup.c b/app/widgets/gimpsearchpopup.c index 1fc8323eb5..7e82899f96 100644 --- a/app/widgets/gimpsearchpopup.c +++ b/app/widgets/gimpsearchpopup.c @@ -36,7 +36,6 @@ #include "gimppopup.h" #include "gimpsearchpopup.h" #include "gimptoggleaction.h" -#include "gimpuimanager.h" #include "gimp-intl.h" @@ -110,11 +109,6 @@ static void gimp_search_popup_run_selected (GimpSearchPopup *pop static void gimp_search_popup_setup_results (GtkWidget **results_list, GtkWidget **list_view); -static gchar * gimp_search_popup_find_accel_label (GimpAction *action); -static gboolean gimp_search_popup_view_accel_find_func (GtkAccelKey *key, - GClosure *closure, - gpointer data); - G_DEFINE_TYPE_WITH_PRIVATE (GimpSearchPopup, gimp_search_popup, GIMP_TYPE_POPUP) @@ -229,24 +223,24 @@ gimp_search_popup_add_result (GimpSearchPopup *popup, GimpAction *action, gint section) { - GtkTreeIter iter; - GtkTreeIter next_section; - GtkListStore *store; - GtkTreeModel *model; - gchar *markup; - gchar *action_name; - gchar *label; - gchar *escaped_label = NULL; - const gchar *icon_name; - gchar *accel_string; - gchar *escaped_accel = NULL; - gboolean has_shortcut = FALSE; - const gchar *tooltip; - gchar *escaped_tooltip = NULL; - gboolean has_tooltip = FALSE; - gboolean sensitive = FALSE; - const gchar *sensitive_reason = NULL; - gchar *escaped_reason = NULL; + gchar **accels; + GtkTreeIter iter; + GtkTreeIter next_section; + GtkListStore *store; + GtkTreeModel *model; + gchar *markup; + gchar *action_name; + gchar *label; + gchar *escaped_label = NULL; + const gchar *icon_name; + gchar *escaped_accel = NULL; + gboolean has_shortcut = FALSE; + const gchar *tooltip; + gchar *escaped_tooltip = NULL; + gboolean has_tooltip = FALSE; + gboolean sensitive = FALSE; + const gchar *sensitive_reason = NULL; + gchar *escaped_reason = NULL; label = g_strstrip (gimp_strip_uline (gimp_action_get_label (action))); @@ -270,12 +264,13 @@ gimp_search_popup_add_result (GimpSearchPopup *popup, icon_name = gimp_action_get_icon_name (action); } - accel_string = gimp_search_popup_find_accel_label (action); - if (accel_string) + accels = gimp_action_get_display_accels (action); + if (accels && accels[0]) { - escaped_accel = g_markup_escape_text (accel_string, -1); + escaped_accel = g_markup_escape_text (accels[0], -1); has_shortcut = TRUE; } + g_strfreev (accels); tooltip = gimp_action_get_tooltip (action); if (tooltip != NULL) @@ -341,7 +336,6 @@ gimp_search_popup_add_result (GimpSearchPopup *popup, COLUMN_SENSITIVE, sensitive, -1); - g_free (accel_string); g_free (markup); g_free (action_name); g_free (label); @@ -745,54 +739,3 @@ gimp_search_popup_setup_results (GtkWidget **results_list, gtk_container_add (GTK_CONTAINER (*list_view), *results_list); g_object_unref (G_OBJECT (store)); } - -static gchar * -gimp_search_popup_find_accel_label (GimpAction *action) -{ - guint accel_key = 0; - GdkModifierType accel_mask = 0; - GClosure *accel_closure = NULL; - gchar *accel_string; - GtkAccelGroup *accel_group; - GimpUIManager *manager; - - manager = gimp_ui_managers_from_name ("")->data; - accel_group = gimp_ui_manager_get_accel_group (manager); - accel_closure = gimp_action_get_accel_closure (action); - - if (accel_closure) - { - GtkAccelKey *key; - - key = gtk_accel_group_find (accel_group, - gimp_search_popup_view_accel_find_func, - accel_closure); - if (key && - key->accel_key && - key->accel_flags & GTK_ACCEL_VISIBLE) - { - accel_key = key->accel_key; - accel_mask = key->accel_mods; - } - } - - accel_string = gtk_accelerator_get_label (accel_key, accel_mask); - - if (strcmp (g_strstrip (accel_string), "") == 0) - { - /* The value returned by gtk_accelerator_get_label() must be - * freed after use. - */ - g_clear_pointer (&accel_string, g_free); - } - - return accel_string; -} - -static gboolean -gimp_search_popup_view_accel_find_func (GtkAccelKey *key, - GClosure *closure, - gpointer data) -{ - return (GClosure *) data == closure; -} diff --git a/app/widgets/gimptoolbox-color-area.c b/app/widgets/gimptoolbox-color-area.c index 93c85b7370..de93a1421c 100644 --- a/app/widgets/gimptoolbox-color-area.c +++ b/app/widgets/gimptoolbox-color-area.c @@ -328,25 +328,14 @@ color_area_tooltip (GimpFgBgEditor *editor, if (action) { - gchar **accels = gimp_action_get_accels (action); + gchar **accels = gimp_action_get_display_accels (action); if (accels && accels[0]) { - guint accel_key = 0; - GdkModifierType accel_mods = 0; + gchar *escaped = g_markup_escape_text (text, -1); - gtk_accelerator_parse (accels[0], &accel_key, &accel_mods); - - if (accel_key != 0 || accel_mods != 0) - { - gchar *escaped = g_markup_escape_text (text, -1); - gchar *accel; - - accel = gtk_accelerator_get_label (accel_key, accel_mods); - markup = g_strdup_printf ("%s %s", escaped, accel); - g_free (escaped); - g_free (accel); - } + markup = g_strdup_printf ("%s %s", escaped, accels[0]); + g_free (escaped); } g_strfreev (accels); diff --git a/app/widgets/gimpwidgets-utils.c b/app/widgets/gimpwidgets-utils.c index e4dfdb4d11..14315e73ec 100644 --- a/app/widgets/gimpwidgets-utils.c +++ b/app/widgets/gimpwidgets-utils.c @@ -996,60 +996,30 @@ gimp_window_set_transient_for (GtkWindow *window, #endif } -static gboolean -gimp_widget_accel_find_func (GtkAccelKey *key, - GClosure *closure, - gpointer data) -{ - return (GClosure *) data == closure; -} - static void -gimp_widget_accel_changed (GtkAccelGroup *accel_group, - guint unused1, - GdkModifierType unused2, - GClosure *accel_closure, - GtkWidget *widget) +gimp_widget_accels_changed (GimpAction *action, + const gchar **accels, + GtkWidget *widget) { - GClosure *widget_closure; + const gchar *tooltip; + const gchar *help_id; - widget_closure = g_object_get_data (G_OBJECT (widget), "gimp-accel-closure"); + tooltip = gimp_action_get_tooltip (action); + help_id = gimp_action_get_help_id (action); - if (accel_closure == widget_closure) + if (accels && accels[0]) { - GimpAction *action; - GtkAccelKey *accel_key; - const gchar *tooltip; - const gchar *help_id; + gchar *escaped = g_markup_escape_text (tooltip, -1); + gchar *tmp = g_strdup_printf ("%s %s", escaped, accels[0]); - action = g_object_get_data (G_OBJECT (widget), "gimp-accel-action"); + g_free (escaped); - tooltip = gimp_action_get_tooltip (action); - help_id = gimp_action_get_help_id (action); - - accel_key = gtk_accel_group_find (accel_group, - gimp_widget_accel_find_func, - accel_closure); - - if (accel_key && - accel_key->accel_key && - (accel_key->accel_flags & GTK_ACCEL_VISIBLE)) - { - gchar *escaped = g_markup_escape_text (tooltip, -1); - gchar *accel = gtk_accelerator_get_label (accel_key->accel_key, - accel_key->accel_mods); - gchar *tmp = g_strdup_printf ("%s %s", escaped, accel); - - g_free (accel); - g_free (escaped); - - gimp_help_set_help_data_with_markup (widget, tmp, help_id); - g_free (tmp); - } - else - { - gimp_help_set_help_data (widget, tooltip, help_id); - } + gimp_help_set_help_data_with_markup (widget, tmp, help_id); + g_free (tmp); + } + else + { + gimp_help_set_help_data (widget, tooltip, help_id); } } @@ -1058,20 +1028,20 @@ static void gimp_accel_help_widget_weak_notify (gpointer accel_group, static void gimp_accel_help_accel_group_weak_notify (gpointer widget, - GObject *where_accel_group_was) + GObject *where_action_was) { g_object_weak_unref (widget, gimp_accel_help_widget_weak_notify, - where_accel_group_was); + where_action_was); - g_object_set_data (widget, "gimp-accel-group", NULL); + g_object_set_data (widget, "gimp-accel-help-action", NULL); } static void -gimp_accel_help_widget_weak_notify (gpointer accel_group, +gimp_accel_help_widget_weak_notify (gpointer action, GObject *where_widget_was) { - g_object_weak_unref (accel_group, + g_object_weak_unref (action, gimp_accel_help_accel_group_weak_notify, where_widget_was); } @@ -1080,53 +1050,47 @@ void gimp_widget_set_accel_help (GtkWidget *widget, GimpAction *action) { - GtkAccelGroup *accel_group; - GClosure *accel_closure; + GimpAction *prev_action; - accel_group = g_object_get_data (G_OBJECT (widget), "gimp-accel-group"); + prev_action = g_object_get_data (G_OBJECT (widget), "gimp-accel-help-action"); - if (accel_group) + if (prev_action) { - g_signal_handlers_disconnect_by_func (accel_group, - gimp_widget_accel_changed, + g_signal_handlers_disconnect_by_func (prev_action, + gimp_widget_accels_changed, widget); - g_object_weak_unref (G_OBJECT (accel_group), + g_object_weak_unref (G_OBJECT (action), gimp_accel_help_accel_group_weak_notify, widget); g_object_weak_unref (G_OBJECT (widget), gimp_accel_help_widget_weak_notify, - accel_group); - g_object_set_data (G_OBJECT (widget), "gimp-accel-group", NULL); + action); + g_object_set_data (G_OBJECT (widget), "gimp-accel-help-action", NULL); } - accel_closure = gimp_action_get_accel_closure (action); - - if (accel_closure) + if (action) { - accel_group = gtk_accel_group_from_accel_closure (accel_closure); + gchar **accels; - g_object_set_data (G_OBJECT (widget), "gimp-accel-group", - accel_group); - g_object_weak_ref (G_OBJECT (accel_group), + g_object_set_data (G_OBJECT (widget), "gimp-accel-help-action", + action); + g_object_weak_ref (G_OBJECT (action), gimp_accel_help_accel_group_weak_notify, widget); g_object_weak_ref (G_OBJECT (widget), gimp_accel_help_widget_weak_notify, - accel_group); + action); - g_object_set_data (G_OBJECT (widget), "gimp-accel-closure", - accel_closure); g_object_set_data (G_OBJECT (widget), "gimp-accel-action", action); - g_signal_connect_object (accel_group, "accel-changed", - G_CALLBACK (gimp_widget_accel_changed), + g_signal_connect_object (action, "accels-changed", + G_CALLBACK (gimp_widget_accels_changed), widget, 0); - gimp_widget_accel_changed (accel_group, - 0, 0, - accel_closure, - widget); + accels = gimp_action_get_display_accels (action); + gimp_widget_accels_changed (action, (const gchar **) accels, widget); + g_strfreev (accels); } else {