DocumentManager: Refactor saveModified methods

Introduce methods to save a document/list of documents/all documents,
both silently and with a dialog to the DocumentManager.

All of these return a bool that signifies whether the save was
successful or not.

Detailed information on which files failed to load or whether the
save was canceled by the user are still available as optional
in/out parameters.

Change-Id: Id17798302f2a8ba6b85a07c1f0b91f03b20da03f
Reviewed-by: Tobias Hunger <tobias.hunger@digia.com>
This commit is contained in:
Tobias Hunger
2014-01-21 13:25:19 +01:00
parent 063075ecad
commit 88a4421a84
9 changed files with 181 additions and 108 deletions

View File

@@ -719,14 +719,6 @@ void GitPlugin::submitEditorMerge(const QStringList &unmerged)
m_gitClient->merge(m_submitRepository, unmerged);
}
static bool ensureAllDocumentsSaved()
{
bool cancelled;
Core::DocumentManager::saveModifiedDocuments(Core::DocumentManager::modifiedDocuments(),
&cancelled);
return !cancelled;
}
void GitPlugin::diffCurrentFile()
{
const VcsBase::VcsBasePluginState state = currentState();
@@ -788,7 +780,7 @@ void GitPlugin::reflogRepository()
void GitPlugin::undoFileChanges(bool revertStaging)
{
if (!ensureAllDocumentsSaved())
if (!Core::DocumentManager::saveAllModifiedDocuments())
return;
const VcsBase::VcsBasePluginState state = currentState();
QTC_ASSERT(state.hasFile(), return);
@@ -798,7 +790,7 @@ void GitPlugin::undoFileChanges(bool revertStaging)
void GitPlugin::undoUnstagedFileChanges()
{
if (!ensureAllDocumentsSaved())
if (!Core::DocumentManager::saveAllModifiedDocuments())
return;
undoFileChanges(false);
}
@@ -832,7 +824,7 @@ protected:
void GitPlugin::resetRepository()
{
if (!ensureAllDocumentsSaved())
if (!Core::DocumentManager::saveAllModifiedDocuments())
return;
const VcsBase::VcsBasePluginState state = currentState();
QTC_ASSERT(state.hasTopLevel(), return);
@@ -847,7 +839,7 @@ void GitPlugin::resetRepository()
void GitPlugin::startRebase()
{
if (!ensureAllDocumentsSaved())
if (!Core::DocumentManager::saveAllModifiedDocuments())
return;
const VcsBase::VcsBasePluginState state = currentState();
QTC_ASSERT(state.hasTopLevel(), return);
@@ -889,7 +881,7 @@ void GitPlugin::startChangeRelatedAction()
return;
}
if (!ensureAllDocumentsSaved())
if (!Core::DocumentManager::saveAllModifiedDocuments())
return;
switch (dialog.command()) {
@@ -1150,7 +1142,7 @@ void GitPlugin::fetch()
void GitPlugin::pull()
{
if (!ensureAllDocumentsSaved())
if (!Core::DocumentManager::saveAllModifiedDocuments())
return;
const VcsBase::VcsBasePluginState state = currentState();
QTC_ASSERT(state.hasTopLevel(), return);
@@ -1187,7 +1179,7 @@ void GitPlugin::startMergeTool()
void GitPlugin::continueOrAbortCommand()
{
if (!ensureAllDocumentsSaved())
if (!Core::DocumentManager::saveAllModifiedDocuments())
return;
const VcsBase::VcsBasePluginState state = currentState();
QTC_ASSERT(state.hasTopLevel(), return);
@@ -1286,11 +1278,7 @@ void GitPlugin::updateSubmodules()
static bool ensureFileSaved(const QString &fileName)
{
Core::IDocument *document = Core::EditorManager::documentModel()->documentForFilePath(fileName);
if (!document || !document->isModified())
return true;
bool canceled;
Core::DocumentManager::saveModifiedDocuments(QList<Core::IDocument *>() << document, &canceled);
return !canceled;
return Core::DocumentManager::saveModifiedDocument(document);
}
void GitPlugin::applyCurrentFilePatch()
@@ -1342,7 +1330,7 @@ void GitPlugin::applyPatch(const QString &workingDirectory, QString file)
void GitPlugin::stash()
{
if (!ensureAllDocumentsSaved())
if (!Core::DocumentManager::saveAllModifiedDocuments())
return;
// Simple stash without prompt, reset repo.
const VcsBase::VcsBasePluginState state = currentState();