diff --git a/part/part.cpp b/part/part.cpp index d5747342c..5f56b567a 100644 --- a/part/part.cpp +++ b/part/part.cpp @@ -1109,6 +1109,21 @@ bool Part::activateTabIfAlreadyOpenFile() const return Okular::Settings::self()->switchToTabIfOpen(); } +void Part::setModified(bool modified) +{ + KParts::ReadWritePart::setModified(modified); + + if (modified && !m_save->isEnabled()) { + if (!m_warnedAboutModifyingUnsaveableDocument) { + m_warnedAboutModifyingUnsaveableDocument = true; + KMessageBox::information(widget(), + i18n("You have just modified the open document, but this kind of document can not be saved.\nAny modification will be lost once Okular is closed."), + i18n("Document can't be saved"), + QStringLiteral("warnAboutUnsaveableDocuments")); + } + } +} + void Part::slotHandleActivatedSourceReference(const QString &absFileName, int line, int col, bool *handled) { emit openSourceReference(absFileName, line, col); @@ -1486,6 +1501,7 @@ Document::OpenResult Part::doOpenFile(const QMimeType &mimeA, const QString &fil if (openResult == Document::OpenSuccess) { m_fileLastModified = QFileInfo(localFilePath()).lastModified(); + m_warnedAboutModifyingUnsaveableDocument = false; } return openResult; } @@ -1798,16 +1814,21 @@ bool Part::queryClose() 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"), KStandardGuiItem::save(), KStandardGuiItem::discard()); + // Not all things are saveable (e.g. files opened from stdin, folders) + if (m_save->isEnabled()) { + const int res = KMessageBox::warningYesNoCancel(widget(), i18n("Do you want to save your changes to \"%1\" or discard them?", url().fileName()), i18n("Close Document"), KStandardGuiItem::save(), KStandardGuiItem::discard()); - switch (res) { - case KMessageBox::Yes: // Save - saveFile(); - return !isModified(); // Only allow closing if file was really saved - case KMessageBox::No: // Discard + switch (res) { + case KMessageBox::Yes: // Save + saveFile(); + return !isModified(); // Only allow closing if file was really saved + case KMessageBox::No: // Discard + return true; + default: // Cancel + return false; + } + } else { return true; - default: // Cancel - return false; } } diff --git a/part/part.h b/part/part.h index 63e257da1..d8e86f2b1 100644 --- a/part/part.h +++ b/part/part.h @@ -149,6 +149,8 @@ public: bool openNewFilesInTabs() const override; Q_INVOKABLE bool activateTabIfAlreadyOpenFile() const; + void setModified(bool modified) override; + public Q_SLOTS: // dbus Q_SCRIPTABLE Q_NOREPLY void goToPage(uint page) override; Q_SCRIPTABLE Q_NOREPLY void openDocument(const QString &doc); @@ -332,6 +334,7 @@ private: bool isDocumentArchive; bool m_documentOpenWithPassword; bool m_swapInsteadOfOpening; // if set, the next open operation will replace the backing file (used when reloading just saved files) + bool m_warnedAboutModifyingUnsaveableDocument = false; // main widgets Sidebar *m_sidebar;