[gnome-builder/wip/commands2] commands: try harder to locate a named GAction.



commit dc15442c5e61b311ed9eff5dfae4a212ba7a11b3
Author: Christian Hergert <christian hergert me>
Date:   Fri Oct 10 14:52:00 2014 -0700

    commands: try harder to locate a named GAction.
    
    This still *really* needs new API in Gtk+ to be able to resolve an action
    in the same way that gtkactionhelper does (using the muxer and whatnot).

 src/commands/gb-command-gaction-provider.c |   45 ++++++++++++++++++++++++++-
 1 files changed, 43 insertions(+), 2 deletions(-)
---
diff --git a/src/commands/gb-command-gaction-provider.c b/src/commands/gb-command-gaction-provider.c
index 29510fd..d8d235a 100644
--- a/src/commands/gb-command-gaction-provider.c
+++ b/src/commands/gb-command-gaction-provider.c
@@ -21,6 +21,7 @@
 #include <string.h>
 
 #include "gb-command-gaction-provider.h"
+#include "gb-log.h"
 
 G_DEFINE_TYPE (GbCommandGactionProvider, gb_command_gaction_provider,
                GB_TYPE_COMMAND_PROVIDER)
@@ -65,6 +66,8 @@ gb_command_gaction_provider_lookup (GbCommandProvider *provider,
   gchar *tmp;
   gchar *name = NULL;
 
+  ENTRY;
+
   g_return_val_if_fail (GB_IS_COMMAND_GACTION_PROVIDER (self), NULL);
 
   /* Determine the command name */
@@ -90,7 +93,7 @@ gb_command_gaction_provider_lookup (GbCommandProvider *provider,
     {
       parameters = g_variant_parse (NULL, command_text, NULL, NULL, NULL);
       if (!parameters)
-        goto cleanup;
+        GOTO (cleanup);
     }
 
   /*
@@ -115,6 +118,44 @@ gb_command_gaction_provider_lookup (GbCommandProvider *provider,
     }
 
   /*
+   * Now try to lookup the action from the workspace up, which is the case if
+   * we don't have an active tab.
+   */
+  if (!action)
+    {
+      GbWorkbench *workbench;
+      GbWorkspace *workspace;
+
+      workbench = gb_command_provider_get_workbench (provider);
+      workspace = gb_workbench_get_active_workspace (workbench);
+      widget = GTK_WIDGET (workspace);
+
+      while (widget)
+        {
+          if (G_IS_ACTION_MAP (widget))
+            {
+              action = g_action_map_lookup_action (G_ACTION_MAP (widget), name);
+              if (action)
+                break;
+            }
+          else if (GB_IS_WORKSPACE (widget))
+            {
+              GActionGroup *group;
+
+              group = gb_workspace_get_actions (GB_WORKSPACE (widget));
+              if (G_IS_ACTION_MAP (group))
+                {
+                  action = g_action_map_lookup_action (G_ACTION_MAP (group), name);
+                  if (action)
+                    break;
+                }
+            }
+
+          widget = gtk_widget_get_parent (widget);
+        }
+    }
+
+  /*
    * Now try to lookup the action inside of the GApplication.
    * This is useful for stuff like "quit", and "preferences".
    */
@@ -147,7 +188,7 @@ gb_command_gaction_provider_lookup (GbCommandProvider *provider,
 cleanup:
   g_free (name);
 
-  return command;
+  RETURN (command);
 }
 
 static void


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