[gnome-builder/editor-layout] track unsaved document number in tab.



commit 88816e417c2a2627348b9f8d1e0271090db7ea77
Author: Christian Hergert <christian hergert me>
Date:   Sun Nov 30 04:14:20 2014 -0800

    track unsaved document number in tab.

 src/editor/gb-editor-tab-private.h |    2 +
 src/editor/gb-editor-tab.c         |   54 ++++++++++++++++++++++++++++++++----
 2 files changed, 50 insertions(+), 6 deletions(-)
---
diff --git a/src/editor/gb-editor-tab-private.h b/src/editor/gb-editor-tab-private.h
index 75be605..8b65539 100644
--- a/src/editor/gb-editor-tab-private.h
+++ b/src/editor/gb-editor-tab-private.h
@@ -42,6 +42,8 @@ struct _GbEditorTabPrivate
 
   /* Objects owned by GbEditorTab */
   GbEditorDocument *document;
+
+  guint             unsaved_id;
 };
 
 GbEditorFrame *gb_editor_tab_get_last_frame (GbEditorTab *tab);
diff --git a/src/editor/gb-editor-tab.c b/src/editor/gb-editor-tab.c
index daa1deb..f86071e 100644
--- a/src/editor/gb-editor-tab.c
+++ b/src/editor/gb-editor-tab.c
@@ -20,6 +20,7 @@
 
 #include <glib/gi18n.h>
 
+#include "gb-doc-seq.h"
 #include "gb-editor-frame-private.h"
 #include "gb-editor-tab.h"
 #include "gb-editor-tab-private.h"
@@ -333,20 +334,51 @@ gb_editor_tab_grab_focus (GtkWidget *widget)
 }
 
 static void
+gb_editor_tab_update_title (GbEditorTab *tab)
+{
+  GtkSourceFile *file;
+  GFile *location;
+  gchar *title;
+
+  g_return_if_fail (GB_IS_EDITOR_TAB (tab));
+
+  file = gb_editor_document_get_file (tab->priv->document);
+  location = gtk_source_file_get_location (file);
+
+  if (location)
+    {
+      if (tab->priv->unsaved_id)
+        {
+          gb_doc_seq_release (tab->priv->unsaved_id);
+          tab->priv->unsaved_id = 0;
+        }
+
+      title = g_file_get_basename (location);
+      gb_tab_set_title (GB_TAB (tab), title);
+      g_free (title);
+    }
+  else
+    {
+      if (!tab->priv->unsaved_id)
+        {
+          tab->priv->unsaved_id = gb_doc_seq_acquire ();
+          title = g_strdup_printf (_("unsaved %u"), tab->priv->unsaved_id);
+          gb_tab_set_title (GB_TAB (tab), title);
+          g_free (title);
+        }
+    }
+}
+
+static void
 gb_editor_tab_on_notify_location (GbEditorTab   *tab,
                                   GParamSpec    *pspec,
                                   GtkSourceFile *file)
 {
-  gchar *title;
-  GFile *location;
 
   g_return_if_fail (GB_IS_EDITOR_TAB (tab));
   g_return_if_fail (GTK_SOURCE_IS_FILE (file));
 
-  location = gtk_source_file_get_location (file);
-  title = g_file_get_basename (location);
-  gb_tab_set_title (GB_TAB (tab), title);
-  g_free (title);
+  gb_editor_tab_update_title (tab);
 }
 
 static void
@@ -384,6 +416,8 @@ gb_editor_tab_constructed (GObject *object)
                            G_CALLBACK (gb_editor_tab_on_split_toggled),
                            tab,
                            G_CONNECT_SWAPPED);
+
+  gb_editor_tab_update_title (tab);
 }
 
 static void
@@ -413,6 +447,14 @@ gb_editor_tab_dispose (GObject *object)
 static void
 gb_editor_tab_finalize (GObject *object)
 {
+  GbEditorTabPrivate *priv = GB_EDITOR_TAB (object)->priv;
+
+  if (priv->unsaved_id)
+    {
+      gb_doc_seq_release (priv->unsaved_id);
+      priv->unsaved_id = 0;
+    }
+
   G_OBJECT_CLASS (gb_editor_tab_parent_class)->finalize (object);
 }
 


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