[gnome-builder] workbench: wire up open action to toplevel menu



commit 35c273390ca391142085c5990fdfa854a98fec47
Author: Christian Hergert <christian hergert me>
Date:   Sun Dec 14 00:26:28 2014 -0800

    workbench: wire up open action to toplevel menu

 src/editor/gb-editor-workspace.c |    7 +++++++
 src/resources/gtk/menus.ui       |    2 +-
 src/workbench/gb-workbench.c     |   22 ++++++++++++++++++++++
 src/workbench/gb-workspace.c     |   29 +++++++++++------------------
 src/workbench/gb-workspace.h     |    2 ++
 5 files changed, 43 insertions(+), 19 deletions(-)
---
diff --git a/src/editor/gb-editor-workspace.c b/src/editor/gb-editor-workspace.c
index 559cfe1..d4da8e4 100644
--- a/src/editor/gb-editor-workspace.c
+++ b/src/editor/gb-editor-workspace.c
@@ -208,6 +208,12 @@ gb_editor_workspace_grab_focus (GtkWidget *widget)
 }
 
 static void
+gb_editor_workspace_activate_open (GbWorkspace *workspace)
+{
+  open_tab (NULL, NULL, workspace);
+}
+
+static void
 gb_editor_workspace_constructed (GObject *object)
 {
   GbEditorWorkspacePrivate *priv = GB_EDITOR_WORKSPACE (object)->priv;
@@ -243,6 +249,7 @@ gb_editor_workspace_class_init (GbEditorWorkspaceClass *klass)
 
   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;
 
   widget_class->grab_focus = gb_editor_workspace_grab_focus;
 
diff --git a/src/resources/gtk/menus.ui b/src/resources/gtk/menus.ui
index ff976d8..8912484 100644
--- a/src/resources/gtk/menus.ui
+++ b/src/resources/gtk/menus.ui
@@ -52,7 +52,7 @@
       <attribute name="id">file-section-1</attribute>
       <item>
         <attribute name="label" translatable="yes">_Open</attribute>
-        <attribute name="action">workbench.open</attribute>
+        <attribute name="action">win.open</attribute>
       </item>
     </section>
     <section>
diff --git a/src/workbench/gb-workbench.c b/src/workbench/gb-workbench.c
index c6da72a..42ce92e 100644
--- a/src/workbench/gb-workbench.c
+++ b/src/workbench/gb-workbench.c
@@ -197,10 +197,19 @@ gb_workbench_stack_child_changed (GbWorkbench *workbench,
       GAction *action;
       gboolean enabled;
 
+      /* FIXME: None of this is ideal. We should come up with a better
+       * way. Even if that is adding and removing actions from 'win.'.
+       */
+
       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);
     }
 }
 
@@ -397,6 +406,18 @@ on_new_document (GSimpleAction *action,
 }
 
 static void
+on_open (GSimpleAction *action,
+         GVariant      *parameters,
+         gpointer       user_data)
+{
+  GbWorkbench *workbench = user_data;
+
+  g_return_if_fail (GB_IS_WORKBENCH (workbench));
+
+  gb_workspace_open (workbench->priv->active_workspace);
+}
+
+static void
 gb_workbench_constructed (GObject *object)
 {
   static const GActionEntry actions[] = {
@@ -408,6 +429,7 @@ gb_workbench_constructed (GObject *object)
     { "toggle-command-bar", on_toggle_command_bar_activate, "b" },
     { "roll-credits", on_roll_credits },
     { "new-document", on_new_document },
+    { "open", on_open },
   };
   GbWorkbenchPrivate *priv;
   GbWorkbench *workbench = (GbWorkbench *)object;
diff --git a/src/workbench/gb-workspace.c b/src/workbench/gb-workspace.c
index 4c1ccc7..dd7df7c 100644
--- a/src/workbench/gb-workspace.c
+++ b/src/workbench/gb-workspace.c
@@ -33,15 +33,9 @@ enum {
   LAST_PROP
 };
 
-enum {
-  NEW_DOCUMENT,
-  LAST_SIGNAL
-};
-
 G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (GbWorkspace, gb_workspace, GTK_TYPE_BIN)
 
 static GParamSpec *gParamSpecs[LAST_PROP];
-static guint       gSignals [LAST_SIGNAL];
 
 /**
  * gb_workspace_get_actions:
@@ -109,7 +103,17 @@ gb_workspace_new_document (GbWorkspace *workspace)
 {
   g_return_if_fail (GB_IS_WORKSPACE (workspace));
 
-  g_signal_emit (workspace, gSignals [NEW_DOCUMENT], 0);
+  if (GB_WORKSPACE_GET_CLASS (workspace)->new_document)
+    GB_WORKSPACE_GET_CLASS (workspace)->new_document (workspace);
+}
+
+void
+gb_workspace_open (GbWorkspace *workspace)
+{
+  g_return_if_fail (GB_IS_WORKSPACE (workspace));
+
+  if (GB_WORKSPACE_GET_CLASS (workspace)->open)
+    GB_WORKSPACE_GET_CLASS (workspace)->open (workspace);
 }
 
 static void
@@ -200,17 +204,6 @@ gb_workspace_class_init (GbWorkspaceClass *klass)
                           G_PARAM_STATIC_STRINGS));
   g_object_class_install_property (object_class, PROP_ICON_NAME,
                                    gParamSpecs[PROP_ICON_NAME]);
-
-  gSignals [NEW_DOCUMENT] =
-    g_signal_new ("new-document",
-                  GB_TYPE_WORKSPACE,
-                  G_SIGNAL_RUN_LAST,
-                  G_STRUCT_OFFSET (GbWorkspaceClass, new_document),
-                  NULL,
-                  NULL,
-                  g_cclosure_marshal_VOID__VOID,
-                  G_TYPE_NONE,
-                  0);
 }
 
 static void
diff --git a/src/workbench/gb-workspace.h b/src/workbench/gb-workspace.h
index 767e2d4..cd83f65 100644
--- a/src/workbench/gb-workspace.h
+++ b/src/workbench/gb-workspace.h
@@ -50,6 +50,7 @@ struct _GbWorkspaceClass
   GActionGroup *(*get_actions) (GbWorkspace *workspace);
 
   void (*new_document) (GbWorkspace *workspace);
+  void (*open)         (GbWorkspace *workspace);
 };
 
 GType         gb_workspace_get_type      (void) G_GNUC_CONST;
@@ -61,6 +62,7 @@ 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);
 
 G_END_DECLS
 


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