Mercurial > octave
changeset 23910:445d0ab68193
maint: Merge away accidental head.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 14 Aug 2017 09:37:15 -0400 |
parents | b080ee04f6bf (current diff) 1e54d9aba433 (diff) |
children | 21c2fabd6ed2 |
files | |
diffstat | 5 files changed, 112 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- a/libgui/src/files-dock-widget.cc Mon Aug 14 08:39:17 2017 -0400 +++ b/libgui/src/files-dock-widget.cc Mon Aug 14 09:37:15 2017 -0400 @@ -665,7 +665,9 @@ { new_name = path.absolutePath () + '/' + new_name; old_name = path.absolutePath () + '/' + old_name; + emit file_remove_signal (old_name, new_name); // editor: close old path.rename (old_name, new_name); + emit file_renamed_signal (); // editor: load new file _file_system_model->revert (); } }
--- a/libgui/src/files-dock-widget.h Mon Aug 14 08:39:17 2017 -0400 +++ b/libgui/src/files-dock-widget.h Mon Aug 14 09:37:15 2017 -0400 @@ -135,6 +135,9 @@ /** Emitted, whenever the user removes or renames a file. */ void file_remove_signal (const QString& old_name, const QString& new_name); + /** Emitted, when a file or directory is renamed. */ + void file_renamed_signal (void); + private: void process_new_file (const QString& parent_name); void process_new_dir (const QString& parent_name);
--- a/libgui/src/m-editor/file-editor.cc Mon Aug 14 08:39:17 2017 -0400 +++ b/libgui/src/m-editor/file-editor.cc Mon Aug 14 09:37:15 2017 -0400 @@ -62,7 +62,7 @@ _paste_action = nullptr; _selectall_action = nullptr; _closed = false; - _external_close_request = false; + _no_focus = false; construct (); @@ -154,7 +154,7 @@ void file_editor::focus (void) { - if (_external_close_request) + if (_no_focus) return; // No focus for the editor if external open/close request octave_dock_widget::focus (); @@ -582,32 +582,112 @@ request_open_file (file); } + +// Slot used for signals indicating that a file was changed/rename or +// is going to be deleted/renamed void file_editor::handle_file_remove (const QString& old_name, const QString& new_name) { - - if (! old_name.isEmpty () && new_name.isEmpty ()) + // Check if old name is a file or directory + QFileInfo old (old_name); + if (old.isDir ()) + { + // Call the function which handles directories and return + handle_dir_remove (old_name, new_name); + return; + } + + // Is old file open? + file_editor_tab *editor_tab + = static_cast<file_editor_tab *> (find_tab_widget (old_name)); + + if (editor_tab) { - // Only old name is set, no new name -> close old name - - // Have all file editor tabs signal what their filenames are. - editor_tab_map.clear (); - emit fetab_file_name_query (nullptr); - - // Is old file open? - file_editor_tab *editor_tab - = static_cast<file_editor_tab *> (find_tab_widget (old_name)); - - if (editor_tab) + // Yes, close it silently + _no_focus = true; // Remember for not focussing editor + editor_tab->file_has_changed (QString (), true); // Close the tab + _no_focus = false; // Back to normal + + if (! new_name.isEmpty ()) { - _external_close_request = true; // Remember for not focussing editor - editor_tab->file_has_changed (QString (), true); // Close the tab - _external_close_request = false; // Back to normal + // New name is set, store new name and its encoding + // loading this file after the renaming is complete. + // The new name is not signaled after the renaming for being able + // to use this construct for renaming a whole directory, too. + + _tmp_closed_files = QStringList (); + _tmp_closed_files << new_name; + + // Get and store the related encoding + for (editor_tab_map_const_iterator p = editor_tab_map.begin (); + p != editor_tab_map.end (); p++) + { + if (editor_tab == p->second.fet_ID) + { + _tmp_closed_files << p->second.encoding; + break; + } + } } } } + +// Function for closing the files in a removed directory +void +file_editor::handle_dir_remove (const QString& old_name, + const QString& new_name) +{ + QDir old_dir (old_name); + + // Have all file editor tabs signal what their filenames are. + editor_tab_map.clear (); + emit fetab_file_name_query (nullptr); + + // Loop over all open files and pick those within old_dir + _tmp_closed_files = QStringList (); + + for (editor_tab_map_const_iterator p = editor_tab_map.begin (); + p != editor_tab_map.end (); p++) + { + QString rel_path_to_file = old_dir.relativeFilePath (p->first); + if (rel_path_to_file.left (3) != QString ("../")) + { + // We directly go down from old_dir to reach our file: Our + // file is included in the removed/renamed diectory. + // Thus delete it. + _no_focus = true; // Remember for not focussing editor + file_editor_tab *editor_tab + = static_cast<file_editor_tab *> (p->second.fet_ID); + editor_tab->file_has_changed (QString (), true); // Close + _no_focus = false; // Back to normal + + + // Add the new file path and the encoding for later reloading + // if new_name is given + if (! new_name.isEmpty ()) + { + QDir new_dir (new_name); + _tmp_closed_files << new_dir.absoluteFilePath (rel_path_to_file); + _tmp_closed_files << p->second.encoding; + } + } + } +} + +// Slot for signal indicating that a file was renamed +void +file_editor::handle_file_renamed () +{ + _no_focus = true; // Remember for not focussing editor + for (int i = 0; i < _tmp_closed_files.count (); i = i + 2) + request_open_file (_tmp_closed_files.at (i), + _tmp_closed_files.at (i+1)); + _no_focus = false; // Back to normal focus +} + + void file_editor::do_undo () {
--- a/libgui/src/m-editor/file-editor.h Mon Aug 14 08:39:17 2017 -0400 +++ b/libgui/src/m-editor/file-editor.h Mon Aug 14 09:37:15 2017 -0400 @@ -282,6 +282,7 @@ void handle_edit_file_request (const QString& file); void handle_file_remove (const QString&, const QString&); + void handle_file_renamed (void); // Tells the editor to react on changed settings. void notice_settings (const QSettings *settings); @@ -348,6 +349,8 @@ void switch_tab (int direction, bool movetab = false); + void handle_dir_remove (const QString& old_name, const QString& new_name); + bool editor_tab_has_focus (); QWidget * find_tab_widget (const QString& openFileName); @@ -464,13 +467,16 @@ int _marker_breakpoint; bool _closed; - bool _external_close_request; + bool _no_focus; enum { MaxMRUFiles = 10 }; QMenu *_mru_file_menu; QAction *_mru_file_actions[MaxMRUFiles]; QStringList _mru_files; QStringList _mru_files_encodings; + + // List of temporarily closed files while they are renamed + QStringList _tmp_closed_files; }; #endif
--- a/libgui/src/main-window.cc Mon Aug 14 08:39:17 2017 -0400 +++ b/libgui/src/main-window.cc Mon Aug 14 09:37:15 2017 -0400 @@ -1819,6 +1819,8 @@ SIGNAL (file_remove_signal (const QString&, const QString&)), editor_window, SLOT (handle_file_remove (const QString&, const QString&))); + connect (file_browser_window, SIGNAL (file_renamed_signal (void)), + editor_window, SLOT (handle_file_renamed (void))); #endif octave_link::post_event (this,