[gnome-builder/wip/open-file: 3/4] wip: stub out (poorly) a way to open a file from command line
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/open-file: 3/4] wip: stub out (poorly) a way to open a file from command line
- Date: Wed, 24 Sep 2014 00:16:29 +0000 (UTC)
commit c16f4b1275bc0e41fe928d6c19ed07fa688b5d56
Author: Christian Hergert <christian hergert me>
Date: Mon Sep 22 03:00:04 2014 -0700
wip: stub out (poorly) a way to open a file from command line
src/app/gb-application.c | 59 ++++++++++++++++++++++++++++++++++++--
src/editor/gb-editor-commands.h | 3 ++
src/editor/gb-editor-workspace.c | 28 ++++++++++++++++++
src/editor/gb-editor-workspace.h | 2 +
src/workbench/gb-workbench.c | 15 +++++++++
src/workbench/gb-workbench.h | 2 +
6 files changed, 106 insertions(+), 3 deletions(-)
---
diff --git a/src/app/gb-application.c b/src/app/gb-application.c
index fb7075a..3781023 100644
--- a/src/app/gb-application.c
+++ b/src/app/gb-application.c
@@ -26,6 +26,7 @@
#include <glib/gi18n.h>
#include "gb-application.h"
+#include "gb-editor-workspace.h"
#include "gb-log.h"
#include "gb-keybindings.h"
#include "gb-resources.h"
@@ -148,8 +149,8 @@ setup_keybindings (GbApplication *application)
EXIT;
}
-static void
-gb_application_activate (GApplication *application)
+static GtkWindow *
+create_window (GApplication *application)
{
GtkWindow *window;
GdkScreen *screen;
@@ -182,7 +183,54 @@ gb_application_activate (GApplication *application)
gtk_application_add_window (GTK_APPLICATION (application), window);
- EXIT;
+ RETURN (window);
+}
+
+static void
+gb_application_activate (GApplication *application)
+{
+ create_window (application);
+}
+
+static void
+gb_application_open (GApplication *application,
+ GFile **files,
+ gint n_files,
+ const gchar *hint)
+{
+ GbWorkbench *workbench = NULL;
+ GbWorkspace *workspace;
+ GList *list;
+
+ /*
+ * TODO: We should plumb this through so we are executing an action
+ * with a "filename" parameter.
+ */
+
+ list = gtk_application_get_windows (GTK_APPLICATION (application));
+
+ for (; list; list = list->next)
+ {
+ if (GB_IS_WORKBENCH (list->data))
+ {
+ workbench = GB_WORKBENCH (list->data);
+ break;
+ }
+ }
+
+ if (!workbench)
+ workbench = GB_WORKBENCH (create_window (application));
+
+ workspace = gb_workbench_get_workspace (workbench,
+ GB_TYPE_EDITOR_WORKSPACE);
+
+ if (workspace)
+ {
+ guint i;
+
+ for (i = 0; i < n_files; i++)
+ gb_editor_workspace_open (GB_EDITOR_WORKSPACE (workspace), files [i]);
+ }
}
static void
@@ -293,6 +341,7 @@ gb_application_class_init (GbApplicationClass *klass)
app_class->activate = gb_application_activate;
app_class->startup = gb_application_startup;
+ app_class->open = gb_application_open;
EXIT;
}
@@ -301,7 +350,11 @@ static void
gb_application_init (GbApplication *application)
{
ENTRY;
+
g_application_set_application_id (G_APPLICATION (application),
"org.gnome.Builder");
+ g_application_set_flags (G_APPLICATION (application),
+ G_APPLICATION_HANDLES_OPEN);
+
EXIT;
}
diff --git a/src/editor/gb-editor-commands.h b/src/editor/gb-editor-commands.h
index 3a8c3ff..bb1b498 100644
--- a/src/editor/gb-editor-commands.h
+++ b/src/editor/gb-editor-commands.h
@@ -20,10 +20,13 @@
#define GB_EDITOR_COMMANDS_H
#include "gb-editor-workspace.h"
+#include "gb-editor-tab.h"
G_BEGIN_DECLS
void gb_editor_commands_init (GbEditorWorkspace *workspace);
+void gb_editor_tab_open_file (GbEditorTab *tab,
+ GFile *file);
G_END_DECLS
diff --git a/src/editor/gb-editor-workspace.c b/src/editor/gb-editor-workspace.c
index 6ac903f..57dee44 100644
--- a/src/editor/gb-editor-workspace.c
+++ b/src/editor/gb-editor-workspace.c
@@ -29,6 +29,34 @@ enum {
G_DEFINE_TYPE_WITH_PRIVATE (GbEditorWorkspace, gb_editor_workspace, GB_TYPE_WORKSPACE)
+void
+gb_editor_workspace_open (GbEditorWorkspace *workspace,
+ GFile *file)
+{
+ GbEditorTab *tab;
+ GbNotebook *notebook;
+ gint page;
+
+ g_return_if_fail (GB_IS_EDITOR_WORKSPACE (workspace));
+ g_return_if_fail (G_IS_FILE (file));
+
+ notebook = gb_multi_notebook_get_active_notebook (workspace->priv->multi_notebook);
+
+ tab = g_object_new (GB_TYPE_EDITOR_TAB,
+ "visible", TRUE,
+ NULL);
+ gb_notebook_add_tab (notebook, GB_TAB (tab));
+
+ gtk_container_child_get (GTK_CONTAINER (notebook), GTK_WIDGET (tab),
+ "position", &page,
+ NULL);
+ gtk_notebook_set_current_page (GTK_NOTEBOOK (notebook), page);
+
+ gb_editor_tab_open_file (tab, file);
+
+ gtk_widget_grab_focus (GTK_WIDGET (tab));
+}
+
static GActionGroup *
gb_editor_workspace_get_actions (GbWorkspace * workspace)
{
diff --git a/src/editor/gb-editor-workspace.h b/src/editor/gb-editor-workspace.h
index c1098cc..719fe66 100644
--- a/src/editor/gb-editor-workspace.h
+++ b/src/editor/gb-editor-workspace.h
@@ -49,6 +49,8 @@ struct _GbEditorWorkspaceClass
};
GType gb_editor_workspace_get_type (void) G_GNUC_CONST;
+void gb_editor_workspace_open (GbEditorWorkspace *workspace,
+ GFile *file);
G_END_DECLS
diff --git a/src/workbench/gb-workbench.c b/src/workbench/gb-workbench.c
index 2f1b6b1..40fc522 100644
--- a/src/workbench/gb-workbench.c
+++ b/src/workbench/gb-workbench.c
@@ -76,6 +76,21 @@ gb_workbench_get_active_workspace (GbWorkbench *workbench)
return GB_WORKSPACE (child);
}
+GbWorkspace *
+gb_workbench_get_workspace (GbWorkbench *workbench,
+ GType type)
+{
+ g_return_val_if_fail (GB_IS_WORKBENCH (workbench), NULL);
+ g_return_val_if_fail (g_type_is_a (type, GB_TYPE_WORKSPACE), NULL);
+
+ if (type == GB_TYPE_EDITOR_WORKSPACE)
+ return GB_WORKSPACE (workbench->priv->editor);
+ else if (type == GB_TYPE_DEVHELP_WORKSPACE)
+ return GB_WORKSPACE (workbench->priv->devhelp);
+
+ return NULL;
+}
+
static void
gb_workbench_workspace_changed (GbWorkbench *workbench,
GbWorkspace *workspace)
diff --git a/src/workbench/gb-workbench.h b/src/workbench/gb-workbench.h
index 1d5383e..4de6a6d 100644
--- a/src/workbench/gb-workbench.h
+++ b/src/workbench/gb-workbench.h
@@ -55,6 +55,8 @@ struct _GbWorkbenchClass
GType gb_workbench_get_type (void) G_GNUC_CONST;
GbWorkspace *gb_workbench_get_active_workspace (GbWorkbench *workbench);
+GbWorkspace *gb_workbench_get_workspace (GbWorkbench *workbench,
+ GType type);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]