[gnome-builder/document-manager] editor: implement saving via document interface
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/document-manager] editor: implement saving via document interface
- Date: Wed, 10 Dec 2014 09:42:36 +0000 (UTC)
commit 2c22f44b4fe362f75524b2100ddb9d48b76cac53
Author: Christian Hergert <christian hergert me>
Date: Wed Dec 10 01:41:59 2014 -0800
editor: implement saving via document interface
src/editor/gb-editor-document.c | 11 +++++++
src/editor/gb-editor-document.h | 1 +
src/editor/gb-editor-view.c | 59 +++++++++++++++++++++++++++++++++++-
src/resources/ui/gb-editor-view.ui | 34 ++++++++++++++++-----
4 files changed, 96 insertions(+), 9 deletions(-)
---
diff --git a/src/editor/gb-editor-document.c b/src/editor/gb-editor-document.c
index beab52a..7d46e4e 100644
--- a/src/editor/gb-editor-document.c
+++ b/src/editor/gb-editor-document.c
@@ -672,6 +672,16 @@ gb_editor_document_save_finish (GbEditorDocument *document,
}
static void
+gb_editor_document_save (GbDocument *document)
+{
+ GbEditorDocument *self = (GbEditorDocument *)document;
+
+ g_return_if_fail (GB_IS_EDITOR_DOCUMENT (self));
+
+ gb_editor_document_save_async (self, NULL, NULL, NULL);
+}
+
+static void
gb_editor_document_restore_insert (GbEditorDocument *document)
{
GbEditorFileMarks *marks;
@@ -1051,4 +1061,5 @@ gb_editor_document_init_document (GbDocumentInterface *iface)
iface->get_modified = gb_editor_document_get_modified;
iface->get_title = gb_editor_document_get_title;
iface->create_view = gb_editor_document_create_view;
+ iface->save = gb_editor_document_save;
}
diff --git a/src/editor/gb-editor-document.h b/src/editor/gb-editor-document.h
index ce7a937..d132c16 100644
--- a/src/editor/gb-editor-document.h
+++ b/src/editor/gb-editor-document.h
@@ -60,6 +60,7 @@ GType gb_editor_document_get_type (void) G_
GtkSourceFile *gb_editor_document_get_file (GbEditorDocument *document);
void gb_editor_document_set_file (GbEditorDocument *document,
GtkSourceFile *file);
+gdouble gb_editor_document_get_progress (GbEditorDocument *document);
GbSourceChangeMonitor *gb_editor_document_get_change_monitor (GbEditorDocument *document);
GbSourceCodeAssistant *gb_editor_document_get_code_assistant (GbEditorDocument *document);
gboolean gb_editor_document_get_trim_trailing_whitespace (GbEditorDocument *document);
diff --git a/src/editor/gb-editor-view.c b/src/editor/gb-editor-view.c
index fcdfbea..5d99031 100644
--- a/src/editor/gb-editor-view.c
+++ b/src/editor/gb-editor-view.c
@@ -16,24 +16,32 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+
#define G_LOG_DOMAIN "editor-view"
#include <glib/gi18n.h>
+#include "gb-animation.h"
#include "gb-editor-frame.h"
#include "gb-editor-frame-private.h"
#include "gb-editor-view.h"
+#include "gb-glib.h"
#include "gb-html-document.h"
+#include "gb-widget.h"
struct _GbEditorViewPrivate
{
/* References owned by view */
GbEditorDocument *document;
+ /* Weak references */
+ GbAnimation *progress_anim;
+
/* References owned by GtkWidget template */
GtkPaned *paned;
GtkToggleButton *split_button;
GbEditorFrame *frame;
+ GtkProgressBar *progress_bar;
};
G_DEFINE_TYPE_WITH_PRIVATE (GbEditorView, gb_editor_view, GB_TYPE_DOCUMENT_VIEW)
@@ -65,6 +73,45 @@ gb_editor_view_notify_language (GbEditorView *view,
g_object_notify (G_OBJECT (view), "can-preview");
}
+static void
+gb_editor_view_notify_progress (GbEditorView *view,
+ GParamSpec *pspec,
+ GbEditorDocument *document)
+{
+ GbEditorViewPrivate *priv;
+ gdouble progress;
+
+ g_return_if_fail (GB_IS_EDITOR_VIEW (view));
+ g_return_if_fail (GB_IS_EDITOR_DOCUMENT (document));
+
+ priv = view->priv;
+
+ progress = gb_editor_document_get_progress (document);
+
+ if (!gtk_widget_get_visible (GTK_WIDGET (priv->progress_bar)))
+ {
+ gtk_progress_bar_set_fraction (priv->progress_bar, 0.0);
+ gtk_widget_set_opacity (GTK_WIDGET (priv->progress_bar), 1.0);
+ gtk_widget_show (GTK_WIDGET (priv->progress_bar));
+ }
+
+ if (priv->progress_anim)
+ gb_animation_stop (priv->progress_anim);
+
+ gb_clear_weak_pointer (&priv->progress_anim);
+
+ priv->progress_anim = gb_object_animate (priv->progress_bar,
+ GB_ANIMATION_LINEAR,
+ 250,
+ NULL,
+ "fraction", progress,
+ NULL);
+ gb_set_weak_pointer (priv->progress_anim, &priv->progress_anim);
+
+ if (progress == 1.0)
+ gb_widget_fade_hide (GTK_WIDGET (priv->progress_bar));
+}
+
static gboolean
gb_editor_view_get_can_preview (GbDocumentView *view)
{
@@ -73,7 +120,7 @@ gb_editor_view_get_can_preview (GbDocumentView *view)
GtkSourceBuffer *buffer;
const gchar *lang_id;
- g_return_val_if_fail (GB_IS_EDITOR_VIEW (view), NULL);
+ g_return_val_if_fail (GB_IS_EDITOR_VIEW (view), FALSE);
priv = GB_EDITOR_VIEW (view)->priv;
@@ -156,6 +203,12 @@ gb_editor_view_connect (GbEditorView *view,
G_CALLBACK (gb_editor_view_notify_language),
view,
G_CONNECT_SWAPPED);
+
+ g_signal_connect_object (document,
+ "notify::progress",
+ G_CALLBACK (gb_editor_view_notify_progress),
+ view,
+ G_CONNECT_SWAPPED);
}
static void
@@ -176,6 +229,9 @@ gb_editor_view_disconnect (GbEditorView *view,
g_signal_handlers_disconnect_by_func (document,
G_CALLBACK (gb_editor_view_notify_language),
view);
+ g_signal_handlers_disconnect_by_func (document,
+ G_CALLBACK (gb_editor_view_notify_progress),
+ view);
}
static GbDocument *
@@ -374,6 +430,7 @@ gb_editor_view_class_init (GbEditorViewClass *klass)
"/org/gnome/builder/ui/gb-editor-view.ui");
gtk_widget_class_bind_template_child_private (widget_class, GbEditorView, frame);
gtk_widget_class_bind_template_child_private (widget_class, GbEditorView, paned);
+ gtk_widget_class_bind_template_child_private (widget_class, GbEditorView, progress_bar);
gtk_widget_class_bind_template_child_private (widget_class, GbEditorView, split_button);
g_type_ensure (GB_TYPE_EDITOR_FRAME);
diff --git a/src/resources/ui/gb-editor-view.ui b/src/resources/ui/gb-editor-view.ui
index d5bfd83..f174d3b 100644
--- a/src/resources/ui/gb-editor-view.ui
+++ b/src/resources/ui/gb-editor-view.ui
@@ -27,19 +27,37 @@
</object>
</child>
<child>
- <object class="GtkPaned" id="paned">
- <property name="orientation">vertical</property>
- <property name="vexpand">true</property>
+ <object class="GtkOverlay">
<property name="visible">true</property>
+ <property name="expand">true</property>
+ <child type="overlay">
+ <object class="GtkProgressBar" id="progress_bar">
+ <property name="visible">false</property>
+ <property name="fraction">0.0</property>
+ <property name="valign">start</property>
+ <property name="halign">fill</property>
+ <property name="vexpand">false</property>
+ <style>
+ <class name="osd"/>
+ </style>
+ </object>
+ </child>
<child>
- <object class="GbEditorFrame" id="frame">
+ <object class="GtkPaned" id="paned">
+ <property name="orientation">vertical</property>
<property name="expand">true</property>
<property name="visible">true</property>
+ <child>
+ <object class="GbEditorFrame" id="frame">
+ <property name="expand">true</property>
+ <property name="visible">true</property>
+ </object>
+ <packing>
+ <property name="resize">true</property>
+ <property name="shrink">false</property>
+ </packing>
+ </child>
</object>
- <packing>
- <property name="resize">true</property>
- <property name="shrink">false</property>
- </packing>
</child>
</object>
</child>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]