diff libgui/src/m-editor/file-editor.cc @ 27400:7cf857166440

connect signals when creating file_editor_tab in file editor * file-editor.h, file-editor.cc (file_editor::make_file_editor_tab): New function. Create file_editor_tab object and connect signals. (file_editor::add_file_editor_tab): Don't connect signals here. (file_editor::request_new_file, file_editor::request_open_file): Use make_file_editor_tab instead of creating object directly with new.
author John W. Eaton <jwe@octave.org>
date Thu, 12 Sep 2019 17:01:34 -0400
parents e449134870fb
children a3ec8c75ece3
line wrap: on
line diff
--- a/libgui/src/m-editor/file-editor.cc	Thu Sep 12 13:30:05 2019 -0400
+++ b/libgui/src/m-editor/file-editor.cc	Thu Sep 12 17:01:34 2019 -0400
@@ -467,7 +467,7 @@
     // editor tab has yet to be created and there is no object to
     // pass a signal to.  Hence, functionality is here.
 
-    file_editor_tab *fileEditorTab = new file_editor_tab (m_ced);
+    file_editor_tab *fileEditorTab = make_file_editor_tab (m_ced);
     add_file_editor_tab (fileEditorTab, "");  // new tab with empty title
     fileEditorTab->new_file (commands);       // title is updated here
     activate ();                              // focus editor and new tab
@@ -1410,7 +1410,7 @@
 
             // If <unnamed> was absent or modified, create a new tab.
             if (! fileEditorTab)
-              fileEditorTab = new file_editor_tab ();
+              fileEditorTab = make_file_editor_tab ();
 
             fileEditorTab->set_encoding (encoding);
             QString result = fileEditorTab->load_file (openFileName);
@@ -2234,13 +2234,10 @@
     check_actions ();
   }
 
-  void file_editor::add_file_editor_tab (file_editor_tab *f, const QString& fn,
-                                         int index)
+  file_editor_tab *
+  file_editor::make_file_editor_tab (const QString& directory)
   {
-    if (index == -1)
-      m_tab_widget->addTab (f, fn);
-    else
-      m_tab_widget->insertTab (index, f, fn);
+    file_editor_tab *f = new file_editor_tab (directory);
 
     // signals from the qscintilla edit area
     connect (f->qsci_edit_area (), SIGNAL (status_update (bool, bool)),
@@ -2440,6 +2437,17 @@
     connect (f, SIGNAL (interpreter_event (const meth_callback&)),
              this, SIGNAL (interpreter_event (const meth_callback&)));
 
+    return f;
+  }
+
+  void file_editor::add_file_editor_tab (file_editor_tab *f, const QString& fn,
+                                         int index)
+  {
+    if (index == -1)
+      m_tab_widget->addTab (f, fn);
+    else
+      m_tab_widget->insertTab (index, f, fn);
+
     m_tab_widget->setCurrentWidget (f);
 
     check_actions ();