[gnome-builder] libide: add plumbing for open file
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] libide: add plumbing for open file
- Date: Mon, 21 Dec 2015 07:46:36 +0000 (UTC)
commit 04ad23e7d5fde18373e1bd6dccf6525f64e7102d
Author: Christian Hergert <chergert redhat com>
Date: Sun Nov 15 22:57:08 2015 -0800
libide: add plumbing for open file
We still don't have any addins responding to the uri, but this plumbs
things so that they will have a uri to respond to.
data/gtk/menus.ui | 6 +-
libide/Makefile.am | 1 +
libide/greeter/ide-greeter-perspective.c | 2 +-
libide/ide-workbench-actions.c | 106 ++++++++++++++++++++++++++++++
libide/ide-workbench-private.h | 3 +-
libide/ide-workbench.c | 7 ++-
6 files changed, 118 insertions(+), 7 deletions(-)
---
diff --git a/data/gtk/menus.ui b/data/gtk/menus.ui
index e15c61a..2d6fe4e 100644
--- a/data/gtk/menus.ui
+++ b/data/gtk/menus.ui
@@ -69,14 +69,14 @@
</section>
<section>
<item>
- <attribute name="label" translatable="yes">_New Document</attribute>
+ <attribute name="label" translatable="yes">_New File</attribute>
<attribute name="action">workbench.new-document</attribute>
</item>
</section>
<section>
<item>
- <attribute name="label" translatable="yes">_Open</attribute>
- <attribute name="action">workbench.open</attribute>
+ <attribute name="label" translatable="yes">_Open File</attribute>
+ <attribute name="action">win.open-with-dialog</attribute>
</item>
</section>
<section>
diff --git a/libide/Makefile.am b/libide/Makefile.am
index c8774d1..aa36bfa 100644
--- a/libide/Makefile.am
+++ b/libide/Makefile.am
@@ -278,6 +278,7 @@ libide_1_0_la_SOURCES = \
ide-source-view-movements.h \
ide-text-iter.c \
ide-text-iter.h \
+ ide-workbench-actions.c \
ide-workbench-private.h \
ide-worker-manager.c \
ide-worker-manager.h \
diff --git a/libide/greeter/ide-greeter-perspective.c b/libide/greeter/ide-greeter-perspective.c
index fc9d577..de385af 100644
--- a/libide/greeter/ide-greeter-perspective.c
+++ b/libide/greeter/ide-greeter-perspective.c
@@ -422,7 +422,7 @@ ide_greeter_perspective_context_cb (GObject *object,
}
workbench = IDE_WORKBENCH (gtk_widget_get_toplevel (GTK_WIDGET (self)));
- _ide_workbench_set_context (workbench, context);
+ ide_workbench_set_context (workbench, context);
}
static void
diff --git a/libide/ide-workbench-actions.c b/libide/ide-workbench-actions.c
new file mode 100644
index 0000000..27552c2
--- /dev/null
+++ b/libide/ide-workbench-actions.c
@@ -0,0 +1,106 @@
+/* ide-workbench-actions.c
+ *
+ * Copyright (C) 2015 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#define G_LOG_DOMAIN "ide-workbench"
+
+#include <glib/gi18n.h>
+
+#include "ide-debug.h"
+#include "ide-workbench.h"
+#include "ide-workbench-private.h"
+
+static void
+ide_workbench_actions_open_with_dialog_cb (GObject *object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ IdeWorkbench *self = (IdeWorkbench *)object;
+ GError *error = NULL;
+
+ IDE_ENTRY;
+
+ g_assert (IDE_IS_WORKBENCH (self));
+
+ if (!ide_workbench_open_files_finish (self, result, &error))
+ {
+ g_warning ("%s", error->message);
+ g_clear_error (&error);
+ }
+
+ IDE_EXIT;
+}
+
+static void
+ide_workbench_actions_open_with_dialog (GSimpleAction *action,
+ GVariant *param,
+ gpointer user_data)
+{
+ IdeWorkbench *self = user_data;
+ GtkWidget *button;
+ GtkWidget *dialog;
+ gint ret;
+
+ IDE_ENTRY;
+
+ g_assert (IDE_IS_WORKBENCH (self));
+
+ dialog = gtk_file_chooser_dialog_new (_("Open File"),
+ GTK_WINDOW (self),
+ GTK_FILE_CHOOSER_ACTION_OPEN,
+ _("Cancel"), GTK_RESPONSE_CANCEL,
+ _("Open"), GTK_RESPONSE_OK,
+ NULL);
+
+ button = gtk_dialog_get_widget_for_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
+ gtk_style_context_add_class (gtk_widget_get_style_context (button),
+ GTK_STYLE_CLASS_SUGGESTED_ACTION);
+
+ /*
+ * TODO: Allow workbench addins to specify file filters?
+ * Do we want to move this to a custom interface and use that
+ * for file loading as well?
+ */
+
+ ret = gtk_dialog_run (GTK_DIALOG (dialog));
+
+ if (ret == GTK_RESPONSE_OK)
+ {
+ g_autoptr(GFile) file = NULL;
+
+ IDE_PROBE;
+
+ file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog));
+ ide_workbench_open_files_async (self, &file, 1, NULL,
+ ide_workbench_actions_open_with_dialog_cb,
+ NULL);
+ }
+
+ gtk_widget_destroy (dialog);
+
+ IDE_EXIT;
+}
+
+void
+ide_workbench_actions_init (IdeWorkbench *self)
+{
+ const GActionEntry actions[] = {
+ { "open-with-dialog", ide_workbench_actions_open_with_dialog },
+ };
+
+ g_action_map_add_action_entries (G_ACTION_MAP (self), actions, G_N_ELEMENTS (actions), self);
+}
diff --git a/libide/ide-workbench-private.h b/libide/ide-workbench-private.h
index ec8cecd..198da01 100644
--- a/libide/ide-workbench-private.h
+++ b/libide/ide-workbench-private.h
@@ -53,8 +53,9 @@ typedef struct
gpointer user_data;
} IdeWorkbenchForeach;
-void _ide_workbench_set_context (IdeWorkbench *workbench,
+void ide_workbench_set_context (IdeWorkbench *workbench,
IdeContext *context);
+void ide_workbench_actions_init (IdeWorkbench *self);
G_END_DECLS
diff --git a/libide/ide-workbench.c b/libide/ide-workbench.c
index 5f00424..3d61dc4 100644
--- a/libide/ide-workbench.c
+++ b/libide/ide-workbench.c
@@ -233,9 +233,12 @@ ide_workbench_init (IdeWorkbench *self)
{
gtk_widget_init_template (GTK_WIDGET (self));
+ ide_workbench_actions_init (self);
+
ide_workbench_init_greeter (self);
ide_workbench_init_editor (self);
ide_workbench_init_preferences (self);
+
ide_window_settings_register (GTK_WINDOW (self));
g_signal_connect_object (self->perspectives_stack,
@@ -331,8 +334,8 @@ ide_workbench_get_context (IdeWorkbench *self)
}
void
-_ide_workbench_set_context (IdeWorkbench *self,
- IdeContext *context)
+ide_workbench_set_context (IdeWorkbench *self,
+ IdeContext *context)
{
g_return_if_fail (IDE_IS_WORKBENCH (self));
g_return_if_fail (IDE_IS_CONTEXT (context));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]