[gnome-builder/wip/chergert/perspective] workbench: fix save-all-quit action



commit fb58246708a012b69df8408a48c3830379a3eb3e
Author: Christian Hergert <chergert redhat com>
Date:   Mon Dec 14 03:07:15 2015 -0800

    workbench: fix save-all-quit action

 data/keybindings/vim.css       |    2 +-
 libide/ide-workbench-actions.c |   45 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 46 insertions(+), 1 deletions(-)
---
diff --git a/data/keybindings/vim.css b/data/keybindings/vim.css
index 0c6bb49..6ed24e9 100644
--- a/data/keybindings/vim.css
+++ b/data/keybindings/vim.css
@@ -915,7 +915,7 @@
 
 @binding-set builder-vim-source-view-normal-Z
 {
-  bind "<shift>z" { "action" ("workbench", "save-all-quit", "") };
+  bind "<shift>z" { "action" ("win", "save-all-quit", "") };
 }
 
 @binding-set builder-vim-source-view-visual-z
diff --git a/libide/ide-workbench-actions.c b/libide/ide-workbench-actions.c
index ba6cbd1..7fd3cf0 100644
--- a/libide/ide-workbench-actions.c
+++ b/libide/ide-workbench-actions.c
@@ -20,6 +20,7 @@
 
 #include <glib/gi18n.h>
 
+#include "ide-application.h"
 #include "ide-buffer-manager.h"
 #include "ide-debug.h"
 #include "ide-workbench.h"
@@ -115,6 +116,49 @@ ide_workbench_actions_save_all (GSimpleAction *action,
   ide_buffer_manager_save_all_async (bufmgr, NULL, NULL, NULL);
 }
 
+static void
+save_all_quit_cb (GObject      *object,
+                  GAsyncResult *result,
+                  gpointer      user_data)
+{
+  IdeBufferManager *bufmgr = (IdeBufferManager *)object;
+  g_autoptr(IdeWorkbench) self = user_data;
+  g_autoptr(GError) error = NULL;
+
+  g_assert (IDE_IS_BUFFER_MANAGER (bufmgr));
+  g_assert (IDE_IS_WORKBENCH (self));
+
+  if (!ide_buffer_manager_save_all_finish (bufmgr, result, &error))
+    {
+      g_warning ("%s", error->message);
+      return;
+    }
+
+  g_application_quit (G_APPLICATION (IDE_APPLICATION_DEFAULT));
+}
+
+static void
+ide_workbench_actions_save_all_quit (GSimpleAction *action,
+                                     GVariant      *variant,
+                                     gpointer       user_data)
+{
+  IdeWorkbench *workbench = user_data;
+  IdeContext *context;
+  IdeBufferManager *bufmgr;
+
+  g_assert (IDE_IS_WORKBENCH (workbench));
+
+  context = ide_workbench_get_context (workbench);
+  if (context == NULL)
+    return;
+
+  bufmgr = ide_context_get_buffer_manager (context);
+  ide_buffer_manager_save_all_async (bufmgr,
+                                     NULL,
+                                     save_all_quit_cb,
+                                     g_object_ref (workbench));
+}
+
 void
 ide_workbench_actions_init (IdeWorkbench *self)
 {
@@ -122,6 +166,7 @@ ide_workbench_actions_init (IdeWorkbench *self)
   const GActionEntry actions[] = {
     { "open-with-dialog", ide_workbench_actions_open_with_dialog },
     { "save-all", ide_workbench_actions_save_all },
+    { "save-all-quit", ide_workbench_actions_save_all_quit },
   };
 
   g_action_map_add_action_entries (G_ACTION_MAP (self), actions, G_N_ELEMENTS (actions), self);


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