[gnome-builder/wip/libide] libide: add ide_context_unload_async()



commit 44e0e73befd7fddbcf5bf29c63d466b6e9ebae6a
Author: Christian Hergert <christian hergert me>
Date:   Tue Mar 3 10:39:41 2015 -0800

    libide: add ide_context_unload_async()
    
    This is where we will perform last minute state saving within the context.
    Applications should call this before they close their workbench.
    
    In particular, Builder will probably want to make the window insensitive
    after delete-event, then unload_async(), and after that destroy the window.

 libide/ide-context.c |   76 ++++++++++++++++++++++++++++++++++++++++++++++++++
 libide/ide-context.h |    7 ++++
 2 files changed, 83 insertions(+), 0 deletions(-)
---
diff --git a/libide/ide-context.c b/libide/ide-context.c
index 87c57a2..7746a06 100644
--- a/libide/ide-context.c
+++ b/libide/ide-context.c
@@ -25,6 +25,7 @@
 #include "ide-buffer-manager.h"
 #include "ide-build-system.h"
 #include "ide-context.h"
+#include "ide-debug.h"
 #include "ide-device-manager.h"
 #include "ide-global.h"
 #include "ide-internal.h"
@@ -1184,3 +1185,78 @@ async_initable_init (GAsyncInitableIface *iface)
   iface->init_async = ide_context_init_async;
   iface->init_finish = ide_context_init_finish;
 }
+
+static void
+ide_context_unload__unsaved_files_save_cb (GObject      *object,
+                                           GAsyncResult *result,
+                                           gpointer      user_data)
+{
+  IdeUnsavedFiles *unsaved_files = (IdeUnsavedFiles *)object;
+  g_autoptr(GTask) task = user_data;
+  GError *error = NULL;
+
+  if (!ide_unsaved_files_save_finish (unsaved_files, result, &error))
+    {
+      g_task_return_error (task, error);
+      return;
+    }
+
+  g_task_return_boolean (task, TRUE);
+}
+
+/**
+ * ide_context_unload_async:
+ *
+ * This function attempts to unload various components in the #IdeContext. This should be called
+ * before you dispose the context. Unsaved buffers will be persisted to the drafts directory.
+ * More operations may be added in the future.
+ */
+void
+ide_context_unload_async (IdeContext          *self,
+                          GCancellable        *cancellable,
+                          GAsyncReadyCallback  callback,
+                          gpointer             user_data)
+{
+  IdeUnsavedFiles *unsaved_files;
+  g_autoptr(GTask) task = NULL;
+
+  IDE_ENTRY;
+
+  g_return_if_fail (IDE_IS_CONTEXT (self));
+  g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
+
+  task = g_task_new (self, cancellable, callback, user_data);
+
+  unsaved_files = ide_context_get_unsaved_files (self);
+
+  ide_unsaved_files_save_async (unsaved_files,
+                                cancellable,
+                                ide_context_unload__unsaved_files_save_cb,
+                                g_object_ref (task));
+
+  /*
+   * TODO:
+   *
+   * Detach devices?
+   * Anything else?
+   */
+
+  IDE_EXIT;
+}
+
+gboolean
+ide_context_unload_finish (IdeContext    *self,
+                           GAsyncResult  *result,
+                           GError       **error)
+{
+  GTask *task = (GTask *)result;
+  gboolean ret;
+
+  IDE_ENTRY;
+
+  g_return_val_if_fail (IDE_IS_CONTEXT (self), FALSE);
+
+  ret = g_task_propagate_boolean (task, error);
+
+  IDE_RETURN (ret);
+}
diff --git a/libide/ide-context.h b/libide/ide-context.h
index fdd7d45..eef84fd 100644
--- a/libide/ide-context.h
+++ b/libide/ide-context.h
@@ -43,6 +43,13 @@ IdeVcs                   *ide_context_get_vcs               (IdeContext
 const gchar              *ide_context_get_root_build_dir    (IdeContext           *self);
 gpointer                  ide_context_get_service_typed     (IdeContext           *self,
                                                              GType                 service_type);
+void                      ide_context_unload_async          (IdeContext           *self,
+                                                             GCancellable         *cancellable,
+                                                             GAsyncReadyCallback   callback,
+                                                             gpointer              user_data);
+gboolean                  ide_context_unload_finish         (IdeContext           *self,
+                                                             GAsyncResult         *result,
+                                                             GError              **error);
 void                      ide_context_new_async             (GFile                *project_file,
                                                              GCancellable         *cancellable,
                                                              GAsyncReadyCallback   callback,


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