[gtk+] actionable: Allow all detailed action name formats



commit 29d1cc2fcd43bd4d929243f8cc8dc0adbcb5428a
Author: Christian Persch <chpe src gnome org>
Date:   Wed Oct 11 20:43:19 2017 +0200

    actionable: Allow all detailed action name formats
    
    Use g_action_parse_detailed_name() to enable use of this API
    for actions with non-string parameter.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=788841

 gtk/gtkactionable.c |   36 +++++++++++++++++++-----------------
 1 files changed, 19 insertions(+), 17 deletions(-)
---
diff --git a/gtk/gtkactionable.c b/gtk/gtkactionable.c
index 0d4d610..e515af2 100644
--- a/gtk/gtkactionable.c
+++ b/gtk/gtkactionable.c
@@ -224,14 +224,14 @@ gtk_actionable_set_action_target (GtkActionable *actionable,
  * Sets the action-name and associated string target value of an
  * actionable widget.
  *
- * This allows for the effect of both gtk_actionable_set_action_name()
- * and gtk_actionable_set_action_target_value() in the common case that
- * the target is string-valued.
+ * @detailed_action_name is a string in the format accepted by
+ * g_action_parse_detailed_name().
  *
- * @detailed_action_name is a string of the form
- * `"action::target"` where `action`
- * is the action name and `target` is the string to use
- * as the target.
+ * (Note that prior to version 3.22.25,
+ * this function is only usable for actions with a simple "s" target, and
+ * @detailed_action_name must be of the form `"action::target"` where
+ * `action` is the action name and `target` is the string to use
+ * as the target.)
  *
  * Since: 3.4
  **/
@@ -239,9 +239,9 @@ void
 gtk_actionable_set_detailed_action_name (GtkActionable *actionable,
                                          const gchar   *detailed_action_name)
 {
-  gchar **parts;
-
-  g_return_if_fail (GTK_IS_ACTIONABLE (actionable));
+  GError *error = NULL;
+  GVariant *target;
+  gchar *name;
 
   if (detailed_action_name == NULL)
     {
@@ -250,12 +250,14 @@ gtk_actionable_set_detailed_action_name (GtkActionable *actionable,
       return;
     }
 
-  parts = g_strsplit (detailed_action_name, "::", 2);
-  gtk_actionable_set_action_name (actionable, parts[0]);
-  if (parts[0] && parts[1])
-    gtk_actionable_set_action_target (actionable, "s", parts[1]);
-  else
-    gtk_actionable_set_action_target_value (actionable, NULL);
-  g_strfreev (parts);
+  if (!g_action_parse_detailed_name (detailed_action_name, &name, &target, &error))
+    g_error ("gtk_actionable_set_detailed_action_name: %s", error->message);
+
+  gtk_actionable_set_action_name (actionable, name);
+  gtk_actionable_set_action_target_value (actionable, target);
+
+  if (target)
+    g_variant_unref (target);
+  g_free (name);
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]