[latexila] Document: use tepl_file_get_short_name()



commit dcda511499b9cb25faa2fde7220e6cfcd26f9d3a
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Sun Aug 6 16:08:40 2017 +0200

    Document: use tepl_file_get_short_name()
    
    When the location is null, the TeplFile:short-name is set synchronously.
    On the other hand when the location isn't null, the :short-name is
    updated asynchronously inside TeplFile, so it's dangerous to call
    get_short_name() without listening to notify::short-name.
    
    So use get_short_name() only when location is null, as a first step.

 src/document.vala |   38 ++------------------------------------
 1 files changed, 2 insertions(+), 36 deletions(-)
---
diff --git a/src/document.vala b/src/document.vala
index 9da254f..55c991f 100644
--- a/src/document.vala
+++ b/src/document.vala
@@ -24,7 +24,6 @@ public class Document : Tepl.Buffer
     public File location { get; set; }
     public bool readonly { get; set; default = false; }
     public weak DocumentTab tab;
-    public uint _unsaved_doc_num = 0;
     public int project_id { get; set; default = -1; }
     private bool backup_made = false;
     private string _etag;
@@ -299,7 +298,7 @@ public class Document : Tepl.Buffer
     public string get_uri_for_display ()
     {
         if (location == null)
-            return get_unsaved_document_name ();
+            return get_file ().get_short_name ();
 
         return Latexila.utils_replace_home_dir_with_tilde (location.get_parse_name ());
     }
@@ -307,44 +306,11 @@ public class Document : Tepl.Buffer
     public string get_short_name_for_display ()
     {
         if (location == null)
-            return get_unsaved_document_name ();
+            return get_file ().get_short_name ();
 
         return location.get_basename ();
     }
 
-    private string get_unsaved_document_name ()
-    {
-        uint num = get_unsaved_document_num ();
-        return _("Untitled Document") + @" $num";
-    }
-
-    private uint get_unsaved_document_num ()
-    {
-        return_val_if_fail (location == null, 0);
-
-        if (_unsaved_doc_num > 0)
-            return _unsaved_doc_num;
-
-        // get all unsaved document numbers
-        uint[] all_nums = {};
-        foreach (Document doc in LatexilaApp.get_instance ().get_documents ())
-        {
-            // avoid infinite loop
-            if (doc == this)
-                continue;
-
-            if (doc.location == null)
-                all_nums += doc.get_unsaved_document_num ();
-        }
-
-        // take the first free num
-        uint num;
-        for (num = 1 ; num in all_nums ; num++);
-
-        _unsaved_doc_num = num;
-        return num;
-    }
-
     public bool is_externally_modified ()
     {
         if (location == null)


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