diff libgui/src/main-window.cc @ 29613:9367cba2a6d5

allow most dock widgets to be used from command line This change is an initial attempt to allow the documentation, file, history, variable editor, and workspace widgets to be opened from the command line. While running in command line mode, some connections between those widgets and the interpreter or between two widgets may be missing. The aim is to eventually make those work but this is a good start. These dock widgets are now owned by the base_qobject object and shared with the main_window object. If they exist when the main_window is created (possible if using the new terminal widget) then a pointer to the main_window object is passed to the dock_widget so that they may be docked there. If the desktop is closed and control returns to the command line, undocked widgets remain available. * octave-qobject.h, octave-qobject.cc (base_qobject::m_documentation_widget, base_qobject::m_file_browser_widget, base_qobject::m_history_widget, base_qobject::m_workspace_widget, base_qobject::m_editor_widget, base_qobject::m_variable_editor_widget): New data members. (base_qobject::documentation_widget, base_qobject::file_browser_widget, base_qobject::history_widget, base_qobject::workspace_widget, base_qobject::editor_widget, base_qobject::variable_editor_widget): New functions to create dock widgets as needed. (base_qobject::show_documentation_window, base_qobject::show_file_browser_window, base_qobject::show_command_history_window, base_qobject::show_workspace_window, base_qobject::edit_variable, base_qobject::handle_variable_editor_update): New functions. Make signal slot connections that do not require the main window here, not in main_window::construct_octave_qt_link. * files-dock-widget.cc (files_dock_widget::files_dock_widget): If no parent, call make_window. * documentation-dock-widget.cc (documentation_dock_widget::documentation_dock_widget): Likewise. * history-dock-widget.cc (history_dock_widget::history_dock_widget): Likewise. * workspace-view.cc (workspace_view::workspace_view): Likewise. * doc.m: Always give the event manager a chance to display the documentation, not just if the GUI is running. * documentation.cc (documentation::documentation): Make sub-objects children of the documentation object, not children of the parent of the documentation object. * main-window.h, main-window.cc (main_window::m_command_window, main_window::m_history_window, main_window::m_file_browser_window, main_window::m_doc_browser_window, main_window::m_editor_window, main_window::m_workspace_window, main_window::m_variable_editor_window): Manage objects with QPointer. (main_window::main_window): Acquire m_doc_browser_window, m_history_window, m_workspace_window, and m_variable_editor_window from octave_qobj. * octave-dock-widget.cc (octave_dock_widget::octave_dock_widget): Don't reference m_parent if it is nullptr. (octave_dock_widget::handle_settings): Likewise. Return immediately if settings is nullptr. (octave_dock_widget::set_main_window): New function. * variable-editor.h, variable-editor.cc (variable_editor::~variable_editor): Explicitly delete m_tool_bar and set it to nullptr. (variable_editor::edit_variable, variable_editor::notice_settings, variable_editor::variable_destroyed): Avoid referencing m_tool_bar if it is nullptr. * qt-interpreter-events.h, qt-interpreter-events.cc (qt_interpreter_events::show_documentation): Rename from show_doc. Change all uses. (qt_interpreter_events::register_documentation): Rename from register_doc. Change all uses. (qt_interpreter_events::unregister_documentation): Rename from unregister_doc. Change all uses. (qt_interpreter_events::show_file_browser, qt_interpreter_events::show_command_history, qt_interpreter_events::show_workspace): New functions. (qt_interpreter_events::show_documentation_signal): Rename from show_doc_signal. Change all uses. qt_interpreter_events::register_documentation_signal): Rename from register_doc_signal. Change all uses. qt_interpreter_events::unregister_documentation_signal): Rename from unregister_doc_signal. Change all uses. (qt_interpreter_events::show_file_browser_signal, qt_interpreter_events::show_command_history_signal, qt_interpreter_events::show_workspace_signal): New signals. * event-manager.h, event-manager.cc (F__event_manager_show_file_browser__, F__event_manager_show_command_history__, F__event_manager_show_workspace__): New functions. (F__event_manager_show_documentation__): Rename from __event_manager_show_doc__. Change all uses. (F__event_manager_register_documentation__): Rename from F__event_manager_register_doc__. Change all uses. (F__event_manager_unregister_documentation__): Rename from F__event_manager_unregister_doc__. Change all uses. (Fopenvar): Don't require GUI to be running. (interpreter_events::show_documentation): Rename from show_doc. Change all uses. (interpreter_events::register_documentation): Rename from register_doc. Change all uses. (interpreter_events::unregister_documentation): Rename from unregister_doc. Change all uses. (interpreter_events::show_file_browser, interpreter_events::show_command_history, interpreter_events::show_workspace): New functions. (event_manager::show_documentation): Rename from show_doc. Change all uses. (event_manager::register_documentation): Rename from register_doc. Change all uses. (event_manager::register_documentation): Rename from unregister_doc. Change all uses.
author John W. Eaton <jwe@octave.org>
date Thu, 29 Apr 2021 11:12:40 -0400
parents 9c04fea333ca
children 710c2cb73c2d
line wrap: on
line diff
--- a/libgui/src/main-window.cc	Tue May 04 15:33:58 2021 -0400
+++ b/libgui/src/main-window.cc	Thu Apr 29 11:12:40 2021 -0400
@@ -97,11 +97,12 @@
 {
   main_window::main_window (base_qobject& oct_qobj)
     : QMainWindow (), m_octave_qobj (oct_qobj),
-      m_workspace_model (nullptr),
-      m_status_bar (nullptr), m_command_window (nullptr),
-      m_history_window (nullptr), m_file_browser_window (nullptr),
-      m_doc_browser_window (nullptr), m_editor_window (nullptr),
-      m_workspace_window (nullptr), m_variable_editor_window (nullptr),
+      m_status_bar (nullptr),
+      m_command_window (nullptr),
+      m_history_window (nullptr),
+      m_file_browser_window (nullptr),
+      m_editor_window (nullptr),
+      m_workspace_window (nullptr),
       m_external_editor (new external_editor_interface (this, m_octave_qobj)),
       m_active_editor (m_external_editor), m_settings_dlg (nullptr),
       m_find_files_dlg (nullptr), m_set_path_dlg (nullptr),
@@ -154,8 +155,6 @@
     shortcut_manager& scmgr = m_octave_qobj.get_shortcut_manager ();
     scmgr.init_data ();
 
-    m_workspace_model = m_octave_qobj.get_workspace_model ();
-
     construct_central_widget ();
 
     m_status_bar = new QStatusBar (this);
@@ -171,20 +170,11 @@
     connect (this, &main_window::settings_changed,
              m_command_window, &terminal_dock_widget::notice_settings);
 
-    m_history_window = new history_dock_widget (this, m_octave_qobj);
-
-    make_dock_widget_connections (m_history_window);
-
-    connect (m_history_window, &history_dock_widget::command_create_script,
-             this, &main_window::new_file_signal);
-
-    connect (m_history_window, &history_dock_widget::information,
-             this, &main_window::report_status_message);
-
-    connect (m_history_window, &history_dock_widget::command_double_clicked,
-             this, &main_window::execute_command_in_terminal);
-
-    m_file_browser_window = new files_dock_widget (this, m_octave_qobj);
+    m_doc_browser_window = m_octave_qobj.documentation_widget (this);
+
+    make_dock_widget_connections (m_doc_browser_window);
+
+    m_file_browser_window = m_octave_qobj.file_browser_widget (this);
 
     make_dock_widget_connections (m_file_browser_window);
 
@@ -198,9 +188,28 @@
     connect (m_file_browser_window, &files_dock_widget::run_file_signal,
              this, &main_window::run_file_in_terminal);
 
-    m_doc_browser_window = new documentation_dock_widget (this, m_octave_qobj);
-
-    make_dock_widget_connections (m_doc_browser_window);
+    m_history_window = m_octave_qobj.history_widget (this);
+
+    make_dock_widget_connections (m_history_window);
+
+    connect (m_history_window, &history_dock_widget::command_create_script,
+             this, &main_window::new_file_signal);
+
+    connect (m_history_window, &history_dock_widget::information,
+             this, &main_window::report_status_message);
+
+    connect (m_history_window, &history_dock_widget::command_double_clicked,
+             this, &main_window::execute_command_in_terminal);
+
+    m_workspace_window = m_octave_qobj.workspace_widget (this);
+
+    make_dock_widget_connections (m_workspace_window);
+
+    connect (m_workspace_window, &workspace_view::command_requested,
+             this, &main_window::execute_command_in_terminal);
+
+    connect (m_workspace_window, &workspace_view::edit_variable_signal,
+             this, &main_window::edit_variable);
 
 #if defined (HAVE_QSCINTILLA)
     file_editor *editor = new file_editor (this, m_octave_qobj);
@@ -236,23 +245,13 @@
     m_editor_window = nullptr;
 #endif
 
-    m_variable_editor_window = new variable_editor (this, m_octave_qobj);
+    m_variable_editor_window = m_octave_qobj.variable_editor_widget (this);
 
     make_dock_widget_connections (m_variable_editor_window);
 
     connect (m_variable_editor_window, &variable_editor::command_signal,
              this, &main_window::execute_command_in_terminal);
 
-    m_workspace_window = new workspace_view (this, m_octave_qobj);
-
-    make_dock_widget_connections (m_workspace_window);
-
-    connect (m_workspace_window, &workspace_view::command_requested,
-             this, &main_window::execute_command_in_terminal);
-
-    connect (m_workspace_window, &workspace_view::edit_variable_signal,
-             this, &main_window::edit_variable);
-
     m_previous_dock = m_command_window;
 
     // Set active editor depending on editor window.  If the latter is
@@ -322,6 +321,31 @@
     focus_command_window ();
   }
 
