Mercurial > octave
changeset 27089:9326c2258e60
fix visibility of find dialog when editor is docked/undocked (bug #5)
* file-editor-interface.h: implementation of virtual slot toplevel_change
* file-editor-tab.cc (handle_toplevel_changed): new slot for editor singal
when editor toplevel changed, destroying and re-creating find dialog where
the state of the dialog is saved in a new structure;
(handle_find_dialog_finished): store geometry and visibility in the new
data structure of the find dialog;
(find_create): new method with the main actions for creating the find dialog
moved from find (), this method is called for re-creating the dialog
(find): move most of this slot into new method find_create, only leave
actions for very first initialization of the dialog;
(change_editor_state): use new data struct instead of separate variables
for saving and restoring dialog data
* file-editor-tab.h: new slot handle_toplevel_changed, new method
find_create, new structure for saving dialog data
* file-editor.cc (toplevel_changed): implementation of new slot for signal
on toplevel changed;
(add_file_editor_tab): connect editor signal on toplevel changed to the
related slot in file_editor_tab
* file-editor.h: new signal fetab_toplevel_changed, new slot toplevel_change
* find-dialog.cc (save_data): new method for saving the current state of
the find dialog in a structure passed by the caller;
(restore_data): new method for restoring the current state from a given
data structure;
* find-dialog.h: typedef of data structure with enum for the binary options,
new methods for saving and restoring data in/from the structure
* octave-dock-widget.cc (make_window): manually emit toplevelChanged signal
in case we undock a widget since our methid seems to prevent qt from
doing so
* octave-dock-widget.h: make slot toplevel_changed protected and virtual
allowing a re-implementation in specific widgets
author | Torsten Lilge <ttl-octave@mailbox.org> |
---|---|
date | Tue, 14 May 2019 22:41:32 +0200 |
parents | 4092ffc1e43c |
children | e83d3161b256 |
files | libgui/src/m-editor/file-editor-interface.h libgui/src/m-editor/file-editor-tab.cc libgui/src/m-editor/file-editor-tab.h libgui/src/m-editor/file-editor.cc libgui/src/m-editor/file-editor.h libgui/src/m-editor/find-dialog.cc libgui/src/m-editor/find-dialog.h libgui/src/octave-dock-widget.cc libgui/src/octave-dock-widget.h |
diffstat | 9 files changed, 139 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- a/libgui/src/m-editor/file-editor-interface.h Fri May 10 22:15:37 2019 +0200 +++ b/libgui/src/m-editor/file-editor-interface.h Tue May 14 22:41:32 2019 +0200 @@ -73,6 +73,8 @@ public slots: + virtual void toplevel_change (bool) = 0; + virtual void handle_file_remove (const QString& o, const QString& n) = 0; virtual void request_new_file (const QString& command = QString ()) = 0;
--- a/libgui/src/m-editor/file-editor-tab.cc Fri May 10 22:15:37 2019 +0200 +++ b/libgui/src/m-editor/file-editor-tab.cc Tue May 14 22:41:32 2019 +0200 @@ -166,7 +166,6 @@ // Leave the find dialog box out of memory until requested. _find_dialog = nullptr; - _find_dialog_is_visible = false; // symbols _edit_area->setMarginType (1, QsciScintilla::SymbolMargin); @@ -855,6 +854,31 @@ _lexer_apis->savePrepared (_prep_apis_file); } + // Slot for editors signal is its toplevel state has changed + void file_editor_tab::handle_toplevel_changed (bool) + { + // The find dialog has to be re-created since making the editor + // floating or docked obviously changes the parent/child relation + // of the find dialog + if (_find_dialog == nullptr) + return; + else + { + if (_find_dialog->isVisible ()) + { + _find_dialog->save_data (&m_find_dlg_data); // Save current data + delete _find_dialog; + _find_dialog = nullptr; + + find_create (); // Create new dialog + + _find_dialog->restore_data (&m_find_dlg_data); // Restore data + + _edit_area->setFocus (); + } + } + } + // slot for fetab_set_focus: sets the focus to the current edit area void file_editor_tab::set_focus (const QWidget *ID) { @@ -1288,15 +1312,36 @@ { // Find dialog is going to hide. Save location of window for // when it is reshown. - _find_dialog_geometry = _find_dialog->geometry (); - _find_dialog_is_visible = false; + m_find_dlg_data.geometry = _find_dialog->geometry (); + m_find_dlg_data.is_visible = false; } + // Slot for initially creating and showing the find dialog void file_editor_tab::find (const QWidget *ID, QList<QAction *> fetab_actions) { if (ID != this) return; + m_find_dlg_data.actions = fetab_actions.mid (0,2); + + // Create the dialog + find_create (); + + // Since find_create shows the dialog without activating the widget + // (which is reuqired in other cases) do this manually here + _find_dialog->activateWindow (); + + // Initiate search text from possible selection and save the initial + // data from the dialog on the defined structure + _find_dialog->init_search_text (); + _find_dialog->save_data (&m_find_dlg_data); + } + + // This methos creates the find dialog in way that is at first suitable + // for re-creating it after the toplevel of the editor has changed. + // The find dialog is initially creatied, activated and shown with find () + void file_editor_tab::find_create () + { // The find_dialog feature doesn't need a slot for return info. // Rather than Qt::DeleteOnClose, let the find feature hang about // in case it contains useful information like previous searches @@ -1307,8 +1352,8 @@ if (! _find_dialog) { _find_dialog = new find_dialog (_edit_area, - fetab_actions.mid (0,2), - qobject_cast<QWidget *> (sender ())); + m_find_dlg_data.actions, + this); connect (_find_dialog, SIGNAL (finished (int)), this, SLOT (handle_find_dialog_finished (int))); @@ -1319,20 +1364,16 @@ _find_dialog, SLOT (find_prev ())); _find_dialog->setWindowModality (Qt::NonModal); - _find_dialog_geometry = _find_dialog->geometry (); } else if (! _find_dialog->isVisible ()) { - _find_dialog->setGeometry (_find_dialog_geometry); + _find_dialog->setGeometry (m_find_dlg_data.geometry); QPoint p = _find_dialog->pos (); _find_dialog->move (p.x ()+10, p.y ()+10); } + _find_dialog->setAttribute(Qt::WA_ShowWithoutActivating); _find_dialog->show (); - _find_dialog_is_visible = true; - _find_dialog->activateWindow (); - _find_dialog->init_search_text (); - } void file_editor_tab::find_next (const QWidget *ID) @@ -2738,16 +2779,16 @@ { if (_find_dialog->isVisible ()) { - _find_dialog_geometry = _find_dialog->geometry (); + m_find_dlg_data.geometry = _find_dialog->geometry (); _find_dialog->hide (); } } return; } - if (_find_dialog && _find_dialog_is_visible) + if (_find_dialog && m_find_dlg_data.is_visible) { - _find_dialog->setGeometry (_find_dialog_geometry); + _find_dialog->setGeometry (m_find_dlg_data.geometry); QPoint p = _find_dialog->pos (); _find_dialog->move (p.x ()+10, p.y ()+10); _find_dialog->show ();
--- a/libgui/src/m-editor/file-editor-tab.h Fri May 10 22:15:37 2019 +0200 +++ b/libgui/src/m-editor/file-editor-tab.h Tue May 14 22:41:32 2019 +0200 @@ -84,6 +84,7 @@ // Simply transmit filename. void file_name_query (const QWidget *ID); + void handle_toplevel_changed (bool); void set_focus (const QWidget *ID); void set_current_directory (const QString& dir); void context_help (const QWidget *ID, bool); @@ -246,6 +247,8 @@ std::string condition; }; + void find_create (void); + bool valid_file_name (const QString& file = QString ()); bool exit_debug_and_clear (const QString& full_name, const QString& base_name); @@ -307,10 +310,6 @@ QIntList _bp_lines; QStringList _bp_conditions; - find_dialog *_find_dialog; - bool _find_dialog_is_visible; - QRect _find_dialog_geometry; - QsciAPIs *_lexer_apis; QString _prep_apis_file; @@ -330,6 +329,10 @@ int remove_line; int do_not_remove_line; } m_breakpoint_info; + + find_dialog *_find_dialog; + find_dialog::find_dialog_data m_find_dlg_data; + }; }
--- a/libgui/src/m-editor/file-editor.cc Fri May 10 22:15:37 2019 +0200 +++ b/libgui/src/m-editor/file-editor.cc Tue May 14 22:41:32 2019 +0200 @@ -1255,6 +1255,12 @@ } + void file_editor::toplevel_change (bool toplevel) + { + emit fetab_toplevel_changed (toplevel); + octave_dock_widget::toplevel_change (toplevel); + } + void file_editor::update_octave_directory (const QString& dir) { m_ced = dir; @@ -2357,6 +2363,9 @@ connect (this, SIGNAL (fetab_set_focus (const QWidget*)), f, SLOT (set_focus (const QWidget*))); + connect (this, SIGNAL (fetab_toplevel_changed (bool)), + f, SLOT (handle_toplevel_changed (bool))); + connect (this, SIGNAL (fetab_insert_debugger_pointer (const QWidget*, int)), f, SLOT (insert_debugger_pointer (const QWidget*, int)));
--- a/libgui/src/m-editor/file-editor.h Fri May 10 22:15:37 2019 +0200 +++ b/libgui/src/m-editor/file-editor.h Tue May 14 22:41:32 2019 +0200 @@ -122,6 +122,7 @@ signals: + void fetab_toplevel_changed (bool); void fetab_settings_changed (const QSettings *settings); void fetab_change_request (const QWidget *ID); void fetab_file_name_query (const QWidget *ID); @@ -181,6 +182,8 @@ public slots: + void toplevel_change (bool); + void focus (void); void set_focus (QWidget *fet); void enable_menu_shortcuts (bool);
--- a/libgui/src/m-editor/find-dialog.cc Fri May 10 22:15:37 2019 +0200 +++ b/libgui/src/m-editor/find-dialog.cc Tue May 14 22:41:32 2019 +0200 @@ -202,6 +202,39 @@ } + void find_dialog::save_data (find_dialog_data *fdlg_data) + { + fdlg_data->text = _search_line_edit->text (); + fdlg_data->replace_text = _replace_line_edit->text (); + fdlg_data->geometry = geometry (); + fdlg_data->is_visible = isVisible (); + fdlg_data->options = 0 + + _extension->isVisible () * FIND_DLG_MORE + + _case_check_box->isChecked () * FIND_DLG_CASE + + _from_start_check_box->isChecked () * FIND_DLG_START + + _wrap_check_box->isChecked () * FIND_DLG_WRAP + + _regex_check_box->isChecked () * FIND_DLG_REGX + + _whole_words_check_box->isChecked () * FIND_DLG_WORDS + + _backward_check_box->isChecked () * FIND_DLG_BACK + + _search_selection_check_box->isChecked () * FIND_DLG_SEL; + } + + void find_dialog::restore_data (const find_dialog_data* fdlg_data) + { + setGeometry (fdlg_data->geometry); + setVisible (fdlg_data->is_visible); + _search_line_edit->setText (fdlg_data->text); + _replace_line_edit->setText (fdlg_data->replace_text); + _extension->setVisible (FIND_DLG_MORE & fdlg_data->options); + _case_check_box->setChecked (FIND_DLG_CASE & fdlg_data->options); + _from_start_check_box->setChecked (FIND_DLG_START & fdlg_data->options); + _wrap_check_box->setChecked (FIND_DLG_WRAP & fdlg_data->options); + _regex_check_box->setChecked (FIND_DLG_REGX & fdlg_data->options); + _whole_words_check_box->setChecked (FIND_DLG_WORDS & fdlg_data->options); + _backward_check_box->setChecked (FIND_DLG_BACK & fdlg_data->options); + _search_selection_check_box->setChecked (FIND_DLG_SEL & fdlg_data->options); + } + // set text of "search from start" depending on backward search void find_dialog::handle_backward_search_changed (int backward) {
--- a/libgui/src/m-editor/find-dialog.h Fri May 10 22:15:37 2019 +0200 +++ b/libgui/src/m-editor/find-dialog.h Tue May 14 22:41:32 2019 +0200 @@ -77,10 +77,36 @@ class find_dialog : public QDialog { Q_OBJECT + public: + + typedef struct + { + QList<QAction *> actions; + QString text; + QString replace_text; + QRect geometry; + bool is_visible; + int options; + } find_dialog_data; + + enum find_dialog_options + { + FIND_DLG_MORE = 1, + FIND_DLG_CASE = 2, + FIND_DLG_START = 4, + FIND_DLG_WRAP = 8, + FIND_DLG_REGX = 16, + FIND_DLG_WORDS = 32, + FIND_DLG_BACK = 64, + FIND_DLG_SEL = 128 + }; + find_dialog (QsciScintilla *edit_area, QList<QAction *> find_actions, QWidget *parent = nullptr); void init_search_text (void); + void save_data (find_dialog_data *fdlg_data); + void restore_data (const find_dialog_data *fdlg_data); private slots: void handle_sel_search_changed (int);
--- a/libgui/src/octave-dock-widget.cc Fri May 10 22:15:37 2019 +0200 +++ b/libgui/src/octave-dock-widget.cc Tue May 14 22:41:32 2019 +0200 @@ -305,6 +305,8 @@ focus (); set_style (true); } + + emit topLevelChanged (true); // Be sure signal is emitted } // dock the widget
--- a/libgui/src/octave-dock-widget.h Fri May 10 22:15:37 2019 +0200 +++ b/libgui/src/octave-dock-widget.h Tue May 14 22:41:32 2019 +0200 @@ -150,6 +150,8 @@ protected slots: + virtual void toplevel_change (bool); + //! Slot to steer changing visibility from outside. virtual void handle_visibility_changed (bool visible) @@ -165,7 +167,6 @@ private slots: void change_visibility (bool); - void toplevel_change (bool); private: