changeset 21565:08baf0ebc9a9

Reappropriate <unnamed> editor tab when opening a new file (bug #47529) * file-editor.cc (file_editor::request_open_file): Check for an unmodified unnamed file, and use it if one is present. (file_editor::find_tab_widget): Return true if file == tab_file == "". * file-editor-tab.cc (file_editor_tab::file_name_query): Report file name even if it is empty.
author Lachlan Andrew <lachlanbis@gmail.com>
date Sat, 26 Mar 2016 19:46:49 +1100
parents 87fc55416513
children 02826fb0f261
files libgui/src/m-editor/file-editor-tab.cc libgui/src/m-editor/file-editor.cc
diffstat 2 files changed, 18 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/m-editor/file-editor-tab.cc	Wed Mar 30 16:57:21 2016 -0700
+++ b/libgui/src/m-editor/file-editor-tab.cc	Sat Mar 26 19:46:49 2016 +1100
@@ -2267,9 +2267,8 @@
   if (ID != this && ID != 0)
     return;
 
-  // Unnamed files shouldn't be transmitted.
-  if (! _file_name.isEmpty ())
-    emit add_filename_to_list (_file_name, _encoding, this);
+  // This list also includes windows with name ""
+  emit add_filename_to_list (_file_name, _encoding, this);
 }
 
 void
--- a/libgui/src/m-editor/file-editor.cc	Wed Mar 30 16:57:21 2016 -0700
+++ b/libgui/src/m-editor/file-editor.cc	Sat Mar 26 19:46:49 2016 +1100
@@ -326,7 +326,8 @@
     {
       QString tab_file = p->first;
 
-      if (same_file (file.toStdString (), tab_file.toStdString ()))
+      if (same_file (file.toStdString (), tab_file.toStdString ())
+          || file == tab_file)     // needed as same_file ("","") is false.
         {
           retval = p->second.fet_ID;
           break;
@@ -454,7 +455,20 @@
         }
       else
         {
-          file_editor_tab *fileEditorTab = new file_editor_tab ();
+          file_editor_tab *fileEditorTab = 0;
+          // Reuse <unnamed> tab if it hasn't yet been modified.
+          tab = find_tab_widget ("");
+          if (tab)
+            {
+              fileEditorTab = static_cast<file_editor_tab *>(tab);
+              if (fileEditorTab->qsci_edit_area ()->isModified ())
+                fileEditorTab = 0;
+            }
+
+          // If <unnamed> was absent or modified, create a new tab.
+          if (!fileEditorTab)
+            fileEditorTab = new file_editor_tab ();
+
           if (fileEditorTab)
             {
               fileEditorTab->set_encoding (encoding);