widget: add helpers to resolve GActionGroups available to GtkWidget

These functions, while added for use by the GTK inspector, are generally
useful to applications that need to resolve what action groups are
available to a particular GtkWidget.

https://bugzilla.gnome.org/show_bug.cgi?id=741386
This commit is contained in:
Christian Hergert 2014-12-11 15:25:41 -08:00
parent ab5b0d0983
commit 661da5558c
8 changed files with 52 additions and 15 deletions

View File

@ -5543,6 +5543,8 @@ gtk_widget_get_modifier_mask
gtk_widget_insert_action_group
gtk_widget_get_opacity
gtk_widget_set_opacity
gtk_widget_list_action_prefixes
gtk_widget_get_action_group
<SUBSECTION>
gtk_widget_get_path

View File

@ -732,10 +732,10 @@ gtk_action_muxer_remove (GtkActionMuxer *muxer,
}
}
gchar **
const gchar **
gtk_action_muxer_list_prefixes (GtkActionMuxer *muxer)
{
return (gchar **) g_hash_table_get_keys_as_array (muxer->groups, NULL);
return (const gchar **) g_hash_table_get_keys_as_array (muxer->groups, NULL);
}
GActionGroup *

View File

@ -41,7 +41,7 @@ void gtk_action_muxer_insert (GtkActi
void gtk_action_muxer_remove (GtkActionMuxer *muxer,
const gchar *prefix);
gchar ** gtk_action_muxer_list_prefixes (GtkActionMuxer *muxer);
const gchar ** gtk_action_muxer_list_prefixes (GtkActionMuxer *muxer);
GActionGroup * gtk_action_muxer_lookup (GtkActionMuxer *muxer,
const gchar *prefix);
GtkActionMuxer * gtk_action_muxer_get_parent (GtkActionMuxer *muxer);

View File

@ -17037,18 +17037,49 @@ gtk_widget_get_template_child (GtkWidget *widget,
return ret;
}
gchar **
_gtk_widget_list_action_prefixes (GtkWidget *widget)
/**
* 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.
*
* Since: 3.16
*/
const gchar **
gtk_widget_list_action_prefixes (GtkWidget *widget)
{
g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
if (widget->priv->muxer)
return gtk_action_muxer_list_prefixes (widget->priv->muxer);
return NULL;
return gtk_action_muxer_list_prefixes (widget->priv->muxer);
return g_new0 (const gchar *, 0 + 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.
*
* Since: 3.16
*/
GActionGroup *
_gtk_widget_get_action_group (GtkWidget *widget,
const gchar *prefix)
gtk_widget_get_action_group (GtkWidget *widget,
const gchar *prefix)
{
g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
g_return_val_if_fail (prefix, NULL);
if (widget->priv->muxer)
return gtk_action_muxer_lookup (widget->priv->muxer, prefix);
return NULL;

View File

@ -1475,6 +1475,13 @@ void gtk_widget_class_bind_template_child_full (GtkWidgetClass *
gboolean internal_child,
gssize struct_offset);
GDK_AVAILABLE_IN_3_16
GActionGroup *gtk_widget_get_action_group (GtkWidget *widget,
const gchar *prefix);
GDK_AVAILABLE_IN_3_16
const gchar ** gtk_widget_list_action_prefixes (GtkWidget *widget);
G_END_DECLS
#endif /* __GTK_WIDGET_H__ */

View File

@ -153,9 +153,6 @@ void _gtk_widget_style_context_invalidated (GtkWidget *widget
void _gtk_widget_update_parent_muxer (GtkWidget *widget);
GtkActionMuxer * _gtk_widget_get_action_muxer (GtkWidget *widget,
gboolean create);
gchar ** _gtk_widget_list_action_prefixes (GtkWidget *widget);
GActionGroup * _gtk_widget_get_action_group (GtkWidget *widget,
const gchar *prefix);
void _gtk_widget_add_controller (GtkWidget *widget,
GtkEventController *controller);

View File

@ -220,12 +220,12 @@ gtk_inspector_actions_set_object (GtkInspectorActions *sl,
GActionGroup *group;
gint i;
prefixes = _gtk_widget_list_action_prefixes (GTK_WIDGET (object));
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]);
group = gtk_widget_get_action_group (GTK_WIDGET (object), prefixes[i]);
add_group (sl, group, prefixes[i]);
}
g_free (prefixes);

View File

@ -1262,7 +1262,7 @@ find_action_owner (GtkActionable *actionable)
while (widget != NULL)
{
group = _gtk_widget_get_action_group (widget, prefix);
group = gtk_widget_get_action_group (widget, prefix);
if (group && g_action_group_has_action (group, name))
return (GObject *)widget;
widget = action_ancestor (widget);