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:
@@ -51,8 +51,9 @@
|
||||
#include <utils/globalfilechangeblocker.h>
|
||||
#include <utils/hostosinfo.h>
|
||||
#include <utils/mimetypes/mimedatabase.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/optional.h>
|
||||
#include <utils/pathchooser.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/reloadpromptutils.h>
|
||||
|
||||
#include <QStringList>
|
||||
@@ -1141,7 +1142,7 @@ void DocumentManager::checkForReload()
|
||||
QStringList filesToDiff;
|
||||
foreach (IDocument *document, changedIDocuments) {
|
||||
IDocument::ChangeTrigger trigger = IDocument::TriggerInternal;
|
||||
IDocument::ChangeType type = IDocument::TypePermissions;
|
||||
optional<IDocument::ChangeType> 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
|
||||
|
||||
Reference in New Issue
Block a user