+  main_window::~main_window (void)
+  {
+    // Prevent floating dock widgets from being deleted.
+
+    if (m_history_window->isFloating ())
+      m_history_window.clear ();
+
+    if (m_file_browser_window->isFloating ())
+      m_file_browser_window.clear ();
+
+    if (m_doc_browser_window->isFloating ())
+      m_doc_browser_window.clear ();
+
+#if 0
+    if (m_editor_window->isFloating ())
+      m_editor_window.clear ();
+#endif
+
+    if (m_workspace_window->isFloating ())
+      m_workspace_window.clear ();
+
+    if (m_variable_editor_window->isFloating ())
+      m_variable_editor_window.clear ();
+  }
+
   void main_window::make_dock_widget_connections (octave_dock_widget *dw)
   {
     connect (this, &main_window::init_window_menu,
@@ -1943,7 +1967,6 @@
         m_variable_editor_window->show ();
         m_variable_editor_window->raise ();
       }
-
   }
 
   void main_window::refresh_variable_editor (void)
@@ -2075,11 +2098,6 @@
   {
     setWindowIcon (QIcon (":/actions/icons/logo.png"));
 
-    m_workspace_window->setModel (m_workspace_model);
-
-    connect (m_workspace_model, &workspace_model::model_changed,
-             m_workspace_window, &workspace_view::handle_model_changed);
-
     interpreter_qobject *interp_qobj = m_octave_qobj.interpreter_qobj ();
 
     qt_interpreter_events *qt_link = interp_qobj->qt_link ();
@@ -2245,12 +2263,6 @@
                  m_command_window, &terminal_dock_widget::update_prompt);
       }
 
