[gnome-builder] actions: wire up new document action to header bar button



commit a91c98cd73219bca6e45cf73c01f267c99055f70
Author: Christian Hergert <christian hergert me>
Date:   Sun Dec 14 00:09:12 2014 -0800

    actions: wire up new document action to header bar button

 src/editor/gb-editor-workspace.c |    7 +++++++
 src/resources/ui/gb-workbench.ui |    4 ++--
 src/workbench/gb-workbench.c     |   13 +++++++++++++
 src/workbench/gb-workspace.c     |   25 +++++++++++++++++++++++++
 src/workbench/gb-workspace.h     |    3 +++
 5 files changed, 50 insertions(+), 2 deletions(-)
---
diff --git a/src/editor/gb-editor-workspace.c b/src/editor/gb-editor-workspace.c
index bf8218f..559cfe1 100644
--- a/src/editor/gb-editor-workspace.c
+++ b/src/editor/gb-editor-workspace.c
@@ -192,6 +192,12 @@ gb_editor_workspace_get_actions (GbWorkspace *workspace)
 }
 
 static void
+gb_editor_workspace_new_document (GbWorkspace *workspace)
+{
+  new_document (NULL, NULL, workspace);
+}
+
+static void
 gb_editor_workspace_grab_focus (GtkWidget *widget)
 {
   GbEditorWorkspace *workspace = GB_EDITOR_WORKSPACE (widget);
@@ -236,6 +242,7 @@ gb_editor_workspace_class_init (GbEditorWorkspaceClass *klass)
   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;
 
   widget_class->grab_focus = gb_editor_workspace_grab_focus;
 
diff --git a/src/resources/ui/gb-workbench.ui b/src/resources/ui/gb-workbench.ui
index d3d6e3a..8075921 100644
--- a/src/resources/ui/gb-workbench.ui
+++ b/src/resources/ui/gb-workbench.ui
@@ -89,8 +89,8 @@
         <child>
           <object class="GtkButton" id="new_tab">
             <property name="visible">True</property>
-            <property name="action_name">workbench.new-tab</property>
-            <property name="tooltip-text" translatable="yes">Open new tab</property>
+            <property name="action_name">win.new-document</property>
+            <property name="tooltip-text" translatable="yes">Create new document</property>
             <style>
               <class name="image-button"/>
             </style>
diff --git a/src/workbench/gb-workbench.c b/src/workbench/gb-workbench.c
index 06b9e1e..83601d0 100644
--- a/src/workbench/gb-workbench.c
+++ b/src/workbench/gb-workbench.c
@@ -374,6 +374,18 @@ on_roll_credits (GSimpleAction *action,
 }
 
 static void
+on_new_document (GSimpleAction *action,
+                 GVariant      *parameters,
+                 gpointer       user_data)
+{
+  GbWorkbench *workbench = user_data;
+
+  g_return_if_fail (GB_IS_WORKBENCH (workbench));
+
+  gb_workspace_new_document (workbench->priv->active_workspace);
+}
+
+static void
 gb_workbench_constructed (GObject *object)
 {
   static const GActionEntry actions[] = {
@@ -384,6 +396,7 @@ gb_workbench_constructed (GObject *object)
     { "show-command-bar", on_show_command_bar_activate },
     { "toggle-command-bar", on_toggle_command_bar_activate, "b" },
     { "roll-credits", on_roll_credits },
+    { "new-document", on_new_document },
   };
   GbWorkbenchPrivate *priv;
   GbWorkbench *workbench = (GbWorkbench *)object;
diff --git a/src/workbench/gb-workspace.c b/src/workbench/gb-workspace.c
index d19a3c2..4c1ccc7 100644
--- a/src/workbench/gb-workspace.c
+++ b/src/workbench/gb-workspace.c
@@ -33,9 +33,15 @@ 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:
@@ -98,6 +104,14 @@ gb_workspace_set_title (GbWorkspace *workspace,
                             gParamSpecs[PROP_TITLE]);
 }
 
+void
+gb_workspace_new_document (GbWorkspace *workspace)
+{
+  g_return_if_fail (GB_IS_WORKSPACE (workspace));
+
+  g_signal_emit (workspace, gSignals [NEW_DOCUMENT], 0);
+}
+
 static void
 gb_workspace_finalize (GObject *object)
 {
@@ -186,6 +200,17 @@ 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 d24fd26..767e2d4 100644
--- a/src/workbench/gb-workspace.h
+++ b/src/workbench/gb-workspace.h
@@ -48,6 +48,8 @@ struct _GbWorkspaceClass
   GtkBinClass parent_class;
 
   GActionGroup *(*get_actions) (GbWorkspace *workspace);
+
+  void (*new_document) (GbWorkspace *workspace);
 };
 
 GType         gb_workspace_get_type      (void) G_GNUC_CONST;
@@ -58,6 +60,7 @@ 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);
 
 G_END_DECLS
 


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