Mercurial > octave
changeset 25369:c89fa0989e7b
prevent notifications on externally changed editor files (bug 53539)
* file-editor-tab.h: new private class variable for storing the last
modification time of the current file
* file-editor-tab.cc (file_editor_tab): initialize new class variable;
(set_file_name): store last modification time of the current file;
(file_has_changed): do nothing if the last modification time of the
file has not changed;
author | Torsten <mttl@mailbox.org> |
---|---|
date | Sat, 12 May 2018 19:07:58 +0200 |
parents | 2dad85fe6b8b |
children | 9cc1ca6538e3 |
files | libgui/src/m-editor/file-editor-tab.cc libgui/src/m-editor/file-editor-tab.h |
diffstat | 2 files changed, 25 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/libgui/src/m-editor/file-editor-tab.cc Fri May 11 11:27:01 2018 -0400 +++ b/libgui/src/m-editor/file-editor-tab.cc Sat May 12 19:07:58 2018 +0200 @@ -112,6 +112,9 @@ _bp_conditions.clear (); m_bp_restore_count = 0; + // Initialize last modification date to now + m_last_modified = QDateTime::currentDateTimeUtc(); + // disable editor drag & drop so parent can handle _edit_area->setAcceptDrops (false); @@ -434,8 +437,11 @@ QStringList trackedFiles = _file_system_watcher.files (); if (! trackedFiles.isEmpty ()) _file_system_watcher.removePath (_file_name); - if (! fileName.isEmpty ()) + if (! fileName.isEmpty () && QFile::exists (fileName)) + { _file_system_watcher.addPath (fileName); + m_last_modified = QFileInfo (fileName).lastModified ().toUTC (); + } // update lexer and file name variable if file name changes if (_file_name != fileName) @@ -2309,6 +2315,20 @@ void file_editor_tab::file_has_changed (const QString&, bool do_close) { + bool file_exists = QFile::exists (_file_name); + + if (file_exists) + { + // Test if file is really modified or if just the timezone has + // changed. In the latter, just return without doing anything + QDateTime modified = QFileInfo (_file_name).lastModified ().toUTC (); + + if (modified <= m_last_modified) + return; + + m_last_modified = modified; + } + // Prevent popping up multiple message boxes when the file has // been changed multiple times by temporarily removing from the // file watcher. @@ -2316,11 +2336,11 @@ if (! trackedFiles.isEmpty ()) _file_system_watcher.removePath (_file_name); - if (QFile::exists (_file_name) && ! do_close) + if (file_exists && ! do_close) { + // The file is modified if (_always_reload_changed_files) - load_file (_file_name); else
--- a/libgui/src/m-editor/file-editor-tab.h Fri May 11 11:27:01 2018 -0400 +++ b/libgui/src/m-editor/file-editor-tab.h Sat May 12 19:07:58 2018 +0200 @@ -25,6 +25,7 @@ #include <QWidget> #include <QCloseEvent> +#include <QDateTime> #include <QFileSystemWatcher> #include <QSettings> #include <QFileInfo> @@ -284,6 +285,7 @@ QString _ced; QString _encoding; QString _new_encoding; + QDateTime m_last_modified; bool _long_title; bool _copy_available;