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:
@@ -106,7 +106,6 @@ public:
|
||||
QScopedPointer<Indenter> m_indenter;
|
||||
QScopedPointer<Formatter> 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)
|
||||
|
||||
Reference in New Issue
Block a user