diff --git a/libgui/src/main-window.cc b/libgui/src/main-window.cc --- a/libgui/src/main-window.cc +++ b/libgui/src/main-window.cc @@ -1639,8 +1639,15 @@ namespace octave } // Restore the geometry of all dock-widgets + for (auto *widget : dock_widget_list ()) { + // Leave any widgets that existed before main_window was created + // as they were. + + if (widget->adopted ()) + continue; + QString name = widget->objectName (); if (! name.isEmpty ()) @@ -2970,7 +2977,7 @@ namespace octave // Slot for resetting the window layout to the default one hide (); showNormal (); // Unmaximize - do_reset_windows (false); // Add all widgets + do_reset_windows (false, true, true); // Add all widgets // Re-add after giving time: This seems to be a reliable way to // reset the main window's layout QTimer::singleShot (250, this, [=] () { do_reset_windows (); }); @@ -2979,7 +2986,7 @@ namespace octave // Create the default layout of the main window. Do not use // restoreState () and restoreGeometry () with default values since // this might lead to problems when the Qt version changes - void main_window::do_reset_windows (bool show, bool save) + void main_window::do_reset_windows (bool show, bool save, bool force_all) { // Set main window default geometry and store its width for // later resizing the command window @@ -3001,17 +3008,29 @@ namespace octave #endif // Add the dock widgets and show them - addDockWidget (Qt::LeftDockWidgetArea, m_file_browser_window); - addDockWidget (Qt::LeftDockWidgetArea, m_workspace_window); - addDockWidget (Qt::LeftDockWidgetArea, m_history_window); - - addDockWidget (Qt::RightDockWidgetArea, m_command_window); - - addDockWidget (Qt::RightDockWidgetArea, m_doc_browser_window); - tabifyDockWidget (m_command_window, m_doc_browser_window); - - addDockWidget (Qt::RightDockWidgetArea, m_variable_editor_window); - tabifyDockWidget (m_command_window, m_variable_editor_window); + if (! m_file_browser_window->adopted () || force_all) + addDockWidget (Qt::LeftDockWidgetArea, m_file_browser_window); + + if (! m_workspace_window->adopted () || force_all) + addDockWidget (Qt::LeftDockWidgetArea, m_workspace_window); + + if (! m_history_window->adopted () || force_all) + addDockWidget (Qt::LeftDockWidgetArea, m_history_window); + + if (! m_command_window->adopted () || force_all) + addDockWidget (Qt::RightDockWidgetArea, m_command_window); + + if (! m_doc_browser_window->adopted () || force_all) + { + addDockWidget (Qt::RightDockWidgetArea, m_doc_browser_window); + tabifyDockWidget (m_command_window, m_doc_browser_window); + } + + if (! m_variable_editor_window->adopted () || force_all) + { + addDockWidget (Qt::RightDockWidgetArea, m_variable_editor_window); + tabifyDockWidget (m_command_window, m_variable_editor_window); + } #if defined (HAVE_QSCINTILLA) addDockWidget (Qt::RightDockWidgetArea, m_editor_window); diff --git a/libgui/src/main-window.h b/libgui/src/main-window.h --- a/libgui/src/main-window.h +++ b/libgui/src/main-window.h @@ -165,7 +165,8 @@ namespace octave void prepare_to_exit (void); void go_to_previous_widget (void); void reset_windows (void); - void do_reset_windows (bool show = true, bool save = true); + void do_reset_windows (bool show = true, bool save = true, + bool force_all = false); void update_octave_directory (const QString& dir); void browse_for_directory (void); diff --git a/libgui/src/octave-dock-widget.cc b/libgui/src/octave-dock-widget.cc --- a/libgui/src/octave-dock-widget.cc +++ b/libgui/src/octave-dock-widget.cc @@ -184,7 +184,8 @@ namespace octave octave_dock_widget::octave_dock_widget (const QString& obj_name, QWidget *p, base_qobject& oct_qobj) - : label_dock_widget (p, oct_qobj), m_focus_follows_mouse (false), + : label_dock_widget (p, oct_qobj), m_adopted (false), + m_custom_style (false), m_focus_follows_mouse (false), m_recent_float_geom (), m_recent_dock_geom (), m_waiting_for_mouse_button_release (false) { @@ -345,6 +346,7 @@ namespace octave if (m_main_window) { settings->setValue (mw_state.key, m_main_window->saveState ()); + // Stay window, otherwise will bounce back to window by default // because there is no layout information for this widget in the // saved settings. @@ -360,6 +362,7 @@ namespace octave } // adjust the (un)dock icon + disconnect (m_dock_action, 0, this, 0); connect (m_dock_action, &QAction::triggered, this, &octave_dock_widget::make_window); if (titleBarWidget ()) diff --git a/libgui/src/octave-dock-widget.h b/libgui/src/octave-dock-widget.h --- a/libgui/src/octave-dock-widget.h +++ b/libgui/src/octave-dock-widget.h @@ -98,6 +98,9 @@ namespace octave void set_main_window (main_window *mw); + void set_adopted (bool adopted = true) { m_adopted = adopted; } + bool adopted (void) const { return m_adopted; } + signals: //! Custom signal that tells whether a user has clicked away that dock @@ -168,6 +171,7 @@ namespace octave main_window *m_main_window; + bool m_adopted; bool m_custom_style; bool m_focus_follows_mouse; int m_title_3d; diff --git a/libgui/src/octave-qobject.cc b/libgui/src/octave-qobject.cc --- a/libgui/src/octave-qobject.cc +++ b/libgui/src/octave-qobject.cc @@ -261,8 +261,17 @@ namespace octave connect (qt_link (), &qt_interpreter_events::show_workspace_signal, this, &base_qobject::show_workspace_window); + // Initially, before the variable editor window has been created, + // connect the qt_link edit variable signal to the octave_qobject + // slot that will: + // + // * create the window + // * replace this connection with one directly from qt_link to the + // variable editor + // * re-emit the original signal. + connect (qt_link (), &qt_interpreter_events::edit_variable_signal, - this, &base_qobject::edit_variable); + this, &base_qobject::show_variable_editor_window); if (m_app_context.experimental_terminal_widget ()) { @@ -386,8 +395,11 @@ namespace octave QPointer base_qobject::documentation_widget (main_window *mw) { - if (m_documentation_widget) - m_documentation_widget->set_main_window (mw); + if (m_documentation_widget && mw) + { + m_documentation_widget->set_main_window (mw); + m_documentation_widget->set_adopted (true); + } else { m_documentation_widget @@ -410,9 +422,7 @@ namespace octave QPointer base_qobject::file_browser_widget (main_window *mw) { - if (m_file_browser_widget) - m_file_browser_widget->set_main_window (mw); - else + if (! m_file_browser_widget) m_file_browser_widget = QPointer (new files_dock_widget (mw, *this)); @@ -423,7 +433,10 @@ namespace octave base_qobject::history_widget (main_window *mw) { if (m_history_widget) - m_history_widget->set_main_window (mw); + { + m_history_widget->set_main_window (mw); + m_history_widget->set_adopted (true); + } else { m_history_widget @@ -448,7 +461,10 @@ namespace octave base_qobject::workspace_widget (main_window *mw) { if (m_workspace_widget) - m_workspace_widget->set_main_window (mw); + { + m_workspace_widget->set_main_window (mw); + m_workspace_widget->set_adopted (true); + } else { m_workspace_widget @@ -473,9 +489,7 @@ namespace octave base_qobject::editor_widget (main_window */*mw*/) { #if 0 - if (m_editor_widget) - m_editor_widget->set_main_window (mw); - else + if (! m_editor_widget) m_editor_widget = new file_editor (mw, *this); #endif @@ -485,11 +499,22 @@ namespace octave QPointer base_qobject::variable_editor_widget (main_window *mw) { - if (m_variable_editor_widget) - m_variable_editor_widget->set_main_window (mw); + if (m_variable_editor_widget && mw) + { + m_variable_editor_widget->set_main_window (mw); + m_variable_editor_widget->set_adopted (true); + } else - m_variable_editor_widget - = QPointer (new variable_editor (mw, *this)); + { + m_variable_editor_widget + = QPointer (new variable_editor (mw, *this)); + + disconnect (qt_link (), &qt_interpreter_events::edit_variable_signal, + this, &base_qobject::show_variable_editor_window); + + connect (qt_link (), &qt_interpreter_events::edit_variable_signal, + m_variable_editor_widget, &variable_editor::edit_variable); + } return m_variable_editor_widget; } @@ -587,28 +612,18 @@ namespace octave } } - void base_qobject::edit_variable (const QString& expr, - const octave_value& val) + void base_qobject::show_variable_editor_window (const QString& name, + const octave_value& value) { variable_editor *widget = variable_editor_widget (); -#if 0 - // FIXME: This connection needs to be made whether running with the - // GUI main window or not, but only needs to be made once. - // Currently we have handle_variable_editor_update methods here and - // in the main_window object. - - connect (widget, &variable_editor::updated, - this, &base_qobject::handle_variable_editor_update); -#endif - - widget->edit_variable (expr, val); - if (! widget->isVisible ()) { widget->show (); widget->raise (); } + + emit qt_link()->edit_variable_signal (name, value); } void base_qobject::handle_variable_editor_update (void) diff --git a/libgui/src/octave-qobject.h b/libgui/src/octave-qobject.h --- a/libgui/src/octave-qobject.h +++ b/libgui/src/octave-qobject.h @@ -168,6 +168,8 @@ namespace octave // FIXME: The file_editor_interface needs to be a proper generic // interface for all editors (internal and external) for this to // work properly. + QPointer editor_widget (void); + QPointer editor_widget (main_window *mw = nullptr); @@ -196,7 +198,8 @@ namespace octave void show_workspace_window (void); - void edit_variable (const QString& expr, const octave_value& val); + void show_variable_editor_window (const QString& name, + const octave_value& value); void handle_variable_editor_update (void); diff --git a/libgui/src/variable-editor.cc b/libgui/src/variable-editor.cc --- a/libgui/src/variable-editor.cc +++ b/libgui/src/variable-editor.cc @@ -1147,6 +1147,9 @@ namespace octave m_main->setCentralWidget (central_mdiarea); setWidget (m_main); + + if (! p) + make_window (); } void variable_editor::focusInEvent (QFocusEvent *ev) @@ -1366,8 +1369,6 @@ namespace octave m_tool_bar->setEnabled (true); } - make_window (); - show (); page->show (); page->raise ();