[libdazzle] util: add helper to set action state
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libdazzle] util: add helper to set action state
- Date: Thu, 22 Jun 2017 03:13:22 +0000 (UTC)
commit 9101367ee2d32206a88f6fd82a0470681af09ee9
Author: Christian Hergert <chergert redhat com>
Date: Wed Jun 21 20:13:11 2017 -0700
util: add helper to set action state
This looks up the action based on resolving from the given widget. If we
find the action, we attempt to set properties on it based on the va_list
we get passed to us.
src/util/dzl-gtk.c | 39 +++++++++++++++++++++++++++++++++++++++
src/util/dzl-gtk.h | 5 +++++
2 files changed, 44 insertions(+), 0 deletions(-)
---
diff --git a/src/util/dzl-gtk.c b/src/util/dzl-gtk.c
index e737668..1386714 100644
--- a/src/util/dzl-gtk.c
+++ b/src/util/dzl-gtk.c
@@ -328,3 +328,42 @@ dzl_gtk_widget_add_style_class (GtkWidget *widget,
gtk_style_context_add_class (gtk_widget_get_style_context (widget), class_name);
}
+
+void
+dzl_gtk_widget_action_set (GtkWidget *widget,
+ const gchar *group,
+ const gchar *name,
+ const gchar *first_property,
+ ...)
+{
+ GAction *action = NULL;
+ va_list args;
+
+ g_return_if_fail (GTK_IS_WIDGET (widget));
+ g_return_if_fail (group != NULL);
+ g_return_if_fail (name != NULL);
+ g_return_if_fail (first_property != NULL);
+
+ for (; widget; widget = gtk_widget_get_parent (widget))
+ {
+ GActionGroup *actions = gtk_widget_get_action_group (widget, group);
+
+ if (G_IS_ACTION_MAP (actions))
+ {
+ action = g_action_map_lookup_action (G_ACTION_MAP (actions), name);
+
+ if (action != NULL)
+ break;
+ }
+ }
+
+ if (action == NULL)
+ {
+ g_warning ("Failed to locate action %s.%s", group, name);
+ return;
+ }
+
+ va_start (args, first_property);
+ g_object_set_valist (G_OBJECT (action), first_property, args);
+ va_end (args);
+}
diff --git a/src/util/dzl-gtk.h b/src/util/dzl-gtk.h
index 697b8f8..e507e10 100644
--- a/src/util/dzl-gtk.h
+++ b/src/util/dzl-gtk.h
@@ -23,6 +23,11 @@
G_BEGIN_DECLS
+void dzl_gtk_widget_action_set (GtkWidget *widget,
+ const gchar *group,
+ const gchar *name,
+ const gchar *first_property,
+ ...) G_GNUC_NULL_TERMINATED;
gboolean dzl_gtk_widget_action (GtkWidget *widget,
const gchar *group,
const gchar *name,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]