[gnome-builder] editor: add save tab action.



commit 44a59dcd4ac0aa81b3087ac425fef6d23ac6109f
Author: Christian Hergert <christian hergert me>
Date:   Mon Sep 8 16:06:29 2014 -0700

    editor: add save tab action.

 src/editor/gb-editor-tab.c            |   15 +++++++++++++++
 src/editor/gb-editor-tab.h            |    1 +
 src/editor/gb-editor-workspace.c      |   20 ++++++++++++++++++++
 src/resources/keybindings/default.ini |    1 +
 4 files changed, 37 insertions(+), 0 deletions(-)
---
diff --git a/src/editor/gb-editor-tab.c b/src/editor/gb-editor-tab.c
index a4b0ed3..984deb2 100644
--- a/src/editor/gb-editor-tab.c
+++ b/src/editor/gb-editor-tab.c
@@ -784,6 +784,7 @@ gb_editor_tab_do_save (GbEditorTab *tab)
 
   g_return_if_fail (GB_IS_EDITOR_TAB (tab));
   g_return_if_fail (tab->priv->file);
+  g_return_if_fail (gtk_source_file_get_location (tab->priv->file));
 
   priv = tab->priv;
 
@@ -855,6 +856,20 @@ gb_editor_tab_save_as (GbEditorTab *tab)
   gtk_widget_destroy (GTK_WIDGET (dialog));
 }
 
+void
+gb_editor_tab_save (GbEditorTab *tab)
+{
+  g_return_if_fail (GB_IS_EDITOR_TAB (tab));
+
+  if (!gtk_source_file_get_location (tab->priv->file))
+    {
+      gb_editor_tab_save_as (tab);
+      return;
+    }
+
+  gb_editor_tab_do_save (tab);
+}
+
 static void
 gb_editor_tab_freeze_drag (GbTab *tab)
 {
diff --git a/src/editor/gb-editor-tab.h b/src/editor/gb-editor-tab.h
index 0d27520..ef83399 100644
--- a/src/editor/gb-editor-tab.h
+++ b/src/editor/gb-editor-tab.h
@@ -64,6 +64,7 @@ void              gb_editor_tab_reformat      (GbEditorTab                *tab);
 void              gb_editor_tab_go_to_end     (GbEditorTab                *tab);
 void              gb_editor_tab_go_to_start   (GbEditorTab                *tab);
 void              gb_editor_tab_save_as       (GbEditorTab                *tab);
+void              gb_editor_tab_save          (GbEditorTab                *tab);
 
 G_END_DECLS
 
diff --git a/src/editor/gb-editor-workspace.c b/src/editor/gb-editor-workspace.c
index 5931b48..4f3e9d7 100644
--- a/src/editor/gb-editor-workspace.c
+++ b/src/editor/gb-editor-workspace.c
@@ -104,6 +104,25 @@ on_reformat_activate (GSimpleAction *action,
 }
 
 static void
+on_save_activate (GSimpleAction *action,
+                  GVariant      *parameter,
+                  gpointer       user_data)
+{
+  GbEditorWorkspace *workspace = user_data;
+  GbTab *tab;
+
+  g_return_if_fail (GB_IS_EDITOR_WORKSPACE (workspace));
+
+  tab = gb_multi_notebook_get_active_tab (workspace->priv->multi_notebook);
+
+  if (tab)
+    {
+      g_assert (GB_IS_EDITOR_TAB (tab));
+      gb_editor_tab_save (GB_EDITOR_TAB (tab));
+    }
+}
+
+static void
 on_save_as_activate (GSimpleAction *action,
                      GVariant      *parameter,
                      gpointer       user_data)
@@ -207,6 +226,7 @@ gb_editor_workspace_init (GbEditorWorkspace *workspace)
     { "go-to-end", on_go_to_end_activate },
     { "go-to-start", on_go_to_start_activate },
     { "reformat", on_reformat_activate },
+    { "save", on_save_activate },
     { "save-as", on_save_as_activate },
   };
   GbEditorWorkspacePrivate *priv;
diff --git a/src/resources/keybindings/default.ini b/src/resources/keybindings/default.ini
index 026497e..62d82c2 100644
--- a/src/resources/keybindings/default.ini
+++ b/src/resources/keybindings/default.ini
@@ -6,4 +6,5 @@ find = <Control>F
 go-to-end = <Control>Page_Down
 go-to-start = <Control>Page_Up
 reformat = <Control><Shift>R
+save = <Control>S
 save-as = <Control><Shift>S


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