Fix repeting Stage/Unstage actions in unified diff editor

Don't store diff file index, chunk index and diff editor
controller anymore. Pass needed indices by value,
retrieve them when needed as lambda copy.

Change-Id: I3a81f1ab6d131c0b1d9899ac4b061b6e25582f51
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
Jarek Kobus
2018-02-15 10:29:14 +01:00
parent 9494a9e0c0
commit 64233a4fae
10 changed files with 121 additions and 126 deletions

View File

@@ -71,9 +71,10 @@ QString DiffEditorController::revisionFromDescription() const
return m_document->description().mid(7, 12);
}
QString DiffEditorController::makePatch(PatchOptions options) const
QString DiffEditorController::makePatch(int fileIndex, int chunkIndex,
PatchOptions options) const
{
return m_document->makePatch(m_diffFileIndex, m_chunkIndex,
return m_document->makePatch(fileIndex, chunkIndex,
options & Revert, options & AddPrefix);
}
@@ -152,11 +153,27 @@ void DiffEditorController::reloadFinished(bool success)
m_isReloading = false;
}
void DiffEditorController::requestChunkActions(QMenu *menu, int diffFileIndex, int chunkIndex)
void DiffEditorController::requestChunkActions(QMenu *menu, int fileIndex, int chunkIndex)
{
m_diffFileIndex = diffFileIndex;
m_chunkIndex = chunkIndex;
emit chunkActionsRequested(menu, diffFileIndex >= 0 && chunkIndex >= 0);
emit chunkActionsRequested(menu, fileIndex, chunkIndex);
}
bool DiffEditorController::chunkExists(int fileIndex, int chunkIndex) const
{
if (!m_document)
return false;
if (fileIndex < 0 || chunkIndex < 0)
return false;
if (fileIndex >= m_document->diffFiles().count())
return false;
const FileData fileData = m_document->diffFiles().at(fileIndex);
if (chunkIndex >= fileData.chunks.count())
return false;
return true;
}
} // namespace DiffEditor