-    connect (qt_link, &qt_interpreter_events::set_workspace_signal,
-             m_workspace_model, &workspace_model::set_workspace);
-
-    connect (qt_link, &qt_interpreter_events::clear_workspace_signal,
-             m_workspace_model, &workspace_model::clear_workspace);
-
     connect (qt_link, &qt_interpreter_events::directory_changed_signal,
              this, &main_window::update_octave_directory);
 
@@ -2263,15 +2275,6 @@
     connect (qt_link, &qt_interpreter_events::execute_command_in_terminal_signal,
              this, &main_window::execute_command_in_terminal);
 
-    connect (qt_link, &qt_interpreter_events::set_history_signal,
-             m_history_window, &history_dock_widget::set_history);
-
-    connect (qt_link, &qt_interpreter_events::append_history_signal,
-             m_history_window, &history_dock_widget::append_history);
-
-    connect (qt_link, &qt_interpreter_events::clear_history_signal,
-             m_history_window, &history_dock_widget::clear_history);
-
     connect (qt_link, &qt_interpreter_events::enter_debugger_signal,
              this, &main_window::handle_enter_debugger);
 
@@ -2295,15 +2298,6 @@
     connect (qt_link, &qt_interpreter_events::update_breakpoint_marker_signal,
              this, &main_window::handle_update_breakpoint_marker_request);
 
-    connect (qt_link, &qt_interpreter_events::show_doc_signal,
-             m_doc_browser_window, &documentation_dock_widget::showDoc);
-
-    connect (qt_link, &qt_interpreter_events::register_doc_signal,
-             m_doc_browser_window, &documentation_dock_widget::registerDoc);
-
-    connect (qt_link, &qt_interpreter_events::unregister_doc_signal,
-             m_doc_browser_window, &documentation_dock_widget::unregisterDoc);
-
     connect (qt_link, &qt_interpreter_events::gui_status_update_signal,
              this, &main_window::handle_gui_status_update);