[gnome-builder] app: allows opening project from command line
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] app: allows opening project from command line
- Date: Sun, 3 Apr 2016 03:48:08 +0000 (UTC)
commit 16a3111cf52b74f54cbe4e78bea661aaa53e812f
Author: chandu <anoopchandu18 gmail com>
Date: Sat Apr 2 10:03:00 2016 +0000
app: allows opening project from command line
libide/ide-application-actions.c | 21 ++++++++++++++
libide/ide-application-command-line.c | 20 ++++++++++++-
libide/ide-application.c | 47 +++++++++++++++++++++++++++++++++
libide/ide-application.h | 2 +
4 files changed, 88 insertions(+), 2 deletions(-)
---
diff --git a/libide/ide-application-actions.c b/libide/ide-application-actions.c
index e9cd7b0..ae515d9 100644
--- a/libide/ide-application-actions.c
+++ b/libide/ide-application-actions.c
@@ -278,12 +278,33 @@ ide_application_actions_dayhack (GSimpleAction *action,
g_settings_set_string (settings, "style-scheme-name", "builder");
}
+static void
+ide_application_actions_load_project (GSimpleAction *action,
+ GVariant *args,
+ gpointer user_data)
+{
+ IdeApplication *self = user_data;
+ g_autofree gchar *filename = NULL;
+ g_autoptr(GFile) file = NULL;
+
+ g_assert (IDE_IS_APPLICATION (self));
+
+ g_variant_get (args, "s", &filename);
+ file = g_file_new_for_path (filename);
+
+ if (!ide_application_open_project (self, file))
+ {
+ g_message ("unable to open project specified by path - %s", filename);
+ }
+}
+
static const GActionEntry IdeApplicationActions[] = {
{ "about", ide_application_actions_about },
{ "dayhack", ide_application_actions_dayhack },
{ "nighthack", ide_application_actions_nighthack },
{ "open-project", ide_application_actions_open_project },
{ "new-project", ide_application_actions_new_project },
+ { "load-project", ide_application_actions_load_project, "s"},
{ "preferences", ide_application_actions_preferences },
{ "quit", ide_application_actions_quit },
{ "shortcuts", ide_application_actions_shortcuts },
diff --git a/libide/ide-application-command-line.c b/libide/ide-application-command-line.c
index b7e10eb..98958c7 100644
--- a/libide/ide-application-command-line.c
+++ b/libide/ide-application-command-line.c
@@ -163,6 +163,7 @@ ide_application_local_command_line (GApplication *application,
{
IdeApplication *self = (IdeApplication *)application;
g_autofree gchar *path_copy = NULL;
+ g_autofree gchar *filename = NULL;
GOptionContext *context = NULL;
GOptionGroup *group;
const gchar *shortdesc = NULL;
@@ -224,6 +225,14 @@ ide_application_local_command_line (GApplication *application,
&gapplication_service,
N_("Enter GApplication Service mode") },
+ { "project",
+ 'p',
+ G_OPTION_FLAG_IN_MAIN,
+ G_OPTION_ARG_FILENAME,
+ &filename,
+ N_("Opens the project specified by PATH"),
+ N_("PATH") },
+
{ NULL }
};
@@ -435,12 +444,19 @@ ide_application_local_command_line (GApplication *application,
{
g_application_hold (G_APPLICATION (self));
g_timeout_add_seconds (10, application_service_timeout_cb, g_object_ref (self));
+ goto cleanup;
}
- else
+
+ if (filename != NULL)
{
- g_application_activate (application);
+ GVariant *file;
+ file = g_variant_new ("s", filename);
+ g_action_group_activate_action ((GActionGroup *) application, "load-project", file);
+ goto cleanup;
}
+ g_application_activate (application);
+
cleanup:
g_clear_pointer (&type, g_free);
g_clear_pointer (&dbus_address, g_free);
diff --git a/libide/ide-application.c b/libide/ide-application.c
index b1df589..2379c76 100644
--- a/libide/ide-application.c
+++ b/libide/ide-application.c
@@ -645,3 +645,50 @@ ide_application_get_menu_by_id (IdeApplication *self,
return NULL;
}
+
+gboolean
+ide_application_open_project (IdeApplication *self,
+ GFile *file)
+{
+ g_return_val_if_fail (IDE_IS_APPLICATION (self), FALSE);
+ g_return_val_if_fail (G_IS_FILE (file), FALSE);
+
+ if (!g_file_query_exists (file, NULL))
+ return FALSE;
+
+ GList *list;
+ IdeContext *context;
+ GtkWindow *window;
+ GFile *projectfile;
+ IdeWorkbench *workbench = NULL;
+
+ list = gtk_application_get_windows (GTK_APPLICATION (self));
+
+ for (; list != NULL; list = list->next)
+ {
+ window = list->data;
+ context = ide_workbench_get_context (IDE_WORKBENCH (window));
+
+ if (context != NULL)
+ {
+ projectfile = g_file_get_parent (ide_context_get_project_file (context));
+ if (g_file_equal (file, projectfile))
+ workbench = IDE_WORKBENCH (window);
+ }
+ }
+
+ if (workbench == NULL)
+ {
+ workbench = g_object_new (IDE_TYPE_WORKBENCH,
+ "application", self,
+ NULL);
+ ide_workbench_open_project_async (workbench, file, NULL, NULL, NULL);
+ }
+
+ gtk_window_present (GTK_WINDOW (workbench));
+
+ if (ide_workbench_get_context(workbench) != NULL)
+ return TRUE;
+ else
+ return FALSE;
+}
diff --git a/libide/ide-application.h b/libide/ide-application.h
index 747ad8b..1b6a7ad 100644
--- a/libide/ide-application.h
+++ b/libide/ide-application.h
@@ -54,6 +54,8 @@ GDBusProxy *ide_application_get_worker_finish (IdeApplication *
GError **error);
GMenu *ide_application_get_menu_by_id (IdeApplication *self,
const gchar *id);
+gboolean ide_application_open_project (IdeApplication *self,
+ GFile *file);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]