DiffEditor/VCS: Save document before applying/reverting patch chunk

Fixes: QTCREATORBUG-22506
Change-Id: I646f24068c0c81890f36052537320a743fdeb498
Reviewed-by: André Hartmann <aha_1980@gmx.de>
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Orgad Shaneh
2022-10-16 04:59:51 +03:00
committed by Orgad Shaneh
parent 7edf743583
commit f696d1e6cf
4 changed files with 23 additions and 9 deletions

View File

@@ -134,9 +134,6 @@ void DiffEditorWidgetController::patch(PatchAction patchAction, int fileIndex, i
if (!chunkExists(fileIndex, chunkIndex))
return;
if (!PatchTool::confirmPatching(m_diffEditorWidget, patchAction))
return;
const FileData fileData = m_contextFileData.at(fileIndex);
const QString fileName = patchAction == PatchAction::Apply
? fileData.fileInfo[LeftSide].fileName
@@ -150,7 +147,17 @@ void DiffEditorWidgetController::patch(PatchAction patchAction, int fileIndex, i
: m_document->baseDirectory();
const FilePath absFilePath = workingDirectory.resolvePath(fileName).absoluteFilePath();
auto textDocument = qobject_cast<TextEditor::TextDocument *>(
DocumentModel::documentForFilePath(absFilePath));
const bool isModified = patchBehaviour == DiffFileInfo::PatchFile &&
textDocument && textDocument->isModified();
if (!PatchTool::confirmPatching(m_diffEditorWidget, patchAction, isModified))
return;
if (patchBehaviour == DiffFileInfo::PatchFile) {
if (textDocument && !EditorManager::saveDocument(textDocument))
return;
const int strip = m_document->baseDirectory().isEmpty() ? -1 : 0;
const QString patch = m_document->makePatch(fileIndex, chunkIndex, {}, patchAction);
@@ -163,8 +170,6 @@ void DiffEditorWidgetController::patch(PatchAction patchAction, int fileIndex, i
workingDirectory, strip, patchAction))
m_document->reload();
} else { // PatchEditor
auto textDocument = qobject_cast<TextEditor::TextDocument *>(
DocumentModel::documentForFilePath(absFilePath));
if (!textDocument)
return;