diff --git a/core/document.cpp b/core/document.cpp --- a/core/document.cpp +++ b/core/document.cpp @@ -4471,8 +4471,16 @@ { if ( clean ) d->m_undoStack->setClean(); + // Since we only use the resetClean + // in some cases and we're past the dependency freeze + // if you happen to compile with an old Qt you will miss + // some extra nicety when saving an okular file with annotations to png file + // it's quite corner case compared to how important the whole save feature + // is so you'll have to live without it +#if QT_VERSION > QT_VERSION_CHECK(5, 8, 0) else d->m_undoStack->resetClean(); +#endif } bool Document::canSaveChanges() const diff --git a/part.h b/part.h --- a/part.h +++ b/part.h @@ -293,6 +293,7 @@ // the document Okular::Document * m_document; + QDateTime m_fileLastModified; QString m_temporaryLocalFile; bool isDocumentArchive; bool m_documentOpenWithPassword; diff --git a/part.cpp b/part.cpp --- a/part.cpp +++ b/part.cpp @@ -1366,6 +1366,7 @@ return Document::OpenError; } + m_fileLastModified = QFileInfo( fileNameToOpen ).lastModified(); return Document::OpenSuccess; } @@ -1459,6 +1460,10 @@ } } + if ( openResult == Document::OpenSuccess ) + { + m_fileLastModified = QFileInfo( fileNameToOpen ).lastModified(); + } return openResult; } @@ -1703,6 +1708,31 @@ if ( !isReadWrite() || !isModified() ) return true; + // 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() ) + { + int res; + if ( m_isReloading ) + { + res = KMessageBox::warningYesNo( widget(), + i18n( "You have unsaved modifications and the file has been modified externally since it was opened.
Unfortunately that means that we can no longer save it and your changes will be lost.
Do you want to continue the reload?" ), + i18n( "File changed" ), + KGuiItem( i18n( "Continue reload" ) ), // <- KMessageBox::Yes + KGuiItem( i18n( "Abort reload" ) )); + } + else + { + res = KMessageBox::warningYesNo( widget(), + i18n( "You have unsaved modifications and the file has been modified externally since it was opened.
Unfortunately that means that we can no longer save it and your changes will be lost.
Do you want to continue closing the file?" ), + i18n( "File changed" ), + KGuiItem( i18n( "Continue closing" ) ), // <- KMessageBox::Yes + KGuiItem( i18n( "Abort closing" ) )); + } + return res == KMessageBox::Yes; + } + const int res = KMessageBox::warningYesNoCancel( widget(), i18n( "Do you want to save your changes to \"%1\" or discard them?", url().fileName() ), i18n( "Close Document" ), @@ -1783,6 +1813,7 @@ factory()->removeClient( m_generatorGuiClient ); m_generatorGuiClient = nullptr; m_document->closeDocument(); + m_fileLastModified = QDateTime(); updateViewActions(); delete m_tempfile; m_tempfile = nullptr; @@ -2448,6 +2479,17 @@ 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() ) + { + QMessageBox::warning( widget(), + i18n( "File changed" ), + i18n( "The file has been modified externally since it was opened, unfortunately that means that we can no longer save it." ) ); + return false; + } + bool hasUserAcceptedReload = false; if ( m_documentOpenWithPassword ) {