diff --git a/src/plugins/bineditor/bineditorplugin.cpp b/src/plugins/bineditor/bineditorplugin.cpp index 6ace310acb3..ae766e5be03 100644 --- a/src/plugins/bineditor/bineditorplugin.cpp +++ b/src/plugins/bineditor/bineditorplugin.cpp @@ -322,31 +322,20 @@ public: : m_widget->isModified(); } - bool isFileReadOnly() const override { - const FilePath fn = filePath(); - if (fn.isEmpty()) - return false; - return !fn.toFileInfo().isWritable(); - } - bool isSaveAsAllowed() const override { return true; } bool reload(QString *errorString, ReloadFlag flag, ChangeType type) override { + Q_UNUSED(type) if (flag == FlagIgnore) return true; - if (type == TypePermissions) { - emit changed(); - } else { - emit aboutToReload(); - int cPos = m_widget->cursorPosition(); - m_widget->clear(); - const bool success = (openImpl(errorString, filePath().toString()) == OpenResult::Success); - m_widget->setCursorPosition(cPos); - emit reloadFinished(success); - return success; - } - return true; + emit aboutToReload(); + int cPos = m_widget->cursorPosition(); + m_widget->clear(); + const bool success = (openImpl(errorString, filePath().toString()) == OpenResult::Success); + m_widget->setCursorPosition(cPos); + emit reloadFinished(success); + return success; } private: diff --git a/src/plugins/coreplugin/documentmanager.cpp b/src/plugins/coreplugin/documentmanager.cpp index a061d09c072..d4e083ec0ab 100644 --- a/src/plugins/coreplugin/documentmanager.cpp +++ b/src/plugins/coreplugin/documentmanager.cpp @@ -51,8 +51,9 @@ #include #include #include -#include +#include #include +#include #include #include @@ -1141,7 +1142,7 @@ void DocumentManager::checkForReload() QStringList filesToDiff; foreach (IDocument *document, changedIDocuments) { IDocument::ChangeTrigger trigger = IDocument::TriggerInternal; - IDocument::ChangeType type = IDocument::TypePermissions; + optional type; bool changed = false; // find out the type & behavior from the two possible files // behavior is internal if all changes are expected (and none removed) @@ -1174,7 +1175,7 @@ void DocumentManager::checkForReload() IDocument::ChangeType fileChange = changeTypes.value(fileKey); if (fileChange == IDocument::TypeRemoved) type = IDocument::TypeRemoved; - else if (fileChange == IDocument::TypeContents && type == IDocument::TypePermissions) + else if (fileChange == IDocument::TypeContents && !type) type = IDocument::TypeContents; } @@ -1196,35 +1197,36 @@ void DocumentManager::checkForReload() QString errorString; // we've got some modification // check if it's contents or permissions: - if (type == IDocument::TypePermissions) { + if (!type) { // Only permission change - success = document->reload(&errorString, IDocument::FlagReload, IDocument::TypePermissions); - // now we know it's a content change or file was removed - } else if (defaultBehavior == IDocument::ReloadUnmodified - && type == IDocument::TypeContents && !document->isModified()) { + document->checkPermissions(); + success = true; + // now we know it's a content change or file was removed + } else if (defaultBehavior == IDocument::ReloadUnmodified && type == IDocument::TypeContents + && !document->isModified()) { // content change, but unmodified (and settings say to reload in this case) - success = document->reload(&errorString, IDocument::FlagReload, type); - // file was removed or it's a content change and the default behavior for - // unmodified files didn't kick in - } else if (defaultBehavior == IDocument::ReloadUnmodified - && type == IDocument::TypeRemoved && !document->isModified()) { + success = document->reload(&errorString, IDocument::FlagReload, *type); + // file was removed or it's a content change and the default behavior for + // unmodified files didn't kick in + } else if (defaultBehavior == IDocument::ReloadUnmodified && type == IDocument::TypeRemoved + && !document->isModified()) { // file removed, but unmodified files should be reloaded // so we close the file documentsToClose << document; } else if (defaultBehavior == IDocument::IgnoreAll) { // content change or removed, but settings say ignore - success = document->reload(&errorString, IDocument::FlagIgnore, type); - // either the default behavior is to always ask, - // or the ReloadUnmodified default behavior didn't kick in, - // so do whatever the IDocument wants us to do + success = document->reload(&errorString, IDocument::FlagIgnore, *type); + // either the default behavior is to always ask, + // or the ReloadUnmodified default behavior didn't kick in, + // so do whatever the IDocument wants us to do } else { // check if IDocument wants us to ask - if (document->reloadBehavior(trigger, type) == IDocument::BehaviorSilent) { + if (document->reloadBehavior(trigger, *type) == IDocument::BehaviorSilent) { // content change or removed, IDocument wants silent handling if (type == IDocument::TypeRemoved) documentsToClose << document; else - success = document->reload(&errorString, IDocument::FlagReload, type); + success = document->reload(&errorString, IDocument::FlagReload, *type); // IDocument wants us to ask } else if (type == IDocument::TypeContents) { // content change, IDocument wants to ask user diff --git a/src/plugins/coreplugin/idocument.cpp b/src/plugins/coreplugin/idocument.cpp index b20a03097b1..4a177a711fb 100644 --- a/src/plugins/coreplugin/idocument.cpp +++ b/src/plugins/coreplugin/idocument.cpp @@ -27,6 +27,7 @@ #include #include +#include #include #include @@ -129,8 +130,6 @@ \value TypeContents The contents of the file changed. - \value TypePermissions - The file permissions changed. \value TypeRemoved The file was removed. @@ -228,6 +227,7 @@ public: QString autoSaveName; Utils::InfoBar *infoBar = nullptr; Id id; + optional fileIsReadOnly; bool temporary = false; bool hasWriteWarning = false; bool restored = false; @@ -403,8 +403,6 @@ const Utils::FilePath &IDocument::filePath() const */ IDocument::ReloadBehavior IDocument::reloadBehavior(ChangeTrigger trigger, ChangeType type) const { - if (type == TypePermissions) - return BehaviorSilent; if (type == TypeContents && trigger == TriggerInternal && !isModified()) return BehaviorSilent; return BehaviorAsk; @@ -443,10 +441,18 @@ bool IDocument::reload(QString *errorString, ReloadFlag flag, ChangeType type) } /*! - \internal + Updates the cached information about the read-only status of the backing file. */ void IDocument::checkPermissions() { + bool previousReadOnly = d->fileIsReadOnly.value_or(false); + if (!filePath().isEmpty()) { + d->fileIsReadOnly = !filePath().toFileInfo().isWritable(); + } else { + d->fileIsReadOnly = false; + } + if (previousReadOnly != *(d->fileIsReadOnly)) + emit changed(); } /*! @@ -524,7 +530,9 @@ bool IDocument::isFileReadOnly() const { if (filePath().isEmpty()) return false; - return !filePath().toFileInfo().isWritable(); + if (!d->fileIsReadOnly) + const_cast(this)->checkPermissions(); + return d->fileIsReadOnly.value_or(false); } /*! diff --git a/src/plugins/coreplugin/idocument.h b/src/plugins/coreplugin/idocument.h index 66a95a8b49a..b468bf1a625 100644 --- a/src/plugins/coreplugin/idocument.h +++ b/src/plugins/coreplugin/idocument.h @@ -68,7 +68,6 @@ public: enum ChangeType { TypeContents, - TypePermissions, TypeRemoved }; @@ -104,7 +103,7 @@ public: void setUniqueDisplayName(const QString &name); QString uniqueDisplayName() const; - virtual bool isFileReadOnly() const; + bool isFileReadOnly() const; bool isTemporary() const; void setTemporary(bool temporary); @@ -123,7 +122,7 @@ public: virtual ReloadBehavior reloadBehavior(ChangeTrigger state, ChangeType type) const; virtual bool reload(QString *errorString, ReloadFlag flag, ChangeType type); - virtual void checkPermissions(); + void checkPermissions(); bool autoSave(QString *errorString, const QString &filePath); void setRestoredFrom(const QString &name); diff --git a/src/plugins/designer/formwindowfile.cpp b/src/plugins/designer/formwindowfile.cpp index 7fbc442a722..7e85f13e472 100644 --- a/src/plugins/designer/formwindowfile.cpp +++ b/src/plugins/designer/formwindowfile.cpp @@ -225,9 +225,6 @@ bool FormWindowFile::reload(QString *errorString, ReloadFlag flag, ChangeType ty if (!wasModified) updateIsModified(); return true; - } - if (type == TypePermissions) { - emit changed(); } else { emit aboutToReload(); const bool success @@ -235,7 +232,6 @@ bool FormWindowFile::reload(QString *errorString, ReloadFlag flag, ChangeType ty emit reloadFinished(success); return success; } - return true; } void FormWindowFile::setFallbackSaveAsFileName(const QString &fn) diff --git a/src/plugins/genericprojectmanager/genericproject.cpp b/src/plugins/genericprojectmanager/genericproject.cpp index bcfd220e88f..2157c62e237 100644 --- a/src/plugins/genericprojectmanager/genericproject.cpp +++ b/src/plugins/genericprojectmanager/genericproject.cpp @@ -642,9 +642,7 @@ bool GenericProjectFile::reload(QString *errorString, IDocument::ReloadFlag flag { Q_UNUSED(errorString) Q_UNUSED(flag) - if (type == TypePermissions) - return true; - + Q_UNUSED(type) if (Target *t = m_project->activeTarget()) static_cast(t->buildSystem())->refresh(m_options); diff --git a/src/plugins/imageviewer/imageviewerfile.cpp b/src/plugins/imageviewer/imageviewerfile.cpp index 2845b840ef1..821e6ba77c0 100644 --- a/src/plugins/imageviewer/imageviewerfile.cpp +++ b/src/plugins/imageviewer/imageviewerfile.cpp @@ -148,7 +148,7 @@ Core::IDocument::OpenResult ImageViewerFile::openImpl(QString *errorString, cons Core::IDocument::ReloadBehavior ImageViewerFile::reloadBehavior(ChangeTrigger state, ChangeType type) const { - if (type == TypeRemoved || type == TypePermissions) + if (type == TypeRemoved) return BehaviorSilent; if (type == TypeContents && state == TriggerInternal && !isModified()) return BehaviorSilent; @@ -159,12 +159,9 @@ bool ImageViewerFile::reload(QString *errorString, Core::IDocument::ReloadFlag flag, Core::IDocument::ChangeType type) { + Q_UNUSED(type) if (flag == FlagIgnore) return true; - if (type == TypePermissions) { - emit changed(); - return true; - } emit aboutToReload(); bool success = (openImpl(errorString, filePath().toString()) == OpenResult::Success); emit reloadFinished(success); diff --git a/src/plugins/modeleditor/modeldocument.cpp b/src/plugins/modeleditor/modeldocument.cpp index 827472c3bf0..bcb1322715a 100644 --- a/src/plugins/modeleditor/modeldocument.cpp +++ b/src/plugins/modeleditor/modeldocument.cpp @@ -121,12 +121,9 @@ bool ModelDocument::isSaveAsAllowed() const bool ModelDocument::reload(QString *errorString, Core::IDocument::ReloadFlag flag, Core::IDocument::ChangeType type) { + Q_UNUSED(type) if (flag == FlagIgnore) return true; - if (type == TypePermissions) { - emit changed(); - return true; - } try { d->documentController->loadProject(filePath().toString()); } catch (const qmt::FileNotFoundException &ex) { diff --git a/src/plugins/qmakeprojectmanager/qmakeproject.cpp b/src/plugins/qmakeprojectmanager/qmakeproject.cpp index cbaa22c7881..97b519e83cc 100644 --- a/src/plugins/qmakeprojectmanager/qmakeproject.cpp +++ b/src/plugins/qmakeprojectmanager/qmakeproject.cpp @@ -121,8 +121,7 @@ public: { Q_UNUSED(errorString) Q_UNUSED(flag) - if (type == TypePermissions) - return true; + Q_UNUSED(type) m_priFile->scheduleUpdate(); return true; } diff --git a/src/plugins/resourceeditor/resourceeditorw.cpp b/src/plugins/resourceeditor/resourceeditorw.cpp index ff711917529..726ef54ddc9 100644 --- a/src/plugins/resourceeditor/resourceeditorw.cpp +++ b/src/plugins/resourceeditor/resourceeditorw.cpp @@ -268,18 +268,14 @@ bool ResourceEditorDocument::isSaveAsAllowed() const bool ResourceEditorDocument::reload(QString *errorString, ReloadFlag flag, ChangeType type) { + Q_UNUSED(type) if (flag == FlagIgnore) return true; - if (type == TypePermissions) { - emit changed(); - } else { - emit aboutToReload(); - QString fn = filePath().toString(); - const bool success = (open(errorString, fn, fn) == OpenResult::Success); - emit reloadFinished(success); - return success; - } - return true; + emit aboutToReload(); + QString fn = filePath().toString(); + const bool success = (open(errorString, fn, fn) == OpenResult::Success); + emit reloadFinished(success); + return success; } void ResourceEditorDocument::dirtyChanged(bool dirty) diff --git a/src/plugins/resourceeditor/resourcenode.cpp b/src/plugins/resourceeditor/resourcenode.cpp index 0792e84d4e6..88c04bbfc2c 100644 --- a/src/plugins/resourceeditor/resourcenode.cpp +++ b/src/plugins/resourceeditor/resourcenode.cpp @@ -70,8 +70,7 @@ public: bool reload(QString *, ReloadFlag, ChangeType type) final { - if (type == TypePermissions) - return true; + Q_UNUSED(type) FolderNode *parent = m_node->parentFolderNode(); QTC_ASSERT(parent, return false); parent->replaceSubtree(m_node, std::make_unique( diff --git a/src/plugins/scxmleditor/scxmleditordocument.cpp b/src/plugins/scxmleditor/scxmleditordocument.cpp index 5c2a072326b..10acfe24c50 100644 --- a/src/plugins/scxmleditor/scxmleditordocument.cpp +++ b/src/plugins/scxmleditor/scxmleditordocument.cpp @@ -136,19 +136,14 @@ bool ScxmlEditorDocument::isModified() const bool ScxmlEditorDocument::reload(QString *errorString, ReloadFlag flag, ChangeType type) { - if (flag == FlagIgnore) { + Q_UNUSED(type) + if (flag == FlagIgnore) return true; - } if (type == TypePermissions) { - emit changed(); - } else { - emit aboutToReload(); - emit reloadRequested(errorString, filePath().toString()); - const bool success = errorString->isEmpty(); - emit reloadFinished(success); - return success; - } - - return true; + emit aboutToReload(); + emit reloadRequested(errorString, filePath().toString()); + const bool success = errorString->isEmpty(); + emit reloadFinished(success); + return success; } QString ScxmlEditorDocument::designWidgetContents() const diff --git a/src/plugins/tasklist/taskfile.cpp b/src/plugins/tasklist/taskfile.cpp index ad9b9d18b72..7bd512df563 100644 --- a/src/plugins/tasklist/taskfile.cpp +++ b/src/plugins/tasklist/taskfile.cpp @@ -52,8 +52,6 @@ bool TaskFile::reload(QString *errorString, ReloadFlag flag, ChangeType type) { Q_UNUSED(flag) - if (type == TypePermissions) - return true; if (type == TypeRemoved) { deleteLater(); return true; diff --git a/src/plugins/texteditor/textdocument.cpp b/src/plugins/texteditor/textdocument.cpp index 971a43ba919..dfafcf2eb6e 100644 --- a/src/plugins/texteditor/textdocument.cpp +++ b/src/plugins/texteditor/textdocument.cpp @@ -106,7 +106,6 @@ public: QScopedPointer m_indenter; QScopedPointer m_formatter; - bool m_fileIsReadOnly = false; int m_autoSaveRevision = -1; TextMarks m_marksCache; // Marks not owned @@ -702,30 +701,11 @@ void TextDocument::setFilePath(const Utils::FilePath &newName) IDocument::setFilePath(Utils::FilePath::fromUserInput(newName.toFileInfo().absoluteFilePath())); } -bool TextDocument::isFileReadOnly() const -{ - if (filePath().isEmpty()) //have no corresponding file, so editing is ok - return false; - return d->m_fileIsReadOnly; -} - bool TextDocument::isModified() const { return d->m_document.isModified(); } -void TextDocument::checkPermissions() -{ - bool previousReadOnly = d->m_fileIsReadOnly; - if (!filePath().isEmpty()) { - d->m_fileIsReadOnly = !filePath().toFileInfo().isWritable(); - } else { - d->m_fileIsReadOnly = false; - } - if (previousReadOnly != d->m_fileIsReadOnly) - emit changed(); -} - Core::IDocument::OpenResult TextDocument::open(QString *errorString, const QString &fileName, const QString &realFileName) { @@ -747,7 +727,6 @@ Core::IDocument::OpenResult TextDocument::openImpl(QString *errorString, const Q if (!fileName.isEmpty()) { const QFileInfo fi(fileName); - d->m_fileIsReadOnly = !fi.isWritable(); readResult = read(realFileName, &content, errorString); const int chunks = content.size(); @@ -864,12 +843,7 @@ bool TextDocument::reload(QString *errorString, ReloadFlag flag, ChangeType type modificationChanged(true); return true; } - if (type == TypePermissions) { - checkPermissions(); - return true; - } else { - return reload(errorString); - } + return reload(errorString); } void TextDocument::setSyntaxHighlighter(SyntaxHighlighter *highlighter) diff --git a/src/plugins/texteditor/textdocument.h b/src/plugins/texteditor/textdocument.h index b01ea25574a..df2ed71ab30 100644 --- a/src/plugins/texteditor/textdocument.h +++ b/src/plugins/texteditor/textdocument.h @@ -115,10 +115,8 @@ public: QByteArray contents() const override; bool setContents(const QByteArray &contents) override; bool shouldAutoSave() const override; - bool isFileReadOnly() const override; bool isModified() const override; bool isSaveAsAllowed() const override; - void checkPermissions() override; bool reload(QString *errorString, ReloadFlag flag, ChangeType type) override; void setFilePath(const Utils::FilePath &newName) override;