[gnome-builder/document-manager] documents: add plumbing for save action via document stack.
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/document-manager] documents: add plumbing for save action via document stack.
- Date: Wed, 10 Dec 2014 09:42:31 +0000 (UTC)
commit 3f97eec00040dd9fa5b386fbc5ef9a16aa6d52eb
Author: Christian Hergert <christian hergert me>
Date: Wed Dec 10 01:41:31 2014 -0800
documents: add plumbing for save action via document stack.
src/documents/gb-document-stack.c | 27 +++++++++++++++++++++++++++
src/documents/gb-document.c | 18 ++++++++++++++++++
src/documents/gb-document.h | 4 ++++
src/resources/gtk/menus.ui | 18 ++++++++++++++----
src/resources/keybindings/default.ini | 4 ++--
5 files changed, 65 insertions(+), 6 deletions(-)
---
diff --git a/src/documents/gb-document-stack.c b/src/documents/gb-document-stack.c
index cc51773..5995678 100644
--- a/src/documents/gb-document-stack.c
+++ b/src/documents/gb-document-stack.c
@@ -439,6 +439,32 @@ gb_document_stack_preview_activate (GSimpleAction *action,
}
static void
+gb_document_stack_save_activate (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data)
+{
+ GbDocumentStackPrivate *priv;
+ GbDocumentStack *stack = user_data;
+
+ g_return_if_fail (GB_IS_DOCUMENT_STACK (stack));
+
+ priv = stack->priv;
+
+ if (priv->active_view)
+ {
+ GbDocument *document;
+
+ document = gb_document_view_get_document (priv->active_view);
+
+ if (document)
+ {
+ if (gb_document_get_modified (document))
+ gb_document_save (document);
+ }
+ }
+}
+
+static void
gb_document_stack_grab_focus (GtkWidget *widget)
{
GbDocumentStack *stack = (GbDocumentStack *)widget;
@@ -784,6 +810,7 @@ gb_document_stack_init (GbDocumentStack *self)
{ "focus-search", gb_document_stack_focus_search },
{ "close", gb_document_stack_close },
{ "preview", gb_document_stack_preview_activate },
+ { "save", gb_document_stack_save_activate },
};
self->priv = gb_document_stack_get_instance_private (self);
diff --git a/src/documents/gb-document.c b/src/documents/gb-document.c
index ac646eb..981d2d9 100644
--- a/src/documents/gb-document.c
+++ b/src/documents/gb-document.c
@@ -70,6 +70,24 @@ gb_document_create_view (GbDocument *document)
return ret;
}
+void
+gb_document_save (GbDocument *document)
+{
+ g_return_if_fail (GB_IS_DOCUMENT (document));
+
+ if (GB_DOCUMENT_GET_INTERFACE (document)->save)
+ GB_DOCUMENT_GET_INTERFACE (document)->save (document);
+}
+
+void
+gb_document_save_as (GbDocument *document)
+{
+ g_return_if_fail (GB_IS_DOCUMENT (document));
+
+ if (GB_DOCUMENT_GET_INTERFACE (document)->save_as)
+ GB_DOCUMENT_GET_INTERFACE (document)->save_as (document);
+}
+
static void
gb_document_default_init (GbDocumentInterface *iface)
{
diff --git a/src/documents/gb-document.h b/src/documents/gb-document.h
index bce458f..4e3502a 100644
--- a/src/documents/gb-document.h
+++ b/src/documents/gb-document.h
@@ -38,12 +38,16 @@ struct _GbDocumentInterface
gboolean (*get_modified) (GbDocument *document);
const gchar *(*get_title) (GbDocument *document);
GtkWidget *(*create_view) (GbDocument *document);
+ void (*save) (GbDocument *document);
+ void (*save_as) (GbDocument *document);
};
GType gb_document_get_type (void) G_GNUC_CONST;
gboolean gb_document_get_modified (GbDocument *document);
const gchar *gb_document_get_title (GbDocument *document);
GtkWidget *gb_document_create_view (GbDocument *document);
+void gb_document_save (GbDocument *document);
+void gb_document_save_as (GbDocument *document);
G_END_DECLS
diff --git a/src/resources/gtk/menus.ui b/src/resources/gtk/menus.ui
index 93ae4af..d828c13 100644
--- a/src/resources/gtk/menus.ui
+++ b/src/resources/gtk/menus.ui
@@ -116,23 +116,33 @@
</section>
<section>
<item>
- <attribute name="label" translatable="yes">Split Document _Left</attribute>
+ <attribute name="label" translatable="yes">Split Document Left</attribute>
<attribute name="action">stack.split-document-left</attribute>
</item>
<item>
- <attribute name="label" translatable="yes">Split Document _Right</attribute>
+ <attribute name="label" translatable="yes">Split Document Right</attribute>
<attribute name="action">stack.split-document-right</attribute>
</item>
</section>
<section>
<item>
- <attribute name="label" translatable="yes">Preview</attribute>
+ <attribute name="label" translatable="yes">Save</attribute>
+ <attribute name="action">stack.save</attribute>
+ </item>
+ <item>
+ <attribute name="label" translatable="yes">Save _As</attribute>
+ <attribute name="action">stack.save-as</attribute>
+ </item>
+ </section>
+ <section>
+ <item>
+ <attribute name="label" translatable="yes">_Preview</attribute>
<attribute name="action">stack.preview</attribute>
</item>
</section>
<section>
<item>
- <attribute name="label" translatable="yes">Close Document</attribute>
+ <attribute name="label" translatable="yes">_Close Document</attribute>
<attribute name="action">stack.close</attribute>
</item>
</section>
diff --git a/src/resources/keybindings/default.ini b/src/resources/keybindings/default.ini
index e1fd59d..fdc2aee 100644
--- a/src/resources/keybindings/default.ini
+++ b/src/resources/keybindings/default.ini
@@ -20,8 +20,6 @@ new-tab = <Control><Shift>T
# I'd like open to not have an accelerator by default eventually. We will move
# the majority of that feature to the global search making it unnecessary.
open = <Control><Shift>O
-save = <Control>S
-save-as = <Control><Shift>S
preview = <Control><Alt>P
[editor-frame]
@@ -43,3 +41,5 @@ move-document-left = <Control><Shift>H
move-document-right = <Control><Shift>L
split-document-left = <Control><Alt>H
split-document-right = <Control><Alt>L
+save = <Control>S
+save-as = <Control><Shift>S
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]