+void Buffer::Impl::refreshFileMonitor()
+{
+ if (file_monitor_ && file_monitor_->filename() == filename.absFileName()) {
+ file_monitor_->refresh();
+ return;
+ }
+
+ // The previous file monitor is invalid
+ // This also destroys the previous file monitor and all its connections
+ file_monitor_ = FileSystemWatcher::monitor(filename);
+ // file_monitor_ will be destroyed with *this, so it is not going to call a
+ // destroyed object method.
+ file_monitor_->connect([this](bool exists) {
+ fileExternallyModified(exists);
+ });
+}
+
+
+void Buffer::Impl::fileExternallyModified(bool const exists)
+{
+ // ignore notifications after our own saving operations
+ if (checksum_ == filename.checksum()) {
+ LYXERR(Debug::FILES, "External modification but "
+ "checksum unchanged: " << filename);
+ return;
+ }
+ lyx_clean = bak_clean = false;
+ // If the file has been deleted, only mark the file as dirty since it is
+ // pointless to prompt for reloading. If later a file is moved into this
+ // location, then the externally modified warning will appear then.
+ if (exists)
+ externally_modified_ = true;
+ // Update external modification notification.
+ // Dirty buffers must be visible at all times.
+ if (wa_ && wa_->unhide(owner_))
+ wa_->updateTitles();
+ else
+ // Unable to unhide the buffer (e.g. no GUI or not current View)
+ lyx_clean = true;
+}
+
+
+bool Buffer::notifiesExternalModification() const
+{
+ return d->externally_modified_;
+}
+
+
+void Buffer::clearExternalModification() const
+{
+ d->externally_modified_ = false;
+ if (d->wa_)
+ d->wa_->updateTitles();
+}
+