forked from qt-creator/qt-creator
Implement diff on close, on revert and on external modification
Task-number: QTCREATORBUG-1531 Change-Id: I8c9a740d66eb7836b3df6850ac243260fd282b32 Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
@@ -29,6 +29,7 @@
|
||||
#include "idocument.h"
|
||||
#include "coreconstants.h"
|
||||
|
||||
#include <coreplugin/diffservice.h>
|
||||
#include <coreplugin/dialogs/readonlyfilesdialog.h>
|
||||
#include <coreplugin/dialogs/saveitemsdialog.h>
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
@@ -38,6 +39,8 @@
|
||||
#include <coreplugin/editormanager/ieditorfactory.h>
|
||||
#include <coreplugin/editormanager/iexternaleditor.h>
|
||||
|
||||
#include <extensionsystem/pluginmanager.h>
|
||||
|
||||
#include <utils/fileutils.h>
|
||||
#include <utils/hostosinfo.h>
|
||||
#include <utils/mimetypes/mimedatabase.h>
|
||||
@@ -606,6 +609,11 @@ static bool saveModifiedFilesHelper(const QList<IDocument *> &documents,
|
||||
(*alwaysSave) = dia.alwaysSaveChecked();
|
||||
if (failedToSave)
|
||||
(*failedToSave) = modifiedDocuments;
|
||||
const QStringList filesToDiff = dia.filesToDiff();
|
||||
if (!filesToDiff.isEmpty()) {
|
||||
if (auto diffService = ExtensionSystem::PluginManager::getObject<DiffService>())
|
||||
diffService->diffModifiedFiles(filesToDiff);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (alwaysSave)
|
||||
@@ -978,6 +986,7 @@ void DocumentManager::checkForReload()
|
||||
|
||||
// handle the IDocuments
|
||||
QStringList errorStrings;
|
||||
QStringList filesToDiff;
|
||||
foreach (IDocument *document, changedIDocuments) {
|
||||
IDocument::ChangeTrigger trigger = IDocument::TriggerInternal;
|
||||
IDocument::ChangeType type = IDocument::TypePermissions;
|
||||
@@ -1067,7 +1076,7 @@ void DocumentManager::checkForReload()
|
||||
// IDocument wants us to ask
|
||||
} else if (type == IDocument::TypeContents) {
|
||||
// content change, IDocument wants to ask user
|
||||
if (previousReloadAnswer == ReloadNone) {
|
||||
if (previousReloadAnswer == ReloadNone || previousReloadAnswer == ReloadNoneAndDiff) {
|
||||
// answer already given, ignore
|
||||
success = document->reload(&errorString, IDocument::FlagIgnore, IDocument::TypeContents);
|
||||
} else if (previousReloadAnswer == ReloadAll) {
|
||||
@@ -1076,7 +1085,8 @@ void DocumentManager::checkForReload()
|
||||
} else {
|
||||
// Ask about content change
|
||||
previousReloadAnswer = reloadPrompt(document->filePath(), document->isModified(),
|
||||
ICore::dialogParent());
|
||||
ExtensionSystem::PluginManager::getObject<DiffService>(),
|
||||
ICore::dialogParent());
|
||||
switch (previousReloadAnswer) {
|
||||
case ReloadAll:
|
||||
case ReloadCurrent:
|
||||
@@ -1084,6 +1094,7 @@ void DocumentManager::checkForReload()
|
||||
break;
|
||||
case ReloadSkipCurrent:
|
||||
case ReloadNone:
|
||||
case ReloadNoneAndDiff:
|
||||
success = document->reload(&errorString, IDocument::FlagIgnore, IDocument::TypeContents);
|
||||
break;
|
||||
case CloseCurrent:
|
||||
@@ -1091,6 +1102,9 @@ void DocumentManager::checkForReload()
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (previousReloadAnswer == ReloadNoneAndDiff)
|
||||
filesToDiff.append(document->filePath().toString());
|
||||
|
||||
// IDocument wants us to ask, and it's the TypeRemoved case
|
||||
} else {
|
||||
// Ask about removed file
|
||||
@@ -1134,6 +1148,12 @@ void DocumentManager::checkForReload()
|
||||
|
||||
d->m_blockedIDocument = 0;
|
||||
}
|
||||
|
||||
if (!filesToDiff.isEmpty()) {
|
||||
if (auto diffService = ExtensionSystem::PluginManager::getObject<DiffService>())
|
||||
diffService->diffModifiedFiles(filesToDiff);
|
||||
}
|
||||
|
||||
if (!errorStrings.isEmpty())
|
||||
QMessageBox::critical(ICore::dialogParent(), tr("File Error"),
|
||||
errorStrings.join(QLatin1Char('\n')));
|
||||
|
Reference in New Issue
Block a user