[gnome-builder/wip/chergert/perspective] workbench: add ide_workbench_open_project_async()
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/chergert/perspective] workbench: add ide_workbench_open_project_async()
- Date: Tue, 1 Dec 2015 06:37:14 +0000 (UTC)
commit 90584d068e595313954cc76eb8869466318e78ad
Author: Christian Hergert <chergert redhat com>
Date: Mon Nov 30 22:36:30 2015 -0800
workbench: add ide_workbench_open_project_async()
We need this in a few places, so time to abstract it cleanly into
the workbench open helpers.
libide/ide-workbench-open.c | 77 +++++++++++++++++++++++++++++++++++++++++++
libide/ide-workbench.h | 8 ++++
2 files changed, 85 insertions(+), 0 deletions(-)
---
diff --git a/libide/ide-workbench-open.c b/libide/ide-workbench-open.c
index eb4e21b..294056b 100644
--- a/libide/ide-workbench-open.c
+++ b/libide/ide-workbench-open.c
@@ -18,6 +18,7 @@
#include <libpeas/peas.h>
+#include "ide-application.h"
#include "ide-uri.h"
#include "ide-workbench.h"
#include "ide-workbench-addin.h"
@@ -396,3 +397,79 @@ ide_workbench_open_files_finish (IdeWorkbench *self,
return g_task_propagate_boolean (task, error);
}
+
+static void
+ide_workbench_open_project_cb (GObject *object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ g_autoptr(GTask) task = user_data;
+ g_autoptr(IdeContext) context = NULL;
+ IdeWorkbench *workbench;
+ guint32 present_time;
+ GError *error = NULL;
+
+ g_assert (G_IS_ASYNC_RESULT (result));
+ g_assert (G_IS_TASK (task));
+
+ context = ide_context_new_finish (result, &error);
+
+ if (context == NULL)
+ {
+ g_task_return_error (task, error);
+ return;
+ }
+
+ workbench = g_task_get_source_object (task);
+
+ if (workbench->context != NULL)
+ {
+ present_time = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (task), "GDK_CURRENT_TIME"));
+ workbench = g_object_new (IDE_TYPE_WORKBENCH,
+ "application", IDE_APPLICATION_DEFAULT,
+ "visible", TRUE,
+ NULL);
+ gtk_window_present_with_time (GTK_WINDOW (workbench), present_time);
+ }
+
+ ide_workbench_set_context (workbench, context);
+ ide_workbench_set_visible_perspective_name (workbench, "editor");
+
+ g_task_return_boolean (task, TRUE);
+}
+
+void
+ide_workbench_open_project_async (IdeWorkbench *self,
+ GFile *file_or_directory,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ g_autoptr(GTask) task = NULL;
+
+ g_assert (IDE_IS_WORKBENCH (self));
+ g_assert (G_IS_FILE (file_or_directory));
+ g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
+
+ task = g_task_new (self, cancellable, callback, user_data);
+
+ g_object_set_data (G_OBJECT (task),
+ "GDK_CURRENT_TIME",
+ GINT_TO_POINTER (GDK_CURRENT_TIME));
+
+ ide_context_new_async (file_or_directory,
+ cancellable,
+ ide_workbench_open_project_cb,
+ g_object_ref (task));
+}
+
+gboolean
+ide_workbench_open_project_finish (IdeWorkbench *self,
+ GAsyncResult *result,
+ GError **error)
+{
+ g_return_val_if_fail (IDE_IS_WORKBENCH (self), FALSE);
+ g_return_val_if_fail (G_IS_TASK (result), FALSE);
+
+ return g_task_propagate_boolean (G_TASK (result), error);
+}
diff --git a/libide/ide-workbench.h b/libide/ide-workbench.h
index d0c311d..33b7484 100644
--- a/libide/ide-workbench.h
+++ b/libide/ide-workbench.h
@@ -31,6 +31,14 @@ G_BEGIN_DECLS
G_DECLARE_FINAL_TYPE (IdeWorkbench, ide_workbench, IDE, WORKBENCH, GtkApplicationWindow)
+void ide_workbench_open_project_async (IdeWorkbench *self,
+ GFile *file_or_directory,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+gboolean ide_workbench_open_project_finish (IdeWorkbench *self,
+ GAsyncResult *result,
+ GError **error);
void ide_workbench_open_uri_async (IdeWorkbench *self,
IdeUri *uri,
const gchar *hint,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]