forked from qt-creator/qt-creator
IDocument: Simplify permission changes
Take care of handling file permission changes centrally. TextDocument had its own, caching implementation of tracking the backing file's read-only state. Move that into IDocument directly. IDocument::reload with a permission-only change is not a very interesting case, but every subclass needed to add handling of it. Instead, remove TypePermission from the file-change types, and handle it separately via the now unified checkPermissions() implementation. IDocument::reloadBehavior already was never called with TypePermission. Change-Id: I321d47ba6193bc878efa9bb50ba7a739fa492745 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -27,6 +27,7 @@
|
||||
|
||||
#include <utils/fileutils.h>
|
||||
#include <utils/infobar.h>
|
||||
#include <utils/optional.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
#include <QFile>
|
||||
@@ -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<bool> 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<IDocument *>(this)->checkPermissions();
|
||||
return d->fileIsReadOnly.value_or(false);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
||||
Reference in New Issue
Block a user