[gnome-builder] workspace: remove get_actions() vfunc



commit 2143926a1db3d4751ca88de3ae94f712ca73bad0
Author: Christian Hergert <christian hergert me>
Date:   Sun Dec 14 02:09:25 2014 -0800

    workspace: remove get_actions() vfunc
    
    This can all be simplified now that we can get action groups back out of
    a gtk+ widget. We still have lots of code cleanup to do, but this gets
    us started.

 src/editor/gb-editor-frame.c             |   37 +++--------------------
 src/editor/gb-editor-workspace-private.h |   38 ------------------------
 src/editor/gb-editor-workspace.c         |   41 ++++++++++++++------------
 src/gnome-builder.mk                     |    1 -
 src/resources/gtk/menus.ui               |    2 +-
 src/resources/keybindings/default.ini    |    8 ++---
 src/resources/ui/gb-workbench.ui         |    2 +-
 src/workbench/gb-workbench.c             |   46 ++++++------------------------
 src/workbench/gb-workspace.c             |   21 -------------
 src/workbench/gb-workspace.h             |    3 --
 10 files changed, 41 insertions(+), 158 deletions(-)
---
diff --git a/src/editor/gb-editor-frame.c b/src/editor/gb-editor-frame.c
index 6133a9c..1ba39a7 100644
--- a/src/editor/gb-editor-frame.c
+++ b/src/editor/gb-editor-frame.c
@@ -899,10 +899,8 @@ gb_editor_frame_on_jump_to_doc (GbEditorFrame *frame,
                                 const gchar   *search_text,
                                 GbSourceView  *source_view)
 {
+  GActionGroup *action_group;
   GbWorkbench *workbench;
-  GAction *action;
-  GVariant *params;
-  GtkWidget *parent;
 
   ENTRY;
 
@@ -911,35 +909,10 @@ gb_editor_frame_on_jump_to_doc (GbEditorFrame *frame,
   g_return_if_fail (search_text);
 
   workbench = gb_widget_get_workbench (GTK_WIDGET (frame));
-  if (!workbench)
-    EXIT;
-
-  parent = GTK_WIDGET (frame);
-
-  /*
-   * TODO: I really want this to all just work by searching for muxed actions
-   *       in Gtk+ directly. Matthias has some patches and Ryan needs to
-   *       review them. This all becomes easier then.
-   */
-
-  while (parent && !GB_IS_EDITOR_WORKSPACE (parent))
-    parent = gtk_widget_get_parent (parent);
-
-  if (GB_IS_EDITOR_WORKSPACE (parent))
-    {
-      GActionGroup *group;
-
-      group = gb_workspace_get_actions (GB_WORKSPACE (parent));
-      action = g_action_map_lookup_action (G_ACTION_MAP (group),
-                                           "jump-to-doc");
-      if (!action)
-        EXIT;
-
-      params = g_variant_new_string (search_text);
-      g_action_activate (action, params);
-
-      EXIT;
-    }
+  action_group = gtk_widget_get_action_group (GTK_WIDGET (workbench),
+                                              "workspace");
+  g_action_group_activate_action (action_group, "jump-to-doc",
+                                  g_variant_new_string (search_text));
 
   EXIT;
 }
diff --git a/src/editor/gb-editor-workspace.c b/src/editor/gb-editor-workspace.c
index d4da8e4..99061b6 100644
--- a/src/editor/gb-editor-workspace.c
+++ b/src/editor/gb-editor-workspace.c
@@ -23,11 +23,18 @@
 
 #include "gb-devhelp-document.h"
 #include "gb-devhelp-view.h"
+#include "gb-document-grid.h"
 #include "gb-editor-document.h"
 #include "gb-editor-workspace.h"
-#include "gb-editor-workspace-private.h"
 #include "gb-tree.h"
 
+struct _GbEditorWorkspacePrivate
+{
+  GHashTable         *command_map;
+  GtkPaned           *paned;
+  GbDocumentGrid     *document_grid;
+};
+
 enum {
   PROP_0,
   LAST_PROP
@@ -185,12 +192,6 @@ open_tab (GSimpleAction *action,
   gtk_widget_destroy (GTK_WIDGET (dialog));
 }
 
-static GActionGroup *
-gb_editor_workspace_get_actions (GbWorkspace *workspace)
-{
-  return G_ACTION_GROUP (GB_EDITOR_WORKSPACE (workspace)->priv->actions);
-}
-
 static void
 gb_editor_workspace_new_document (GbWorkspace *workspace)
 {
@@ -231,7 +232,6 @@ gb_editor_workspace_finalize (GObject *object)
 {
   GbEditorWorkspacePrivate *priv = GB_EDITOR_WORKSPACE (object)->priv;
 
-  g_clear_object (&priv->actions);
   g_clear_pointer (&priv->command_map, g_hash_table_unref);
 
   G_OBJECT_CLASS (gb_editor_workspace_parent_class)->finalize (object);
@@ -247,7 +247,6 @@ gb_editor_workspace_class_init (GbEditorWorkspaceClass *klass)
   object_class->constructed = gb_editor_workspace_constructed;
   object_class->finalize = gb_editor_workspace_finalize;
 
-  workspace_class->get_actions = gb_editor_workspace_get_actions;
   workspace_class->new_document = gb_editor_workspace_new_document;
   workspace_class->open = gb_editor_workspace_activate_open;
 
@@ -265,20 +264,24 @@ gb_editor_workspace_class_init (GbEditorWorkspaceClass *klass)
 static void
 gb_editor_workspace_init (GbEditorWorkspace *workspace)
 {
-    const GActionEntry entries[] = {
-      { "open", open_tab },
-      { "new-document", new_document },
-      { "jump-to-doc", jump_to_doc_tab, "s" },
-    };
+  const GActionEntry entries[] = {
+    { "open", open_tab },
+    { "new-document", new_document },
+    { "jump-to-doc", jump_to_doc_tab, "s" },
+  };
+  GSimpleActionGroup *actions;
 
   workspace->priv = gb_editor_workspace_get_instance_private (workspace);
 
-  workspace->priv->actions = g_simple_action_group_new ();
-  g_action_map_add_action_entries (G_ACTION_MAP (workspace->priv->actions),
-                                   entries, G_N_ELEMENTS (entries),
-                                   workspace);
-
   workspace->priv->command_map = g_hash_table_new (g_str_hash, g_str_equal);
 
   gtk_widget_init_template (GTK_WIDGET (workspace));
+
+  actions = g_simple_action_group_new ();
+  g_action_map_add_action_entries (G_ACTION_MAP (actions),
+                                   entries, G_N_ELEMENTS (entries),
+                                   workspace);
+  gtk_widget_insert_action_group (GTK_WIDGET (workspace), "workspace",
+                                  G_ACTION_GROUP (actions));
+  g_clear_object (&actions);
 }
diff --git a/src/gnome-builder.mk b/src/gnome-builder.mk
index 1eadffe..e493aa4 100644
--- a/src/gnome-builder.mk
+++ b/src/gnome-builder.mk
@@ -82,7 +82,6 @@ libgnome_builder_la_SOURCES = \
        src/editor/gb-editor-view.h \
        src/editor/gb-editor-workspace.c \
        src/editor/gb-editor-workspace.h \
-       src/editor/gb-editor-workspace-private.h \
        src/editor/gb-source-change-monitor.c \
        src/editor/gb-source-change-monitor.h \
        src/editor/gb-source-formatter.c \
diff --git a/src/resources/gtk/menus.ui b/src/resources/gtk/menus.ui
index a0e553d..77e4cce 100644
--- a/src/resources/gtk/menus.ui
+++ b/src/resources/gtk/menus.ui
@@ -57,7 +57,7 @@
     <section>
       <item>
         <attribute name="label" translatable="yes">_Open</attribute>
-        <attribute name="action">win.open</attribute>
+        <attribute name="action">workspace.open</attribute>
       </item>
     </section>
     <section>
diff --git a/src/resources/keybindings/default.ini b/src/resources/keybindings/default.ini
index b472ec9..1c50e58 100644
--- a/src/resources/keybindings/default.ini
+++ b/src/resources/keybindings/default.ini
@@ -11,12 +11,9 @@ show-command-bar = <Control>space
 global-search = <Control>period
 save-all = <Control><Alt>S
 
-[editor]
-# I'd like open to not have an accelerator by default eventually. We will move
-# the majority of that feature to the global search making it unnecessary.
-open = <Control><Shift>O
-preview = <Control><Alt>P
+[workspace]
 new-document = <Control><Shift>N
+open = <Control><Shift>O
 
 [editor-frame]
 find = <Control><Shift>F
@@ -39,3 +36,4 @@ split-document-left = <Control><Alt>H
 split-document-right = <Control><Alt>L
 save = <Control>S
 save-as = <Control><Shift>S
+preview = <Control><Alt>P
diff --git a/src/resources/ui/gb-workbench.ui b/src/resources/ui/gb-workbench.ui
index 8075921..a14c732 100644
--- a/src/resources/ui/gb-workbench.ui
+++ b/src/resources/ui/gb-workbench.ui
@@ -89,7 +89,7 @@
         <child>
           <object class="GtkButton" id="new_tab">
             <property name="visible">True</property>
-            <property name="action_name">win.new-document</property>
+            <property name="action_name">workspace.new-document</property>
             <property name="tooltip-text" translatable="yes">Create new document</property>
             <style>
               <class name="image-button"/>
diff --git a/src/workbench/gb-workbench.c b/src/workbench/gb-workbench.c
index 21a512f..dbbd7ad 100644
--- a/src/workbench/gb-workbench.c
+++ b/src/workbench/gb-workbench.c
@@ -189,47 +189,21 @@ gb_workbench_stack_child_changed (GbWorkbench *workbench,
   child = gtk_stack_get_visible_child (stack);
   g_assert (!child || GB_IS_WORKSPACE (child));
 
-  if (child)
-    g_signal_emit (workbench, gSignals[WORKSPACE_CHANGED], 0, child);
-
   if (GB_IS_WORKSPACE (child))
     {
-      GAction *action;
-      gboolean enabled;
+      GActionGroup *action_group;
 
-      /* FIXME: None of this is ideal. We should come up with a better
-       * way. Even if that is adding and removing actions from 'win.'.
+      /*
+       * Some actions need to be propagated from the workspace to the
+       * toplevel. This way the header bar can activate them.
        */
-
-      enabled = !!GB_WORKSPACE_GET_CLASS (child)->new_document;
-      action = g_action_map_lookup_action (G_ACTION_MAP (workbench),
-                                           "new-document");
-      g_simple_action_set_enabled (G_SIMPLE_ACTION (action), enabled);
-
-      enabled = !!GB_WORKSPACE_GET_CLASS (child)->open;
-      action = g_action_map_lookup_action (G_ACTION_MAP (workbench),
-                                           "open");
-      g_simple_action_set_enabled (G_SIMPLE_ACTION (action), enabled);
+      action_group = gtk_widget_get_action_group (child, "workspace");
+      gtk_widget_insert_action_group (GTK_WIDGET (workbench),
+                                      "workspace", action_group);
     }
-}
-
-static void
-gb_workbench_load_workspace_actions (GbWorkbench *workbench,
-                                     GbWorkspace *workspace)
-{
-  GActionGroup *group;
-  const gchar *name;
-
-  group = gb_workspace_get_actions (workspace);
-  name = gtk_widget_get_name (GTK_WIDGET (workspace));
 
-  g_assert (name);
-
-  if (group)
-    {
-      g_message (_("Registering actions for \"%s\" prefix."), name);
-      gtk_widget_insert_action_group (GTK_WIDGET (workbench), name, group);
-    }
+  if (child)
+    g_signal_emit (workbench, gSignals[WORKSPACE_CHANGED], 0, child);
 }
 
 static void
@@ -468,8 +442,6 @@ gb_workbench_constructed (GObject *object)
 
   priv = workbench->priv;
 
-  gb_workbench_load_workspace_actions (workbench, GB_WORKSPACE (priv->editor));
-
   app = GTK_APPLICATION (g_application_get_default ());
   menu = gtk_application_get_menu_by_id (app, "gear-menu");
   gtk_menu_button_set_menu_model (GTK_MENU_BUTTON (priv->gear_menu_button),
diff --git a/src/workbench/gb-workspace.c b/src/workbench/gb-workspace.c
index dd7df7c..01a01ac 100644
--- a/src/workbench/gb-workspace.c
+++ b/src/workbench/gb-workspace.c
@@ -37,27 +37,6 @@ G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (GbWorkspace, gb_workspace, GTK_TYPE_BIN)
 
 static GParamSpec *gParamSpecs[LAST_PROP];
 
-/**
- * gb_workspace_get_actions:
- * @workspace: A #GbWorkspace.
- *
- * Fetch the actions for the workspace, to be added to the toplevel.
- * The actions will be added with the prefix for the workspace based on
- * the "name" property.
- *
- * Returns: (transfer none): A #GActionGroup or %NULL.
- */
-GActionGroup *
-gb_workspace_get_actions (GbWorkspace *workspace)
-{
-  g_return_val_if_fail (GB_IS_WORKSPACE (workspace), NULL);
-
-  if (GB_WORKSPACE_GET_CLASS (workspace)->get_actions)
-    return GB_WORKSPACE_GET_CLASS (workspace)->get_actions (workspace);
-
-  return NULL;
-}
-
 const gchar *
 gb_workspace_get_icon_name (GbWorkspace *workspace)
 {
diff --git a/src/workbench/gb-workspace.h b/src/workbench/gb-workspace.h
index cd83f65..a730142 100644
--- a/src/workbench/gb-workspace.h
+++ b/src/workbench/gb-workspace.h
@@ -47,8 +47,6 @@ struct _GbWorkspaceClass
 {
   GtkBinClass parent_class;
 
-  GActionGroup *(*get_actions) (GbWorkspace *workspace);
-
   void (*new_document) (GbWorkspace *workspace);
   void (*open)         (GbWorkspace *workspace);
 };
@@ -60,7 +58,6 @@ void          gb_workspace_set_icon_name (GbWorkspace *workspace,
 const gchar  *gb_workspace_get_title     (GbWorkspace *workspace);
 void          gb_workspace_set_title     (GbWorkspace *workspace,
                                           const gchar *title);
-GActionGroup *gb_workspace_get_actions   (GbWorkspace *workspace);
 void          gb_workspace_new_document  (GbWorkspace *workspace);
 void          gb_workspace_open          (GbWorkspace *workspace);
 


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