Let user "Save As..." when document has been externally modified

Currently Okular stops the user from saving their document if it has
unsaved changes and was modified externally. This makes some sense
because there are now two sources of truth, and Okular cannot reconcile
them itself. However as a consequence, it causes data loss since the
user's unsaved changes in Okular become un-save-able. This is quite
frustrating when it happens.

But this prohibiton on saving over an externally-modified document only
really makes sense for a "Save" operation that overwrites the original
document. If instead, the user does a "Save As...", then they can save
their local changes to another file and avoid losing unsaved changes.
Then if needed, they can manually compare the original
externally-modified document with their newly-saved document and
reconcile the changes by hand.

Accordingly, this commit avoids showing the error message box and
blocking saving if the user is doing a "Save As..." to a new location,
rather than overwriting the open file.

BUG: 402017
FIXED-IN: 23.04.1


(cherry picked from commit b5191a2c1f)
remotes/origin/release/23.04
Nate Graham 3 years ago
parent ba03a87b4a
commit b596df0c93
  1. 4
      part/part.cpp

@ -2645,7 +2645,9 @@ bool Part::saveAs(const QUrl &saveUrl, SaveAsFlags flags)
// TODO When we get different saving backends we need to query the backend
// as to if it can save changes even if the open file has been modified,
// since we only have poppler as saving backend for now we're skipping that check
if (m_fileLastModified != QFileInfo(localFilePath()).lastModified()) {
// Don't warn the user about external changes if they're doing a Save As with a different URL, since then there's nothing to warn about
// because the original changed document is safe.
if (m_fileLastModified != QFileInfo(localFilePath()).lastModified() && saveUrl == realUrl()) {
KMessageBox::error(widget(), i18n("The file '%1' has been modified by another program, which means it can no longer be saved.", url().fileName()), i18n("File Changed"));
return false;
}

Loading…
Cancel
Save