[gnome-builder/editor-layout] add open document action
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/editor-layout] add open document action
- Date: Sun, 30 Nov 2014 13:21:49 +0000 (UTC)
commit c182cfe4778acbe565b51e561e866c9e956576ed
Author: Christian Hergert <christian hergert me>
Date: Sun Nov 30 05:09:22 2014 -0800
add open document action
src/editor/gb-editor-tab.c | 11 +++---
src/editor/gb-editor-tab.h | 16 ++++----
src/editor/gb-editor-workspace.c | 71 ++++++++++++++++++++++++++++++++++++--
3 files changed, 82 insertions(+), 16 deletions(-)
---
diff --git a/src/editor/gb-editor-tab.c b/src/editor/gb-editor-tab.c
index e04c9ee..01a1687 100644
--- a/src/editor/gb-editor-tab.c
+++ b/src/editor/gb-editor-tab.c
@@ -29,6 +29,12 @@
G_DEFINE_TYPE_WITH_PRIVATE (GbEditorTab, gb_editor_tab, GB_TYPE_TAB)
+GbEditorTab *
+gb_editor_tab_new (void)
+{
+ return g_object_new (GB_TYPE_EDITOR_TAB, NULL);
+}
+
static void
gb_editor_tab_progress_cb (goffset current_num_bytes,
goffset total_num_bytes,
@@ -247,11 +253,6 @@ gb_editor_tab_open_file (GbEditorTab *tab,
EXIT;
}
-void
-gb_editor_tab_open (GbEditorTab *tab)
-{
-}
-
static void
gb_editor_tab_on_frame_focused (GbEditorTab *tab,
GbEditorFrame *frame)
diff --git a/src/editor/gb-editor-tab.h b/src/editor/gb-editor-tab.h
index 84a6f08..e526fdc 100644
--- a/src/editor/gb-editor-tab.h
+++ b/src/editor/gb-editor-tab.h
@@ -51,14 +51,14 @@ struct _GbEditorTabClass
GbTabClass parent_class;
};
-GType gb_editor_tab_get_type (void) G_GNUC_CONST;
-void gb_editor_tab_save (GbEditorTab *tab);
-void gb_editor_tab_save_as (GbEditorTab *tab);
-void gb_editor_tab_open (GbEditorTab *tab);
-void gb_editor_tab_open_file (GbEditorTab *tab,
- GFile *file);
-void gb_editor_tab_scroll_up (GbEditorTab *tab);
-void gb_editor_tab_scroll_down (GbEditorTab *tab);
+GbEditorTab *gb_editor_tab_new (void);
+GType gb_editor_tab_get_type (void) G_GNUC_CONST;
+void gb_editor_tab_save (GbEditorTab *tab);
+void gb_editor_tab_save_as (GbEditorTab *tab);
+void gb_editor_tab_open_file (GbEditorTab *tab,
+ GFile *file);
+void gb_editor_tab_scroll_up (GbEditorTab *tab);
+void gb_editor_tab_scroll_down (GbEditorTab *tab);
G_END_DECLS
diff --git a/src/editor/gb-editor-workspace.c b/src/editor/gb-editor-workspace.c
index 5b463df..bfcd3ab 100644
--- a/src/editor/gb-editor-workspace.c
+++ b/src/editor/gb-editor-workspace.c
@@ -122,14 +122,78 @@ new_tab (GSimpleAction *action,
GbEditorWorkspace *workspace = user_data;
GbEditorTab *tab;
- tab = g_object_new (GB_TYPE_EDITOR_TAB,
- "visible", TRUE,
- NULL);
+ tab = gb_editor_tab_new ();
gtk_container_add (GTK_CONTAINER (workspace->priv->tab_grid),
GTK_WIDGET (tab));
+ gtk_widget_show (GTK_WIDGET (tab));
gtk_widget_grab_focus (GTK_WIDGET (tab));
}
+static void
+open_tab (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data)
+{
+ GbEditorWorkspace *workspace = user_data;
+ GtkFileChooserDialog *dialog;
+ GtkWidget *toplevel;
+ GtkWidget *suggested;
+ GtkResponseType response;
+ GbEditorTab *tab;
+
+ g_return_if_fail (GB_IS_EDITOR_WORKSPACE (workspace));
+
+ toplevel = gtk_widget_get_toplevel (GTK_WIDGET (workspace));
+
+ dialog = g_object_new (GTK_TYPE_FILE_CHOOSER_DIALOG,
+ "action", GTK_FILE_CHOOSER_ACTION_OPEN,
+ "local-only", FALSE,
+ "select-multiple", TRUE,
+ "show-hidden", FALSE,
+ "transient-for", toplevel,
+ "title", _("Open Document"),
+ NULL);
+
+ gtk_dialog_add_buttons (GTK_DIALOG (dialog),
+ _("Cancel"), GTK_RESPONSE_CANCEL,
+ _("Open"), GTK_RESPONSE_OK,
+ NULL);
+
+ gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
+
+ suggested = gtk_dialog_get_widget_for_response (GTK_DIALOG (dialog),
+ GTK_RESPONSE_OK);
+ gtk_style_context_add_class (gtk_widget_get_style_context (suggested),
+ GTK_STYLE_CLASS_SUGGESTED_ACTION);
+
+ response = gtk_dialog_run (GTK_DIALOG (dialog));
+
+ if (response == GTK_RESPONSE_OK)
+ {
+ GSList *files;
+ GSList *iter;
+
+ files = gtk_file_chooser_get_files (GTK_FILE_CHOOSER (dialog));
+
+ for (iter = files; iter; iter = iter->next)
+ {
+ GFile *file = iter->data;
+
+ tab = gb_editor_tab_new ();
+ gb_editor_tab_open_file (tab, file);
+ gtk_container_add (GTK_CONTAINER (workspace->priv->tab_grid),
+ GTK_WIDGET (tab));
+ gtk_widget_show (GTK_WIDGET (tab));
+
+ g_clear_object (&file);
+ }
+
+ g_slist_free (files);
+ }
+
+ gtk_widget_destroy (GTK_WIDGET (dialog));
+}
+
static GActionGroup *
gb_editor_workspace_get_actions (GbWorkspace *workspace)
{
@@ -186,6 +250,7 @@ gb_editor_workspace_init (GbEditorWorkspace *workspace)
const GActionEntry entries[] = {
{ "close-tab", close_tab },
{ "new-tab", new_tab },
+ { "open", open_tab },
{ "save", save_tab },
{ "save-as", save_as_tab },
{ "scroll-up", scroll_up_tab },
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]