[gnome-builder] layout-view: make vfuncs return string copies



commit 780d89c0ef7df64d06f3652674040f2bcf5abb0d
Author: Christian Hergert <chergert redhat com>
Date:   Tue Jul 19 18:58:56 2016 -0700

    layout-view: make vfuncs return string copies
    
    We want these to return a copy of a string so that they work better from
    dynamic language bindings.

 libide/editor/ide-editor-view.c     |   10 ++++++----
 libide/workbench/ide-layout-view.c  |   24 ++++++++++++------------
 libide/workbench/ide-layout-view.h  |    8 ++++----
 plugins/devhelp/gbp-devhelp-view.c  |    4 ++--
 plugins/terminal/gb-terminal-view.c |    6 +++---
 5 files changed, 27 insertions(+), 25 deletions(-)
---
diff --git a/libide/editor/ide-editor-view.c b/libide/editor/ide-editor-view.c
index fdea589..1365333 100644
--- a/libide/editor/ide-editor-view.c
+++ b/libide/editor/ide-editor-view.c
@@ -185,10 +185,12 @@ ide_editor_view__buffer_changed_on_volume (IdeEditorView *self,
     }
 }
 
-static const gchar *
+static gchar *
 ide_editor_view_get_special_title (IdeLayoutView *view)
 {
-  return ((IdeEditorView *)view)->title;
+  g_assert (IDE_IS_EDITOR_VIEW (view));
+
+  return g_strdup (IDE_EDITOR_VIEW (view)->title);
 }
 
 static void
@@ -634,7 +636,7 @@ ide_editor_view_hierarchy_changed (GtkWidget *widget,
     ide_editor_view_load_addins (self);
 }
 
-static const gchar *
+static gchar *
 ide_editor_view_get_title (IdeLayoutView *view)
 {
   IdeEditorView *self = (IdeEditorView *)view;
@@ -642,7 +644,7 @@ ide_editor_view_get_title (IdeLayoutView *view)
   g_assert (IDE_IS_EDITOR_VIEW (self));
 
   if (self->document)
-    return ide_buffer_get_title (self->document);
+    return g_strdup (ide_buffer_get_title (self->document));
 
   return NULL;
 }
diff --git a/libide/workbench/ide-layout-view.c b/libide/workbench/ide-layout-view.c
index 75771ac..433cd9e 100644
--- a/libide/workbench/ide-layout-view.c
+++ b/libide/workbench/ide-layout-view.c
@@ -114,17 +114,15 @@ ide_layout_view_set_split_view (IdeLayoutView   *self,
     IDE_LAYOUT_VIEW_GET_CLASS (self)->set_split_view (self, split_view);
 }
 
+gchar *
+ide_layout_view_get_title (IdeLayoutView *self)
 {
   g_return_val_if_fail (IDE_IS_LAYOUT_VIEW (self), NULL);
 
-
-/* XXX: Make non-const */
-const gchar *
-ide_layout_view_get_title (IdeLayoutView *self)
   if (IDE_LAYOUT_VIEW_GET_CLASS (self)->get_title)
     return IDE_LAYOUT_VIEW_GET_CLASS (self)->get_title (self);
 
-  return _("untitled document");
+  return g_strdup (_("untitled document"));
 }
 
 void
