[gnome-builder] app: add gb_application_open_project()
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] app: add gb_application_open_project()
- Date: Wed, 8 Apr 2015 07:26:31 +0000 (UTC)
commit 216fcb1c7b8d10351c9d4534d8a3bcac21e794d2
Author: Christian Hergert <christian hergert me>
Date: Wed Apr 8 00:02:26 2015 -0700
app: add gb_application_open_project()
src/app/gb-application.c | 83 ++++++++++++++++++++++++++++++++++++----------
src/app/gb-application.h | 3 ++
2 files changed, 68 insertions(+), 18 deletions(-)
---
diff --git a/src/app/gb-application.c b/src/app/gb-application.c
index 566b049..4aa2847 100644
--- a/src/app/gb-application.c
+++ b/src/app/gb-application.c
@@ -363,9 +363,72 @@ gb_application__context_new_cb (GObject *object,
cleanup:
g_task_return_boolean (task, FALSE);
+ g_application_unmark_busy (G_APPLICATION (self));
g_application_release (G_APPLICATION (self));
}
+void
+gb_application_open_project (GbApplication *self,
+ GFile *file,
+ GPtrArray *additional_files)
+{
+ g_autoptr(GFile) directory = NULL;
+ g_autoptr(GTask) task = NULL;
+ g_autoptr(GPtrArray) ar = NULL;
+ GList *windows;
+ GList *iter;
+
+ g_return_if_fail (GB_IS_APPLICATION (self));
+ g_return_if_fail (G_IS_FILE (file));
+
+ windows = gtk_application_get_windows (GTK_APPLICATION (self));
+
+ for (iter = windows; iter; iter = iter->next)
+ {
+ if (GB_IS_WORKBENCH (iter->data))
+ {
+ IdeContext *context;
+
+ context = gb_workbench_get_context (iter->data);
+
+ if (context != NULL)
+ {
+ GFile *project_file;
+
+ project_file = ide_context_get_project_file (context);
+
+ if (g_file_equal (file, project_file))
+ {
+ gtk_window_present (iter->data);
+ return;
+ }
+ }
+ }
+ }
+
+ task = g_task_new (self, NULL, NULL, NULL);
+
+ if (additional_files)
+ ar = g_ptr_array_ref (additional_files);
+ else
+ ar = g_ptr_array_new ();
+
+ g_task_set_task_data (task, g_ptr_array_ref (ar), (GDestroyNotify)g_ptr_array_unref);
+
+ if (g_file_query_file_type (file, 0, NULL) == G_FILE_TYPE_DIRECTORY)
+ directory = g_object_ref (file);
+ else
+ directory = g_file_get_parent (file);
+
+ g_application_mark_busy (G_APPLICATION (self));
+ g_application_hold (G_APPLICATION (self));
+
+ ide_context_new_async (directory,
+ NULL,
+ gb_application__context_new_cb,
+ g_object_ref (task));
+}
+
static void
gb_application_open (GApplication *application,
GFile **files,
@@ -409,25 +472,9 @@ gb_application_open (GApplication *application,
*/
if (ar && ar->len)
{
- g_autoptr(GFile) directory = NULL;
- g_autoptr(GTask) task = NULL;
- GFile *file;
-
- task = g_task_new (self, NULL, NULL, NULL);
- g_task_set_task_data (task, g_ptr_array_ref (ar), (GDestroyNotify)g_ptr_array_unref);
-
- file = g_ptr_array_index (ar, 0);
-
- if (g_file_query_file_type (file, 0, NULL) == G_FILE_TYPE_DIRECTORY)
- directory = g_object_ref (file);
- else
- directory = g_file_get_parent (file);
+ GFile *file = g_ptr_array_index (ar, 0);
- ide_context_new_async (directory,
- NULL,
- gb_application__context_new_cb,
- g_object_ref (task));
- g_application_hold (G_APPLICATION (self));
+ gb_application_open_project (self, file, ar);
}
IDE_EXIT;
diff --git a/src/app/gb-application.h b/src/app/gb-application.h
index 43d2666..d66df1b 100644
--- a/src/app/gb-application.h
+++ b/src/app/gb-application.h
@@ -27,6 +27,9 @@ G_BEGIN_DECLS
G_DECLARE_FINAL_TYPE (GbApplication, gb_application, GB, APPLICATION, GtkApplication)
+void gb_application_open_project (GbApplication *self,
+ GFile *file,
+ GPtrArray *additional_files);
G_END_DECLS
#endif /* GB_APPLICATION_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]