[gnome-builder: 7/7] GbEditorView: show infobar warning when document changes externally
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder: 7/7] GbEditorView: show infobar warning when document changes externally
- Date: Fri, 12 Dec 2014 07:58:36 +0000 (UTC)
commit 6d339af2e022d2a337e9c311f8e07ae259563cac
Author: Christian Hergert <christian hergert me>
Date: Thu Dec 11 23:57:48 2014 -0800
GbEditorView: show infobar warning when document changes externally
This should look familiar, it's intended to follow the design that
gedit took.
src/editor/gb-editor-view.c | 78 +++++++++++++++++++++++++++
src/resources/ui/gb-editor-view.ui | 102 +++++++++++++++++++++++++++++++++---
2 files changed, 172 insertions(+), 8 deletions(-)
---
diff --git a/src/editor/gb-editor-view.c b/src/editor/gb-editor-view.c
index 9173596..e83113e 100644
--- a/src/editor/gb-editor-view.c
+++ b/src/editor/gb-editor-view.c
@@ -42,6 +42,10 @@ struct _GbEditorViewPrivate
GtkToggleButton *split_button;
GbEditorFrame *frame;
GtkProgressBar *progress_bar;
+ GtkLabel *modified_label;
+ GtkButton *modified_reload_button;
+ GtkButton *modified_cancel_button;
+ GtkRevealer *modified_revealer;
};
G_DEFINE_TYPE_WITH_PRIVATE (GbEditorView, gb_editor_view, GB_TYPE_DOCUMENT_VIEW)
@@ -204,6 +208,58 @@ gb_editor_view_get_frame2 (GbEditorView *view)
}
static void
+gb_editor_view_hide_revealer_child (GtkRevealer *revealer)
+{
+ g_return_if_fail (GTK_IS_REVEALER (revealer));
+
+ gtk_revealer_set_reveal_child (revealer, FALSE);
+}
+
+static void
+gb_editor_view_file_changed_on_volume (GbEditorView *view,
+ GParamSpec *pspec,
+ GbEditorDocument *document)
+{
+ GtkSourceFile *source_file;
+ GFile *location;
+ gchar *path;
+ gchar *str;
+
+ g_return_if_fail (GB_IS_EDITOR_VIEW (view));
+ g_return_if_fail (GB_IS_EDITOR_DOCUMENT (document));
+
+ source_file = gb_editor_document_get_file (document);
+ location = gtk_source_file_get_location (source_file);
+
+ if (!location)
+ return;
+
+ if (g_file_is_native (location))
+ path = g_file_get_path (location);
+ else
+ path = g_file_get_uri (location);
+
+ str = g_strdup_printf (_("The file ā%sā was modified outside of Builder."),
+ path);
+
+ gtk_label_set_label (view->priv->modified_label, str);
+ gtk_revealer_set_reveal_child (view->priv->modified_revealer, TRUE);
+
+ g_free (path);
+ g_free (str);
+}
+
+static void
+gb_editor_view_reload_document (GbEditorView *view,
+ GtkButton *button)
+{
+ g_return_if_fail (GB_IS_EDITOR_VIEW (view));
+
+ gb_editor_document_reload (view->priv->document);
+ gtk_revealer_set_reveal_child (view->priv->modified_revealer, FALSE);
+}
+
+static void
gb_editor_view_connect (GbEditorView *view,
GbEditorDocument *document)
{
@@ -229,6 +285,24 @@ gb_editor_view_connect (GbEditorView *view,
G_CALLBACK (gb_editor_view_notify_progress),
view,
G_CONNECT_SWAPPED);
+
+ g_signal_connect_object (view->priv->modified_cancel_button,
+ "clicked",
+ G_CALLBACK (gb_editor_view_hide_revealer_child),
+ view->priv->modified_revealer,
+ G_CONNECT_SWAPPED);
+
+ g_signal_connect_object (view->priv->modified_reload_button,
+ "clicked",
+ G_CALLBACK (gb_editor_view_reload_document),
+ view,
+ G_CONNECT_SWAPPED);
+
+ g_signal_connect_object (document,
+ "notify::file-changed-on-volume",
+ G_CALLBACK (gb_editor_view_file_changed_on_volume),
+ view,
+ G_CONNECT_SWAPPED);
}
static void
@@ -452,6 +526,10 @@ gb_editor_view_class_init (GbEditorViewClass *klass)
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);
+ gtk_widget_class_bind_template_child_private (widget_class, GbEditorView, modified_revealer);
+ gtk_widget_class_bind_template_child_private (widget_class, GbEditorView, modified_label);
+ gtk_widget_class_bind_template_child_private (widget_class, GbEditorView, modified_cancel_button);
+ gtk_widget_class_bind_template_child_private (widget_class, GbEditorView, modified_reload_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 f174d3b..392247f 100644
--- a/src/resources/ui/gb-editor-view.ui
+++ b/src/resources/ui/gb-editor-view.ui
@@ -43,19 +43,105 @@
</object>
</child>
<child>
- <object class="GtkPaned" id="paned">
- <property name="orientation">vertical</property>
- <property name="expand">true</property>
+ <object class="GtkBox">
<property name="visible">true</property>
+ <property name="orientation">vertical</property>
+ <child>
+ <object class="GtkRevealer" id="modified_revealer">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="transition_type">GTK_REVEALER_TRANSITION_TYPE_SLIDE_DOWN</property>
+ <property name="reveal_child">False</property>
+ <child>
+ <object class="GtkInfoBar">
+ <property name="visible">True</property>
+ <property name="app_paintable">True</property>
+ <property name="can_focus">False</property>
+ <child internal-child="action_area">
+ <object class="GtkButtonBox">
+ <property name="can_focus">False</property>
+ <property name="spacing">6</property>
+ <property name="layout_style">end</property>
+ <child>
+ <object class="GtkButton" id="modified_reload_button">
+ <property name="label" translatable="yes">_Reload</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="use_underline">True</property>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="modified_cancel_button">
+ <property name="label" translatable="yes">_Cancel</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="use_underline">True</property>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child internal-child="content_area">
+ <object class="GtkBox">
+ <property name="can_focus">False</property>
+ <property name="spacing">16</property>
+ <child>
+ <object class="GtkLabel" id="modified_label">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="hexpand">True</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes">The file āā was modified outside of
Builder.</property>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ </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]