Mercurial > octave
changeset 29372:fd1c45b62ba9 stable
fix restoring editor session after having closed all tabs (bug #60051)
* file-editor.cc (save_session): moved saving the current session into
this new separate function;
(check_closing): save the session if here, regardless number of tabs;
(handle_tab_ready_to_close): and not here, which would never happen
when no tab has to be closed on exit
* file-editor.h: new function save_session
author | Torsten Lilge <ttl-octave@mailbox.org> |
---|---|
date | Sun, 14 Feb 2021 22:48:19 +0100 |
parents | 8e549734531e |
children | 23a5daf1e809 |
files | libgui/src/m-editor/file-editor.cc libgui/src/m-editor/file-editor.h |
diffstat | 2 files changed, 48 insertions(+), 41 deletions(-) [+] |
line wrap: on
line diff
--- a/libgui/src/m-editor/file-editor.cc Sun Feb 14 10:27:41 2021 -0800 +++ b/libgui/src/m-editor/file-editor.cc Sun Feb 14 22:48:19 2021 +0100 @@ -406,6 +406,48 @@ } } + // Save open files for restoring in next session + // (even if last session will not be restored next time) + // together with encoding and the tab index + void file_editor::save_session (void) + { + resource_manager& rmgr = m_octave_qobj.get_resource_manager (); + gui_settings *settings = rmgr.get_settings (); + + QStringList fetFileNames; + QStringList fet_encodings; + QStringList fet_index; + QStringList fet_lines; + + std::list<file_editor_tab *> editor_tab_lst = m_tab_widget->tab_list (); + + for (auto editor_tab : editor_tab_lst) + { + QString file_name = editor_tab->file_name (); + + // Don't append unnamed files. + + if (! file_name.isEmpty ()) + { + fetFileNames.append (file_name); + fet_encodings.append (editor_tab->encoding ()); + + QString index; + fet_index.append (index.setNum (m_tab_widget->indexOf (editor_tab))); + + int l, c; + editor_tab->qsci_edit_area ()->getCursorPosition (&l, &c); + fet_lines.append (index.setNum (l + 1)); + } + } + + settings->setValue (ed_session_names.key, fetFileNames); + settings->setValue (ed_session_enc.key, fet_encodings); + settings->setValue (ed_session_ind.key, fet_index); + settings->setValue (ed_session_lines.key, fet_lines); + settings->sync (); + } + bool file_editor::check_closing (void) { // When the application or the editor is closing and the user wants to @@ -415,6 +457,10 @@ // Therefore, saving the session for restoring at next start is not done // before the application is definitely closing. + // Save the session. Even is closing is cancelled, this would be + // overwritten by the next attempt to close the editor + save_session (); + std::list<file_editor_tab *> fe_tab_lst = m_tab_widget->tab_list (); m_number_of_tabs = fe_tab_lst.size (); @@ -464,47 +510,6 @@ // Here, the application or the editor will be closed -> store the session - // Save open files for restoring in next session; this only is possible - resource_manager& rmgr = m_octave_qobj.get_resource_manager (); - gui_settings *settings = rmgr.get_settings (); - - // save filenames (even if last session will not be restored next time) - // together with encoding and the tab index - QStringList fetFileNames; - QStringList fet_encodings; - QStringList fet_index; - QStringList fet_lines; - - // save all open tabs before they are definitely closed - - std::list<file_editor_tab *> editor_tab_lst = m_tab_widget->tab_list (); - - for (auto editor_tab : editor_tab_lst) - { - QString file_name = editor_tab->file_name (); - - // Don't append unnamed files. - - if (! file_name.isEmpty ()) - { - fetFileNames.append (file_name); - fet_encodings.append (editor_tab->encoding ()); - - QString index; - fet_index.append (index.setNum (m_tab_widget->indexOf (editor_tab))); - - int l, c; - editor_tab->qsci_edit_area ()->getCursorPosition (&l, &c); - fet_lines.append (index.setNum (l + 1)); - } - } - - settings->setValue (ed_session_names.key, fetFileNames); - settings->setValue (ed_session_enc.key, fet_encodings); - settings->setValue (ed_session_ind.key, fet_index); - settings->setValue (ed_session_lines.key, fet_lines); - settings->sync (); - // Take care of the find dialog if (m_find_dialog) m_find_dialog->close (); @@ -515,6 +520,7 @@ // hidden before, this state has to be restored afterwards. bool vis = isVisible (); + std::list<file_editor_tab *> editor_tab_lst = m_tab_widget->tab_list (); for (auto editor_tab : editor_tab_lst) delete editor_tab;
--- a/libgui/src/m-editor/file-editor.h Sun Feb 14 10:27:41 2021 -0800 +++ b/libgui/src/m-editor/file-editor.h Sun Feb 14 22:48:19 2021 +0100 @@ -180,6 +180,7 @@ void activate (void); void set_focus (QWidget *fet); void enable_menu_shortcuts (bool); + void save_session (void); bool check_closing (void); void handle_tab_ready_to_close (void);