[gnome-builder] views: add 3.18 hack for special view title



commit e933b421204160fc166bf2775632dac602db71c7
Author: Christian Hergert <christian hergert me>
Date:   Tue Sep 15 23:01:43 2015 -0700

    views: add 3.18 hack for special view title
    
    Until we get our new path bar, we need to massage this data by hand. This
    lets us keep the normal title in the list box and a "special" title in
    the documents button.

 src/editor/gb-editor-view.c |    4 +-
 src/views/gb-view-stack.c   |    2 +-
 src/views/gb-view.c         |   60 ++++++++++++++++++++++++++++++++++++++++++-
 src/views/gb-view.h         |    2 +
 4 files changed, 64 insertions(+), 4 deletions(-)
---
diff --git a/src/editor/gb-editor-view.c b/src/editor/gb-editor-view.c
index f371c59..80cb75e 100644
--- a/src/editor/gb-editor-view.c
+++ b/src/editor/gb-editor-view.c
@@ -203,7 +203,7 @@ gb_editor_view__buffer_changed_on_volume (GbEditorView *self,
 }
 
 static const gchar *
-gb_editor_view_get_title (GbView *view)
+gb_editor_view_get_special_title (GbView *view)
 {
   return ((GbEditorView *)view)->title;
 }
@@ -597,7 +597,7 @@ gb_editor_view_class_init (GbEditorViewClass *klass)
 
   view_class->create_split = gb_editor_view_create_split;
   view_class->get_document = gb_editor_view_get_document;
-  view_class->get_title = gb_editor_view_get_title;
+  view_class->get_special_title = gb_editor_view_get_special_title;
   view_class->get_modified = gb_editor_view_get_modified;
   view_class->set_split_view = gb_editor_view_set_split_view;
   view_class->set_back_forward_list = gb_editor_view_set_back_forward_list;
diff --git a/src/views/gb-view-stack.c b/src/views/gb-view-stack.c
index 432c6c4..476790c 100644
--- a/src/views/gb-view-stack.c
+++ b/src/views/gb-view-stack.c
@@ -669,7 +669,7 @@ gb_view_stack_set_active_view (GbViewStack *self,
           self->focus_history = g_list_remove (self->focus_history, active_view);
           self->focus_history = g_list_prepend (self->focus_history, active_view);
 
-          binding = g_object_bind_property (active_view, "title",
+          binding = g_object_bind_property (active_view, "special-title",
                                             self->title_label, "label",
                                             G_BINDING_DEFAULT | G_BINDING_SYNC_CREATE);
           ide_set_weak_pointer (&self->title_binding, binding);
diff --git a/src/views/gb-view.c b/src/views/gb-view.c
index bb98d7d..0a71094 100644
--- a/src/views/gb-view.c
+++ b/src/views/gb-view.c
@@ -37,6 +37,7 @@ enum {
   PROP_CAN_SPLIT,
   PROP_DOCUMENT,
   PROP_MODIFIED,
+  PROP_SPECIAL_TITLE,
   PROP_TITLE,
   LAST_PROP
 };
@@ -202,6 +203,23 @@ gb_view_get_modified (GbView *self)
 }
 
 static void
+gb_view_notify (GObject    *object,
+                GParamSpec *pspec)
+{
+  /*
+   * XXX:
+   *
+   * This should get removed after 3.18 when path bar lands.
+   * This also notifies of special-title after title is emitted.
+   */
+  if (pspec == gParamSpecs [PROP_TITLE])
+    g_object_notify_by_pspec (object, gParamSpecs [PROP_SPECIAL_TITLE]);
+
+  if (G_OBJECT_CLASS (gb_view_parent_class)->notify)
+    G_OBJECT_CLASS (gb_view_parent_class)->notify (object, pspec);
+}
+
+static void
 gb_view_destroy (GtkWidget *widget)
 {
   GbView *self = (GbView *)widget;
@@ -234,6 +252,10 @@ gb_view_get_property (GObject    *object,
       g_value_set_boolean (value, gb_view_get_modified (self));
       break;
 
+    case PROP_SPECIAL_TITLE:
+      g_value_set_string (value, gb_view_get_special_title (self));
+      break;
+
     case PROP_TITLE:
       g_value_set_string (value, gb_view_get_title (self));
       break;
@@ -243,7 +265,6 @@ gb_view_get_property (GObject    *object,
     }
 }
 
-
 static void
 gb_view_class_init (GbViewClass *klass)
 {
@@ -251,6 +272,7 @@ gb_view_class_init (GbViewClass *klass)
   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
 
   object_class->get_property = gb_view_get_property;
+  object_class->notify = gb_view_notify;
 
   widget_class->destroy = gb_view_destroy;
 
@@ -285,6 +307,18 @@ gb_view_class_init (GbViewClass *klass)
                          NULL,
                          (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
 
+  /*
+   * XXX:
+   *
+   * This property should be removed after 3.18 when path bar lands.
+   */
+  gParamSpecs [PROP_SPECIAL_TITLE] =
+    g_param_spec_string ("special-title",
+                         "Special Title",
+                         "The special title to be displayed in the document menu button.",
+                         NULL,
+                         (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+
   g_object_class_install_properties (object_class, LAST_PROP, gParamSpecs);
 }
 
@@ -339,3 +373,27 @@ gb_view_get_menu (GbView *self)
 
   return priv->menu;
 }
+
+/*
+ * XXX:
+ *
+ * This function is a hack in place for 3.18 until we get the path bar
+ * which will provide a better view of file paths. It should be removed
+ * after 3.18 when path bar lands. Also remove the "special-title"
+ * property.
+ */
+const gchar *
+gb_view_get_special_title (GbView *self)
+{
+  const gchar *ret = NULL;
+
+  g_return_val_if_fail (GB_IS_VIEW (self), NULL);
+
+  if (GB_VIEW_GET_CLASS (self)->get_special_title)
+    ret = GB_VIEW_GET_CLASS (self)->get_special_title (self);
+
+  if (ret == NULL)
+    ret = gb_view_get_title (self);
+
+  return ret;
+}
diff --git a/src/views/gb-view.h b/src/views/gb-view.h
index 13d8571..fa34f6b 100644
--- a/src/views/gb-view.h
+++ b/src/views/gb-view.h
@@ -39,6 +39,7 @@ struct _GbViewClass
   GbDocument  *(*get_document)          (GbView             *self);
   gboolean     (*get_modified)          (GbView             *self);
   const gchar *(*get_title)             (GbView             *self);
+  const gchar *(*get_special_title)     (GbView             *self);
   GbView      *(*create_split)          (GbView             *self);
   void         (*set_split_view)        (GbView             *self,
                                          gboolean            split_view);
@@ -54,6 +55,7 @@ gboolean     gb_view_get_can_preview       (GbView             *self);
 gboolean     gb_view_get_can_split         (GbView             *self);
 GbDocument  *gb_view_get_document          (GbView             *self);
 const gchar *gb_view_get_title             (GbView             *self);
+const gchar *gb_view_get_special_title     (GbView             *self);
 GtkWidget   *gb_view_get_controls          (GbView             *self);
 gboolean     gb_view_get_modified          (GbView             *self);
 void         gb_view_set_split_view        (GbView             *self,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]