summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Hergert <christian@hergert.me>2014-12-11 15:25:41 -0800
committerChristian Hergert <christian@hergert.me>2014-12-11 15:25:41 -0800
commit661da5558c14520070174b0fd65f1a9c508f4ca4 (patch)
treeb65f23c6c4193150ce284ca576dee8b6a4cd1f81
parentab5b0d098365c5fb156959d16edecfccf2cc61c2 (diff)
downloadgtk+-661da5558c14520070174b0fd65f1a9c508f4ca4.tar.gz
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
-rw-r--r--docs/reference/gtk/gtk3-sections.txt2
-rw-r--r--gtk/gtkactionmuxer.c4
-rw-r--r--gtk/gtkactionmuxer.h2
-rw-r--r--gtk/gtkwidget.c43
-rw-r--r--gtk/gtkwidget.h7
-rw-r--r--gtk/gtkwidgetprivate.h3
-rw-r--r--gtk/inspector/actions.c4
-rw-r--r--gtk/inspector/prop-editor.c2
8 files changed, 52 insertions, 15 deletions
diff --git a/docs/reference/gtk/gtk3-sections.txt b/docs/reference/gtk/gtk3-sections.txt
index fb93d29a26..857d0fb2ec 100644
--- a/docs/reference/gtk/gtk3-sections.txt
+++ b/docs/reference/gtk/gtk3-sections.txt
@@ -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
diff --git a/gtk/gtkactionmuxer.c b/gtk/gtkactionmuxer.c
index a1dc9f8110..408973bc2f 100644
--- a/gtk/gtkactionmuxer.c
+++ b/gtk/gtkactionmuxer.c
@@ -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 *
diff --git a/gtk/gtkactionmuxer.h b/gtk/gtkactionmuxer.h
index 94b7491409..39e9bf2cce 100644
--- a/gtk/gtkactionmuxer.h
+++ b/gtk/gtkactionmuxer.h
@@ -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);
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 50ca98bf11..4d54206464 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -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;
diff --git a/gtk/gtkwidget.h b/gtk/gtkwidget.h
index ca961a0727..450cd1968e 100644
--- a/gtk/gtkwidget.h
+++ b/gtk/gtkwidget.h
@@ -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__ */
diff --git a/gtk/gtkwidgetprivate.h b/gtk/gtkwidgetprivate.h
index 6fd7a63346..48c9f8cdf4 100644
--- a/gtk/gtkwidgetprivate.h
+++ b/gtk/gtkwidgetprivate.h
@@ -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);
diff --git a/gtk/inspector/actions.c b/gtk/inspector/actions.c
index 7899bcf09e..ff8e2e1dc0 100644
--- a/gtk/inspector/actions.c
+++ b/gtk/inspector/actions.c
@@ -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);
diff --git a/gtk/inspector/prop-editor.c b/gtk/inspector/prop-editor.c
index 3649e78bfd..8a28539114 100644
--- a/gtk/inspector/prop-editor.c
+++ b/gtk/inspector/prop-editor.c
@@ -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);