@@ -196,11 +194,11 @@ ide_layout_view_get_property (GObject    *object,
       break;
 
     case PROP_SPECIAL_TITLE:
-      g_value_set_string (value, ide_layout_view_get_special_title (self));
+      g_value_take_string (value, ide_layout_view_get_special_title (self));
       break;
 
     case PROP_TITLE:
-      g_value_set_string (value, ide_layout_view_get_title (self));
+      g_value_take_string (value, ide_layout_view_get_title (self));
       break;
 
     default:
@@ -238,9 +236,11 @@ ide_layout_view_class_init (IdeLayoutViewClass *klass)
                          (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
 
   /*
-   * XXX:
+   * TODO:
    *
-   * This property should be removed after 3.18 when path bar lands.
+   * This property should be removed once we move to path bar.  It's purpose is
+   * to allow us to special format filenames which may not be needed by other
+   * views such as terminal/devhelp/etc.
    */
   properties [PROP_SPECIAL_TITLE] =
     g_param_spec_string ("special-title",
@@ -258,17 +258,17 @@ ide_layout_view_init (IdeLayoutView *self)
 }
 
 /*
- * XXX:
+ * TODO:
  *
  * 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 *
+gchar *
 ide_layout_view_get_special_title (IdeLayoutView *self)
 {
-  const gchar *ret = NULL;
+  gchar *ret = NULL;
 
   g_return_val_if_fail (IDE_IS_LAYOUT_VIEW (self), NULL);
 
diff --git a/libide/workbench/ide-layout-view.h b/libide/workbench/ide-layout-view.h
index 473f6e8..423abd4 100644
--- a/libide/workbench/ide-layout-view.h
+++ b/libide/workbench/ide-layout-view.h
@@ -37,8 +37,8 @@ struct _IdeLayoutViewClass
   gboolean       (*get_can_preview)       (IdeLayoutView             *self);
   gboolean       (*get_can_split)         (IdeLayoutView             *self);
   gboolean       (*get_modified)          (IdeLayoutView             *self);
-  const gchar   *(*get_title)             (IdeLayoutView             *self);
-  const gchar   *(*get_special_title)     (IdeLayoutView             *self);
+  gchar         *(*get_title)             (IdeLayoutView             *self);
+  gchar         *(*get_special_title)     (IdeLayoutView             *self);
   IdeLayoutView *(*create_split)          (IdeLayoutView             *self,
                                            GFile                     *file);
   void           (*set_split_view)        (IdeLayoutView             *self,
@@ -64,8 +64,8 @@ IdeLayoutView *ide_layout_view_create_split          (IdeLayoutView
                                                       GFile                     *file);
 gboolean       ide_layout_view_get_can_preview       (IdeLayoutView             *self);
 gboolean       ide_layout_view_get_can_split         (IdeLayoutView             *self);
-const gchar   *ide_layout_view_get_title             (IdeLayoutView             *self);
-const gchar   *ide_layout_view_get_special_title     (IdeLayoutView             *self);
+gchar         *ide_layout_view_get_title             (IdeLayoutView             *self);
+gchar         *ide_layout_view_get_special_title     (IdeLayoutView             *self);
 gboolean       ide_layout_view_get_modified          (IdeLayoutView             *self);
 void           ide_layout_view_set_split_view        (IdeLayoutView             *self,
                                                       gboolean                   split_view);
diff --git a/plugins/devhelp/gbp-devhelp-view.c b/plugins/devhelp/gbp-devhelp-view.c
index 5bf5639..7bc2e0a 100644
--- a/plugins/devhelp/gbp-devhelp-view.c
+++ b/plugins/devhelp/gbp-devhelp-view.c
@@ -50,14 +50,14 @@ gbp_devhelp_view_set_uri (GbpDevhelpView *self,
   webkit_web_view_load_uri (self->web_view1, uri);
 }
 
-static const gchar *
+static gchar *
 gbp_devhelp_view_get_title (IdeLayoutView *view)
 {
   GbpDevhelpView *self = (GbpDevhelpView *)view;
 
   g_assert (GBP_IS_DEVHELP_VIEW (view));
 
-  return webkit_web_view_get_title (self->web_view1);
+  return g_strdup (webkit_web_view_get_title (self->web_view1));
 }
 
 static void
diff --git a/plugins/terminal/gb-terminal-view.c b/plugins/terminal/gb-terminal-view.c
index de58bc6..4c8d7e9 100644
--- a/plugins/terminal/gb-terminal-view.c
+++ b/plugins/terminal/gb-terminal-view.c
@@ -268,10 +268,10 @@ notification_received_cb (VteTerminal    *terminal,
     }
 }
 
-static const gchar *
+static gchar *
 gb_terminal_get_title (IdeLayoutView *view)
 {
-  const gchar *title;
+  const gchar *title = NULL;
   GbTerminalView *self = (GbTerminalView *)view;
 
   g_assert (GB_IS_TERMINAL_VIEW (self));
@@ -281,7 +281,7 @@ gb_terminal_get_title (IdeLayoutView *view)
   else
     title = vte_terminal_get_window_title (self->terminal_top);
 
-  return title;
+  return g_strdup (title);
 }
 
 static gboolean


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