diff --git a/docs/reference/gtk/gtk4-sections.txt b/docs/reference/gtk/gtk4-sections.txt index 4d072641da..786bcde361 100644 --- a/docs/reference/gtk/gtk4-sections.txt +++ b/docs/reference/gtk/gtk4-sections.txt @@ -4551,7 +4551,6 @@ gtk_widget_get_overflow gtk_widget_set_overflow gtk_widget_insert_action_group gtk_widget_list_action_prefixes -gtk_widget_get_action_group gtk_widget_activate_action gtk_widget_activate_default gtk_widget_measure diff --git a/gtk/gtkactionmuxer.c b/gtk/gtkactionmuxer.c index 72edec793b..5020f69359 100644 --- a/gtk/gtkactionmuxer.c +++ b/gtk/gtkactionmuxer.c @@ -102,13 +102,10 @@ typedef struct } Group; static void -gtk_action_muxer_append_group_actions (gpointer key, - gpointer value, - gpointer user_data) +gtk_action_muxer_append_group_actions (const char *prefix, + Group *group, + GArray *actions) { - const gchar *prefix = key; - Group *group = value; - GArray *actions = user_data; gchar **group_actions; gchar **action; @@ -134,9 +131,13 @@ gtk_action_muxer_list_actions (GActionGroup *action_group) for ( ; muxer != NULL; muxer = muxer->parent) { - g_hash_table_foreach (muxer->groups, - gtk_action_muxer_append_group_actions, - actions); + GHashTableIter iter; + const char *prefix; + Group *group; + + g_hash_table_iter_init (&iter, muxer->groups); + while (g_hash_table_iter_next (&iter, (gpointer *)&prefix, (gpointer *)&group)) + gtk_action_muxer_append_group_actions (prefix, group, actions); } return (gchar **)(void *) g_array_free (actions, FALSE); @@ -166,6 +167,18 @@ gtk_action_muxer_find_group (GtkActionMuxer *muxer, return group; } +GActionGroup * +gtk_action_muxer_find (GtkActionMuxer *muxer, + const char *action_name, + const char **unprefixed_name) +{ + Group *group; + + group = gtk_action_muxer_find_group (muxer, action_name, unprefixed_name); + + return group->group; +} + static void gtk_action_muxer_action_enabled_changed (GtkActionMuxer *muxer, const gchar *action_name, @@ -742,12 +755,6 @@ gtk_action_muxer_remove (GtkActionMuxer *muxer, } } -const gchar ** -gtk_action_muxer_list_prefixes (GtkActionMuxer *muxer) -{ - return (const gchar **) g_hash_table_get_keys_as_array (muxer->groups, NULL); -} - GActionGroup * gtk_action_muxer_lookup (GtkActionMuxer *muxer, const gchar *prefix) @@ -959,3 +966,4 @@ gtk_normalise_detailed_action_name (const gchar *detailed_action_name) return action_and_target; } + diff --git a/gtk/gtkactionmuxerprivate.h b/gtk/gtkactionmuxerprivate.h index b696fff29e..01b6f14bd1 100644 --- a/gtk/gtkactionmuxerprivate.h +++ b/gtk/gtkactionmuxerprivate.h @@ -41,9 +41,11 @@ void gtk_action_muxer_insert (GtkActi void gtk_action_muxer_remove (GtkActionMuxer *muxer, const gchar *prefix); -const gchar ** gtk_action_muxer_list_prefixes (GtkActionMuxer *muxer); GActionGroup * gtk_action_muxer_lookup (GtkActionMuxer *muxer, const gchar *prefix); +GActionGroup * gtk_action_muxer_find (GtkActionMuxer *muxer, + const char *action_name, + const char **unprefixed_name); GtkActionMuxer * gtk_action_muxer_get_parent (GtkActionMuxer *muxer); void gtk_action_muxer_set_parent (GtkActionMuxer *muxer, diff --git a/gtk/gtkentry.c b/gtk/gtkentry.c index 878cfee2f3..b746537ba4 100644 --- a/gtk/gtkentry.c +++ b/gtk/gtkentry.c @@ -3477,8 +3477,6 @@ set_show_emoji_icon (GtkEntry *entry, gboolean value) { GtkEntryPrivate *priv = gtk_entry_get_instance_private (entry); - GActionGroup *actions; - GAction *action; if (priv->show_emoji_icon == value) return; @@ -3520,12 +3518,6 @@ set_show_emoji_icon (GtkEntry *entry, g_object_notify_by_pspec (G_OBJECT (entry), entry_props[PROP_SHOW_EMOJI_ICON]); gtk_widget_queue_resize (GTK_WIDGET (entry)); - - actions = gtk_widget_get_action_group (priv->text, "context"); - action = g_action_map_lookup_action (G_ACTION_MAP (actions), "insert-emoji"); - g_simple_action_set_enabled (G_SIMPLE_ACTION (action), - priv->show_emoji_icon || - (gtk_entry_get_input_hints (entry) & GTK_INPUT_HINT_NO_EMOJI) == 0); } GtkEventController * diff --git a/gtk/gtkfilechooserwidget.c b/gtk/gtkfilechooserwidget.c index bb68a75fb5..9c40a24fce 100644 --- a/gtk/gtkfilechooserwidget.c +++ b/gtk/gtkfilechooserwidget.c @@ -228,6 +228,8 @@ struct _GtkFileChooserWidgetPrivate { GtkWidget *box; + GActionGroup *item_actions; + /* Save mode widgets */ GtkWidget *save_widgets; GtkWidget *save_widgets_table; @@ -678,6 +680,8 @@ gtk_file_chooser_widget_finalize (GObject *object) GtkFileChooserWidget *impl = GTK_FILE_CHOOSER_WIDGET (object); GtkFileChooserWidgetPrivate *priv = gtk_file_chooser_widget_get_instance_private (impl); + g_clear_object (&priv->item_actions); + g_clear_pointer (&priv->choices, g_hash_table_unref); if (priv->location_changed_id > 0) @@ -2004,28 +2008,25 @@ check_file_list_popover_sensitivity (GtkFileChooserWidget *impl) gboolean all_files; gboolean all_folders; gboolean active; - GActionGroup *actions; GAction *action, *action2; - actions = gtk_widget_get_action_group (priv->browse_files_tree_view, "item"); - selection_check (impl, &num_selected, &all_files, &all_folders); active = (num_selected != 0); - action = g_action_map_lookup_action (G_ACTION_MAP (actions), "copy-location"); + action = g_action_map_lookup_action (G_ACTION_MAP (priv->item_actions), "copy-location"); g_simple_action_set_enabled (G_SIMPLE_ACTION (action), active); - action = g_action_map_lookup_action (G_ACTION_MAP (actions), "add-shortcut"); + action = g_action_map_lookup_action (G_ACTION_MAP (priv->item_actions), "add-shortcut"); g_simple_action_set_enabled (G_SIMPLE_ACTION (action), active && all_folders); - action = g_action_map_lookup_action (G_ACTION_MAP (actions), "visit"); + action = g_action_map_lookup_action (G_ACTION_MAP (priv->item_actions), "visit"); g_simple_action_set_enabled (G_SIMPLE_ACTION (action), active); - action = g_action_map_lookup_action (G_ACTION_MAP (actions), "open"); + action = g_action_map_lookup_action (G_ACTION_MAP (priv->item_actions), "open"); g_simple_action_set_enabled (G_SIMPLE_ACTION (action), (num_selected == 1) && all_folders); - action = g_action_map_lookup_action (G_ACTION_MAP (actions), "rename"); + action = g_action_map_lookup_action (G_ACTION_MAP (priv->item_actions), "rename"); if (num_selected == 1) { GSList *infos; @@ -2042,8 +2043,8 @@ check_file_list_popover_sensitivity (GtkFileChooserWidget *impl) else g_simple_action_set_enabled (G_SIMPLE_ACTION (action), FALSE); - action = g_action_map_lookup_action (G_ACTION_MAP (actions), "delete"); - action2 = g_action_map_lookup_action (G_ACTION_MAP (actions), "trash"); + action = g_action_map_lookup_action (G_ACTION_MAP (priv->item_actions), "delete"); + action2 = g_action_map_lookup_action (G_ACTION_MAP (priv->item_actions), "trash"); if (num_selected == 1) { @@ -2100,14 +2101,13 @@ static void add_actions (GtkFileChooserWidget *impl) { GtkFileChooserWidgetPrivate *priv = gtk_file_chooser_widget_get_instance_private (impl); - GActionGroup *actions; - actions = G_ACTION_GROUP (g_simple_action_group_new ()); - g_action_map_add_action_entries (G_ACTION_MAP (actions), + priv->item_actions = G_ACTION_GROUP (g_simple_action_group_new ()); + g_action_map_add_action_entries (G_ACTION_MAP (priv->item_actions), entries, G_N_ELEMENTS (entries), impl); - gtk_widget_insert_action_group (GTK_WIDGET (priv->browse_files_tree_view), "item", actions); - g_object_unref (actions); + gtk_widget_insert_action_group (GTK_WIDGET (priv->browse_files_tree_view), "item", + priv->item_actions); } static GtkWidget * @@ -2181,7 +2181,6 @@ static void file_list_update_popover (GtkFileChooserWidget *impl) { GtkFileChooserWidgetPrivate *priv = gtk_file_chooser_widget_get_instance_private (impl); - GActionGroup *actions; GAction *action; file_list_build_popover (impl); @@ -2202,17 +2201,16 @@ file_list_update_popover (GtkFileChooserWidget *impl) gtk_widget_set_visible (priv->visit_file_item, (priv->operation_mode != OPERATION_MODE_BROWSE)); - actions = gtk_widget_get_action_group (priv->browse_files_tree_view, "item"); - action = g_action_map_lookup_action (G_ACTION_MAP (actions), "toggle-show-hidden"); + action = g_action_map_lookup_action (G_ACTION_MAP (priv->item_actions), "toggle-show-hidden"); g_simple_action_set_state (G_SIMPLE_ACTION (action), g_variant_new_boolean (priv->show_hidden)); - action = g_action_map_lookup_action (G_ACTION_MAP (actions), "toggle-show-size"); + action = g_action_map_lookup_action (G_ACTION_MAP (priv->item_actions), "toggle-show-size"); g_simple_action_set_state (G_SIMPLE_ACTION (action), g_variant_new_boolean (priv->show_size_column)); - action = g_action_map_lookup_action (G_ACTION_MAP (actions), "toggle-show-time"); + action = g_action_map_lookup_action (G_ACTION_MAP (priv->item_actions), "toggle-show-time"); g_simple_action_set_state (G_SIMPLE_ACTION (action), g_variant_new_boolean (priv->show_time)); - action = g_action_map_lookup_action (G_ACTION_MAP (actions), "toggle-sort-dirs-first"); + action = g_action_map_lookup_action (G_ACTION_MAP (priv->item_actions), "toggle-sort-dirs-first"); g_simple_action_set_state (G_SIMPLE_ACTION (action), g_variant_new_boolean (priv->sort_directories_first)); } diff --git a/gtk/gtkmenutrackeritem.c b/gtk/gtkmenutrackeritem.c index 3cd4796e16..0dc27598c6 100644 --- a/gtk/gtkmenutrackeritem.c +++ b/gtk/gtkmenutrackeritem.c @@ -551,7 +551,7 @@ _gtk_menu_tracker_item_new (GtkActionObservable *observable, if (found) { GTK_NOTE(ACTIONS, g_message ("menutracker: action %s existed from the start", action_name)); - gtk_menu_tracker_item_action_added (GTK_ACTION_OBSERVER (self), observable, NULL, parameter_type, enabled, state); + gtk_menu_tracker_item_action_added (GTK_ACTION_OBSERVER (self), observable, action_name, parameter_type, enabled, state); } else { diff --git a/gtk/gtkplacessidebar.c b/gtk/gtkplacessidebar.c index ca88963440..25e99fa37a 100644 --- a/gtk/gtkplacessidebar.c +++ b/gtk/gtkplacessidebar.c @@ -128,6 +128,8 @@ struct _GtkPlacesSidebar { GtkBookmarksManager *bookmarks_manager; + GActionGroup *row_actions; + #ifdef HAVE_CLOUDPROVIDERS CloudProvidersCollector *cloud_manager; GList *unready_accounts; @@ -2247,8 +2249,7 @@ check_popover_sensitivity (GtkSidebarRow *row, GDrive *drive; GVolume *volume; GMount *mount; - GtkWidget *sidebar; - GActionGroup *actions; + GtkPlacesSidebar *sidebar; GAction *action; g_object_get (row, @@ -2261,13 +2262,12 @@ check_popover_sensitivity (GtkSidebarRow *row, gtk_widget_set_visible (data->add_shortcut_item, (type == PLACES_MOUNTED_VOLUME)); - actions = gtk_widget_get_action_group (sidebar, "row"); - action = g_action_map_lookup_action (G_ACTION_MAP (actions), "remove"); + action = g_action_map_lookup_action (G_ACTION_MAP (sidebar->row_actions), "remove"); g_simple_action_set_enabled (G_SIMPLE_ACTION (action), (type == PLACES_BOOKMARK)); - action = g_action_map_lookup_action (G_ACTION_MAP (actions), "rename"); + action = g_action_map_lookup_action (G_ACTION_MAP (sidebar->row_actions), "rename"); g_simple_action_set_enabled (G_SIMPLE_ACTION (action), (type == PLACES_BOOKMARK || type == PLACES_XDG_DIR)); - action = g_action_map_lookup_action (G_ACTION_MAP (actions), "open"); + action = g_action_map_lookup_action (G_ACTION_MAP (sidebar->row_actions), "open"); g_simple_action_set_enabled (G_SIMPLE_ACTION (action), !gtk_list_box_row_is_selected (GTK_LIST_BOX_ROW (row))); check_visibility (mount, volume, drive, @@ -3479,14 +3479,11 @@ static GActionEntry entries[] = { static void add_actions (GtkPlacesSidebar *sidebar) { - GActionGroup *actions; - - actions = G_ACTION_GROUP (g_simple_action_group_new ()); - g_action_map_add_action_entries (G_ACTION_MAP (actions), + sidebar->row_actions = G_ACTION_GROUP (g_simple_action_group_new ()); + g_action_map_add_action_entries (G_ACTION_MAP (sidebar->row_actions), entries, G_N_ELEMENTS (entries), sidebar); - gtk_widget_insert_action_group (GTK_WIDGET (sidebar), "row", actions); - g_object_unref (actions); + gtk_widget_insert_action_group (GTK_WIDGET (sidebar), "row", sidebar->row_actions); } static GtkWidget * @@ -4375,6 +4372,8 @@ gtk_places_sidebar_finalize (GObject *object) { GtkPlacesSidebar *sidebar = GTK_PLACES_SIDEBAR (object); + g_clear_object (&sidebar->row_actions); + #ifdef HAVE_CLOUDPROVIDERS g_clear_object (&sidebar->cloud_manager); #endif diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c index 0bc88b06b2..532aecb3cb 100644 --- a/gtk/gtkwidget.c +++ b/gtk/gtkwidget.c @@ -12413,58 +12413,6 @@ gtk_widget_get_template_child (GtkWidget *widget, return ret; } -/** - * gtk_widget_list_action_prefixes: - * @widget: A #GtkWidget - * - * Retrieves a %NULL-terminated array of strings containing the prefixes of - * #GActionGroup's available to @widget. - * - * Returns: (transfer container): a %NULL-terminated array of strings. - */ -const gchar ** -gtk_widget_list_action_prefixes (GtkWidget *widget) -{ - GtkActionMuxer *muxer; - - g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL); - - muxer = _gtk_widget_get_action_muxer (widget, FALSE); - if (muxer) - return gtk_action_muxer_list_prefixes (muxer); - - return g_new0 (const gchar *, 1); -} - -/** - * gtk_widget_get_action_group: - * @widget: A #GtkWidget - * @prefix: The “prefix” of the action group. - * - * Retrieves the #GActionGroup that was registered using @prefix. The resulting - * #GActionGroup may have been registered to @widget or any #GtkWidget in its - * ancestry. - * - * If no action group was found matching @prefix, then %NULL is returned. - * - * Returns: (transfer none) (nullable): A #GActionGroup or %NULL. - */ -GActionGroup * -gtk_widget_get_action_group (GtkWidget *widget, - const gchar *prefix) -{ - GtkActionMuxer *muxer; - - g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL); - g_return_val_if_fail (prefix, NULL); - - muxer = _gtk_widget_get_action_muxer (widget, FALSE); - if (muxer) - return gtk_action_muxer_lookup (muxer, prefix); - - return NULL; -} - /** * gtk_widget_activate_action: * @widget: a #GtkWidget diff --git a/gtk/gtkwidget.h b/gtk/gtkwidget.h index bb2766078b..ca9d768ea6 100644 --- a/gtk/gtkwidget.h +++ b/gtk/gtkwidget.h @@ -833,11 +833,6 @@ GDK_AVAILABLE_IN_ALL GdkModifierType gtk_widget_get_modifier_mask (GtkWidget *widget, GdkModifierIntent intent); -GDK_AVAILABLE_IN_ALL -void gtk_widget_insert_action_group (GtkWidget *widget, - const gchar *name, - GActionGroup *group); - GDK_AVAILABLE_IN_ALL guint gtk_widget_add_tick_callback (GtkWidget *widget, GtkTickCallback callback, @@ -976,11 +971,9 @@ void gtk_widget_class_bind_template_child_full (GtkWidgetClass * gssize struct_offset); GDK_AVAILABLE_IN_ALL -GActionGroup *gtk_widget_get_action_group (GtkWidget *widget, - const gchar *prefix); - -GDK_AVAILABLE_IN_ALL -const gchar ** gtk_widget_list_action_prefixes (GtkWidget *widget); +void gtk_widget_insert_action_group (GtkWidget *widget, + const gchar *name, + GActionGroup *group); GDK_AVAILABLE_IN_ALL void gtk_widget_activate_action (GtkWidget *widget, diff --git a/gtk/inspector/action-editor.c b/gtk/inspector/action-editor.c index 7919296cfc..74fefefa71 100644 --- a/gtk/inspector/action-editor.c +++ b/gtk/inspector/action-editor.c @@ -29,7 +29,6 @@ struct _GtkInspectorActionEditorPrivate { GActionGroup *group; - gchar *prefix; gchar *name; gboolean enabled; const GVariantType *parameter_type; @@ -319,7 +318,6 @@ finalize (GObject *object) { GtkInspectorActionEditor *r = GTK_INSPECTOR_ACTION_EDITOR (object); - g_free (r->priv->prefix); g_free (r->priv->name); g_object_unref (r->priv->sg); if (r->priv->state_type) @@ -344,10 +342,6 @@ get_property (GObject *object, g_value_set_object (value, r->priv->group); break; - case PROP_PREFIX: - g_value_set_string (value, r->priv->prefix); - break; - case PROP_NAME: g_value_set_string (value, r->priv->name); break; @@ -376,18 +370,13 @@ set_property (GObject *object, r->priv->group = g_value_get_object (value); break; - case PROP_PREFIX: - g_free (r->priv->prefix); - r->priv->prefix = g_value_dup_string (value); - break; - case PROP_NAME: g_free (r->priv->name); r->priv->name = g_value_dup_string (value); break; case PROP_SIZEGROUP: - r->priv->sg = g_value_get_object (value); + r->priv->sg = g_value_dup_object (value); break; default: @@ -410,10 +399,6 @@ gtk_inspector_action_editor_class_init (GtkInspectorActionEditorClass *klass) g_param_spec_object ("group", "Action Group", "The Action Group containing the action", G_TYPE_ACTION_GROUP, G_PARAM_READWRITE|G_PARAM_CONSTRUCT)); - g_object_class_install_property (object_class, PROP_PREFIX, - g_param_spec_string ("prefix", "Prefix", "The action name prefix", - NULL, G_PARAM_READWRITE|G_PARAM_CONSTRUCT)); - g_object_class_install_property (object_class, PROP_NAME, g_param_spec_string ("name", "Name", "The action name", NULL, G_PARAM_READWRITE|G_PARAM_CONSTRUCT)); @@ -424,13 +409,11 @@ gtk_inspector_action_editor_class_init (GtkInspectorActionEditorClass *klass) GtkWidget * gtk_inspector_action_editor_new (GActionGroup *group, - const gchar *prefix, const gchar *name, GtkSizeGroup *activate) { return g_object_new (GTK_TYPE_INSPECTOR_ACTION_EDITOR, "group", group, - "prefix", prefix, "name", name, "sizegroup", activate, NULL); diff --git a/gtk/inspector/action-editor.h b/gtk/inspector/action-editor.h index 097ae12707..bc234ac798 100644 --- a/gtk/inspector/action-editor.h +++ b/gtk/inspector/action-editor.h @@ -49,7 +49,6 @@ G_BEGIN_DECLS GType gtk_inspector_action_editor_get_type (void); GtkWidget *gtk_inspector_action_editor_new (GActionGroup *group, - const gchar *prefix, const gchar *name, GtkSizeGroup *activate); diff --git a/gtk/inspector/actions.c b/gtk/inspector/actions.c index c6a9c92000..ac4ddbee43 100644 --- a/gtk/inspector/actions.c +++ b/gtk/inspector/actions.c @@ -26,6 +26,7 @@ #include "gtktreeview.h" #include "gtkliststore.h" #include "gtkwidgetprivate.h" +#include "gtkactionmuxerprivate.h" #include "gtkpopover.h" #include "gtklabel.h" #include "gtkstack.h" @@ -33,26 +34,15 @@ #include "gtkstylecontext.h" #include "gtksizegroup.h" -enum -{ - COLUMN_PREFIX, - COLUMN_NAME, - COLUMN_ENABLED, - COLUMN_PARAMETER, - COLUMN_STATE, - COLUMN_GROUP -}; - struct _GtkInspectorActionsPrivate { GtkWidget *list; - GtkSizeGroup *prefix; GtkSizeGroup *name; GtkSizeGroup *enabled; GtkSizeGroup *parameter; GtkSizeGroup *state; GtkSizeGroup *activate; - GHashTable *groups; + GActionGroup *group; }; G_DEFINE_TYPE_WITH_PRIVATE (GtkInspectorActions, gtk_inspector_actions, GTK_TYPE_BOX) @@ -61,17 +51,12 @@ static void gtk_inspector_actions_init (GtkInspectorActions *sl) { sl->priv = gtk_inspector_actions_get_instance_private (sl); - sl->priv->groups = g_hash_table_new_full (g_direct_hash, - g_direct_equal, - NULL, - g_free); gtk_widget_init_template (GTK_WIDGET (sl)); } static void add_action (GtkInspectorActions *sl, GActionGroup *group, - const gchar *prefix, const gchar *name) { gboolean enabled; @@ -81,7 +66,7 @@ add_action (GtkInspectorActions *sl, GtkWidget *row; GtkWidget *label; GtkWidget *box; - char *key = g_strconcat (prefix, ".", name, NULL); + char *key = g_strdup (name); GtkWidget *editor; enabled = g_action_group_get_action_enabled (group, name); @@ -99,12 +84,6 @@ add_action (GtkInspectorActions *sl, box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); gtk_container_add (GTK_CONTAINER (row), box); - label = gtk_label_new (prefix); - gtk_style_context_add_class (gtk_widget_get_style_context (label), "cell"); - gtk_label_set_xalign (GTK_LABEL (label), 0); - gtk_size_group_add_widget (sl->priv->prefix, label); - gtk_container_add (GTK_CONTAINER (box), label); - label = gtk_label_new (name); gtk_style_context_add_class (gtk_widget_get_style_context (label), "cell"); gtk_label_set_xalign (GTK_LABEL (label), 0); @@ -132,7 +111,7 @@ add_action (GtkInspectorActions *sl, gtk_container_add (GTK_CONTAINER (box), label); g_object_set_data (G_OBJECT (row), "state", label); - editor = gtk_inspector_action_editor_new (group, prefix, name, sl->priv->activate); + editor = gtk_inspector_action_editor_new (group, name, sl->priv->activate); gtk_style_context_add_class (gtk_widget_get_style_context (editor), "cell"); gtk_container_add (GTK_CONTAINER (box), editor); @@ -143,27 +122,23 @@ add_action (GtkInspectorActions *sl, static GtkWidget * find_row (GtkInspectorActions *sl, - const char *prefix, const char *action_name) { GtkWidget *row = NULL; GtkWidget *widget; - char *key = g_strconcat (prefix, ".", action_name, NULL); for (widget = gtk_widget_get_first_child (sl->priv->list); widget; widget = gtk_widget_get_next_sibling (widget)) { - const char *rkey = g_object_get_data (G_OBJECT (widget), "key"); - if (g_str_equal (key, rkey)) + const char *key = g_object_get_data (G_OBJECT (widget), "key"); + if (g_str_equal (key, action_name)) { row = widget; break; } } - g_free (key); - return row; } @@ -172,9 +147,7 @@ action_added_cb (GActionGroup *group, const gchar *action_name, GtkInspectorActions *sl) { - const gchar *prefix; - prefix = g_hash_table_lookup (sl->priv->groups, group); - add_action (sl, group, prefix, action_name); + add_action (sl, group, action_name); } static void @@ -182,13 +155,11 @@ action_removed_cb (GActionGroup *group, const gchar *action_name, GtkInspectorActions *sl) { - const gchar *prefix; GtkWidget *row; - prefix = g_hash_table_lookup (sl->priv->groups, group); - row = find_row (sl, prefix, action_name); + row = find_row (sl, action_name); if (row) - gtk_container_remove (GTK_CONTAINER (sl->priv->list), row); + gtk_widget_destroy (row); } static void @@ -197,13 +168,10 @@ action_enabled_changed_cb (GActionGroup *group, gboolean enabled, GtkInspectorActions *sl) { - const gchar *prefix; GtkWidget *row; GtkWidget *label; - prefix = g_hash_table_lookup (sl->priv->groups, group); - - row = find_row (sl, prefix, action_name); + row = find_row (sl, action_name); label = GTK_WIDGET (g_object_get_data (G_OBJECT (row), "enabled")); gtk_label_set_label (GTK_LABEL (label), enabled ? "+" : "-" ); } @@ -214,14 +182,11 @@ action_state_changed_cb (GActionGroup *group, GVariant *state, GtkInspectorActions *sl) { - const gchar *prefix; gchar *state_string; GtkWidget *row; GtkWidget *label; - prefix = g_hash_table_lookup (sl->priv->groups, group); - - row = find_row (sl, prefix, action_name); + row = find_row (sl, action_name); if (state) state_string = g_variant_print (state, FALSE); else @@ -231,39 +196,56 @@ action_state_changed_cb (GActionGroup *group, g_free (state_string); } +static void +connect_group (GActionGroup *group, + GtkInspectorActions *sl) +{ + g_signal_connect (group, "action-added", G_CALLBACK (action_added_cb), sl); + g_signal_connect (group, "action-removed", G_CALLBACK (action_removed_cb), sl); + g_signal_connect (group, "action-enabled-changed", G_CALLBACK (action_enabled_changed_cb), sl); + g_signal_connect (group, "action-state-changed", G_CALLBACK (action_state_changed_cb), sl); +} + +static void +disconnect_group (GActionGroup *group, + GtkInspectorActions *sl) +{ + g_signal_handlers_disconnect_by_func (group, action_added_cb, sl); + g_signal_handlers_disconnect_by_func (group, action_removed_cb, sl); + g_signal_handlers_disconnect_by_func (group, action_enabled_changed_cb, sl); + g_signal_handlers_disconnect_by_func (group, action_state_changed_cb, sl); +} + static void add_group (GtkInspectorActions *sl, GtkStackPage *page, - GActionGroup *group, - const gchar *prefix) + GActionGroup *group) { gint i; gchar **names; g_object_set (page, "visible", TRUE, NULL); - g_signal_connect (group, "action-added", G_CALLBACK (action_added_cb), sl); - g_signal_connect (group, "action-removed", G_CALLBACK (action_removed_cb), sl); - g_signal_connect (group, "action-enabled-changed", G_CALLBACK (action_enabled_changed_cb), sl); - g_signal_connect (group, "action-state-changed", G_CALLBACK (action_state_changed_cb), sl); - g_hash_table_insert (sl->priv->groups, group, g_strdup (prefix)); + connect_group (group, sl); names = g_action_group_list_actions (group); for (i = 0; names[i]; i++) - add_action (sl, group, prefix, names[i]); + add_action (sl, group, names[i]); g_strfreev (names); + + g_set_object (&sl->priv->group, group); } static void -disconnect_group (gpointer key, gpointer value, gpointer data) +remove_group (GtkInspectorActions *sl, + GtkStackPage *page, + GActionGroup *group) { - GActionGroup *group = key; - GtkInspectorActions *sl = data; + g_object_set (page, "visible", FALSE, NULL); - g_signal_handlers_disconnect_by_func (group, action_added_cb, sl); - g_signal_handlers_disconnect_by_func (group, action_removed_cb, sl); - g_signal_handlers_disconnect_by_func (group, action_enabled_changed_cb, sl); - g_signal_handlers_disconnect_by_func (group, action_state_changed_cb, sl); + disconnect_group (group, sl); + + g_set_object (&sl->priv->group, NULL); } void @@ -272,32 +254,25 @@ gtk_inspector_actions_set_object (GtkInspectorActions *sl, { GtkWidget *stack; GtkStackPage *page; + GtkWidget *child; stack = gtk_widget_get_parent (GTK_WIDGET (sl)); page = gtk_stack_get_page (GTK_STACK (stack), GTK_WIDGET (sl)); - g_object_set (page, "visible", FALSE, NULL); - g_hash_table_foreach (sl->priv->groups, disconnect_group, sl); - g_hash_table_remove_all (sl->priv->groups); + remove_group (sl, page, sl->priv->group); + + while ((child = gtk_widget_get_first_child (sl->priv->list))) + gtk_widget_destroy (child); if (GTK_IS_APPLICATION (object)) - add_group (sl, page, G_ACTION_GROUP (object), "app"); + add_group (sl, page, G_ACTION_GROUP (object)); else if (GTK_IS_WIDGET (object)) { - const gchar **prefixes; - GActionGroup *group; - gint i; + GtkActionMuxer *muxer; - prefixes = gtk_widget_list_action_prefixes (GTK_WIDGET (object)); - if (prefixes) - { - for (i = 0; prefixes[i]; i++) - { - group = gtk_widget_get_action_group (GTK_WIDGET (object), prefixes[i]); - add_group (sl, page, group, prefixes[i]); - } - g_free (prefixes); - } + muxer = _gtk_widget_get_action_muxer (GTK_WIDGET (object), FALSE); + if (muxer) + add_group (sl, page, G_ACTION_GROUP (muxer)); } } @@ -308,7 +283,6 @@ gtk_inspector_actions_class_init (GtkInspectorActionsClass *klass) gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/libgtk/inspector/actions.ui"); gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorActions, list); - gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorActions, prefix); gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorActions, name); gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorActions, enabled); gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorActions, parameter); diff --git a/gtk/inspector/actions.ui b/gtk/inspector/actions.ui index 33ba5d58ad..7ec69d18f2 100644 --- a/gtk/inspector/actions.ui +++ b/gtk/inspector/actions.ui @@ -20,12 +20,6 @@ - - - Prefix - 0 - - Name @@ -73,12 +67,6 @@ - - horizontal - - - - horizontal diff --git a/gtk/inspector/prop-editor.c b/gtk/inspector/prop-editor.c index 1c0573fc42..b44a2c177b 100644 --- a/gtk/inspector/prop-editor.c +++ b/gtk/inspector/prop-editor.c @@ -1255,8 +1255,6 @@ action_ancestor (GtkWidget *widget) { if (GTK_IS_MENU (widget)) return gtk_menu_get_attach_widget (GTK_MENU (widget)); - else if (GTK_IS_POPOVER (widget)) - return gtk_popover_get_relative_to (GTK_POPOVER (widget)); else return gtk_widget_get_parent (widget); } @@ -1266,41 +1264,36 @@ find_action_owner (GtkActionable *actionable) { GtkWidget *widget = GTK_WIDGET (actionable); const gchar *full_name; - const gchar *dot; - const gchar *name; - gchar *prefix; GtkWidget *win; - GActionGroup *group; full_name = gtk_actionable_get_action_name (actionable); if (!full_name) return NULL; - dot = strchr (full_name, '.'); - prefix = g_strndup (full_name, dot - full_name); - name = dot + 1; - win = gtk_widget_get_ancestor (widget, GTK_TYPE_APPLICATION_WINDOW); - if (g_strcmp0 (prefix, "win") == 0) + if (g_str_has_prefix (full_name, "win.") == 0) { if (G_IS_OBJECT (win)) return (GObject *)win; } - else if (g_strcmp0 (prefix, "app") == 0) - { + else if (g_str_has_prefix (full_name, "app.") == 0) + { if (GTK_IS_WINDOW (win)) return (GObject *)gtk_window_get_application (GTK_WINDOW (win)); } while (widget != NULL) { - group = gtk_widget_get_action_group (widget, prefix); - if (group && g_action_group_has_action (group, name)) + GtkActionMuxer *muxer; + + muxer = _gtk_widget_get_action_muxer (widget, FALSE); + if (muxer && gtk_action_muxer_find (muxer, full_name, NULL)) return (GObject *)widget; + widget = action_ancestor (widget); } - return NULL; + return NULL; } static void