# HG changeset patch # User Torsten # Date 1452631558 -3600 # Node ID 221847e5f4880a72117fe9d11f29508ebd3e6b4a # Parent 12e98e5ebd138eeff5cf16f3107f3f042e651d42 fix issues when restoring breakpoints and closing tabs or whole application * file-editor-tab.cc (file_editor_tab): clear list of breakpoints; (handle_file_modified_answer): when saving, do not restore breakpoint; (recover_from_exit): new slot for resetting read only state nad restoring breakpoints when this tab was already saved during closing the application and closing was canceled later by the user; (check_restore_breakpoints): new internal function to restore the breakpoints when the breakpoint list is not empty; (save_file): new flag as argument indicating whether breakpoints should be restored (the default) or not (while exiting the application), store list of breakpoint in the new class variable _bp_list, call function for restoring breakpoints only if it is indicated by the new flag * file-editor-tab.h: new slot recover_from_exit, new function check_restore_breakpoints, function save_file with new argument, new class variable storing the list og breakpoints for restoring * file-editor.cc (check_closing): reorganized checking tabs for closing, when closing was canceled by the user, emit new signal for the tabs to recover from exit, save session afterwards (when app really is closing); (add_file_editor_tab): connect new signal for recovering from exit to the related new slots of the tabs * file-editor.h: new signal for recovering from exit diff -r 12e98e5ebd13 -r 221847e5f488 libgui/src/m-editor/file-editor-tab.cc --- a/libgui/src/m-editor/file-editor-tab.cc Tue Jan 12 10:28:48 2016 -0800 +++ b/libgui/src/m-editor/file-editor-tab.cc Tue Jan 12 21:45:58 2016 +0100 @@ -90,6 +90,8 @@ _line = 0; _col = 0; + _bp_list.clear (); // start with an empty list of breakpoints + connect (_edit_area, SIGNAL (cursorPositionChanged (int, int)), this, SLOT (handle_cursor_moved (int,int))); @@ -1343,7 +1345,7 @@ if (decision == QMessageBox::Save) { // Save file, but do not remove from editor. - save_file (_file_name, false); + save_file (_file_name, false, false); } else if (decision == QMessageBox::Discard) { @@ -1363,6 +1365,37 @@ _edit_area->setModified (modified); } +void +file_editor_tab::recover_from_exit () +{ + // reset the possibly still existing read only state + _edit_area->setReadOnly (false); + + // if we are in this slot and the list of breakpoint is not empty, + // then this tab was saved during an exit of the applications (not + // restoring the breakpoints and not emptying the list) and the user + // canceled this closing late on. + check_restore_breakpoints (); +} + +void +file_editor_tab::check_restore_breakpoints () +{ + if (! _bp_list.isEmpty ()) + { + // At least one breakpoint is present. + // Get rid of breakpoints at old (now possibly invalid) linenumbers + remove_all_breakpoints (this); + + // and set breakpoints at the new linenumbers + for (int i = 0; i < _bp_list.length (); i++) + handle_request_add_breakpoint (_bp_list.value (i) + 1); + + // reset the list of breakpoints + _bp_list.clear (); + } +} + QString file_editor_tab::load_file (const QString& fileName) { @@ -1536,7 +1569,8 @@ } void -file_editor_tab::save_file (const QString& saveFileName, bool remove_on_success) +file_editor_tab::save_file (const QString& saveFileName, + bool remove_on_success, bool restore_breakpoints) { // If it is a new file with no name, signal that saveFileAs // should be performed. @@ -1555,13 +1589,7 @@ QFile file (file_to_save); // Get a list of all the breakpoint line numbers. - QIntList list; - emit report_editor_linenr (list); - if (! list.isEmpty ()) - { - // At least one breakpoint is present. Get rid of breakpoints. - remove_all_breakpoints (this); - } + emit report_editor_linenr (_bp_list); // stop watching file QStringList trackedFiles = _file_system_watcher.files (); @@ -1633,8 +1661,10 @@ } // Attempt to restore the breakpoints if that is desired. - for (int i = 0; i < list.length (); i++) - handle_request_add_breakpoint (list.value (i) + 1); + // This is only allowed if the tab is not closing since changing + // breakpoints would reopen the tab in this case. + if (restore_breakpoints) + check_restore_breakpoints (); } void diff -r 12e98e5ebd13 -r 221847e5f488 libgui/src/m-editor/file-editor-tab.h --- a/libgui/src/m-editor/file-editor-tab.h Tue Jan 12 10:28:48 2016 -0800 +++ b/libgui/src/m-editor/file-editor-tab.h Tue Jan 12 21:45:58 2016 +0100 @@ -129,6 +129,7 @@ void do_breakpoint_marker (bool insert, const QWidget *ID, int line = -1); + void recover_from_exit (void); void set_modified (bool modified = true); void set_encoding (const QString& new_encoding); @@ -222,7 +223,8 @@ }; bool valid_file_name (const QString& file=QString ()); - void save_file (const QString& saveFileName, bool remove_on_success = false); + void save_file (const QString& saveFileName, bool remove_on_success = false, + bool restore_breakpoints = true); void save_file_as (bool remove_on_success = false); bool check_valid_identifier (QString file_name); bool check_valid_codec (QTextCodec *codec); @@ -240,6 +242,7 @@ void add_breakpoint_callback (const bp_info& info); void remove_breakpoint_callback (const bp_info& info); void remove_all_breakpoints_callback (const bp_info& info); + void check_restore_breakpoints (void); void center_current_line (bool always=true); void add_octave_apis (octave_value_list key_ovl); @@ -274,6 +277,8 @@ QFileSystemWatcher _file_system_watcher; + QIntList _bp_list; + find_dialog *_find_dialog; bool _find_dialog_is_visible; QRect _find_dialog_geometry; diff -r 12e98e5ebd13 -r 221847e5f488 libgui/src/m-editor/file-editor.cc --- a/libgui/src/m-editor/file-editor.cc Tue Jan 12 10:28:48 2016 -0800 +++ b/libgui/src/m-editor/file-editor.cc Tue Jan 12 21:45:58 2016 +0100 @@ -79,20 +79,42 @@ bool file_editor::check_closing (void) { - // Save open files for restoring in next session; this only is possible - QSettings *settings = resource_manager::get_settings (); + // When the applications is closing all editor tabs are checked whether + // they need to be saved. During these ckecked the tabs are not closed + // since the user might cancel closing octave during one of these saving + // dialogs. Therefore, saving the session for restoring at next start + // is not done before the application is definitely closing // Have all file editor tabs signal what their filenames are. editor_tab_map.clear (); emit fetab_file_name_query (0); + // Save all tabs with confirmation. + file_editor_tab::reset_cancel (); + emit fetab_check_modified_file (); + + // If there was a cancellation, make the already saved/discarded tabs + // recovering from the exit by removing the read-only state and by + // recovering the debugger breakpoints. Finally return false in order to + // cancel closing the application + if (file_editor_tab::was_cancelled ()) + { + emit fetab_recover_from_exit (); + return false; + } + + // Here, the application will be closed -> store the session + + // Save open files for restoring in next session; this only is possible + QSettings *settings = resource_manager::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; - // over all open tabs + // save all open tabs before they are definitely closed for (editor_tab_map_const_iterator p = editor_tab_map.begin (); p != editor_tab_map.end (); p++) { @@ -112,14 +134,8 @@ settings->setValue ("editor/saved_session_tab_index", fet_index); settings->sync (); - // Save all tabs with confirmation. - file_editor_tab::reset_cancel (); - emit fetab_check_modified_file (); - - // Close all tabs if there was no cancellation. - if (file_editor_tab::was_cancelled ()) - return false; - + // Finally close all the tabs and return indication that we can exit + // the application for (int i = 0; i < _tab_widget->count (); i++) { delete _tab_widget->widget (i); @@ -1966,6 +1982,9 @@ f, SLOT (check_modified_file (void))); // Signals from the file_editor trivial operations + connect (this, SIGNAL (fetab_recover_from_exit (void)), + f, SLOT (recover_from_exit (void))); + connect (this, SIGNAL (fetab_set_directory (const QString&)), f, SLOT (set_current_directory (const QString&))); diff -r 12e98e5ebd13 -r 221847e5f488 libgui/src/m-editor/file-editor.h --- a/libgui/src/m-editor/file-editor.h Tue Jan 12 10:28:48 2016 -0800 +++ b/libgui/src/m-editor/file-editor.h Tue Jan 12 21:45:58 2016 +0100 @@ -152,6 +152,7 @@ void fetab_zoom_normal (const QWidget* ID); void fetab_set_directory (const QString& dir); + void fetab_recover_from_exit (void); void request_settings_dialog (const QString&); void execute_command_in_terminal_signal (const QString&);