forked from qt-creator/qt-creator
VcsBaseEditorWidget: Get rid of DiffChunkAction struct
Change-Id: Ia35a8ef6b836709f7e058cfe33bf902f015e89b9 Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
@@ -128,24 +128,8 @@ QByteArray DiffChunk::asPatch(const QString &workingDirectory) const
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace Internal {
|
|
||||||
|
|
||||||
// Data to be passed to apply/revert diff chunk actions.
|
|
||||||
class DiffChunkAction
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
DiffChunkAction(const DiffChunk &dc = DiffChunk(), bool revertIn = false) :
|
|
||||||
chunk(dc), revert(revertIn) {}
|
|
||||||
|
|
||||||
DiffChunk chunk;
|
|
||||||
bool revert;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace Internal
|
|
||||||
} // namespace VcsBase
|
} // namespace VcsBase
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(VcsBase::Internal::DiffChunkAction)
|
|
||||||
|
|
||||||
namespace VcsBase {
|
namespace VcsBase {
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -1015,12 +999,14 @@ void VcsBaseEditorWidget::contextMenuEvent(QContextMenuEvent *e)
|
|||||||
// the user has "Open With" and choose the right diff editor so that
|
// the user has "Open With" and choose the right diff editor so that
|
||||||
// fileNameFromDiffSpecification() works.
|
// fileNameFromDiffSpecification() works.
|
||||||
QAction *applyAction = menu->addAction(tr("Apply Chunk..."));
|
QAction *applyAction = menu->addAction(tr("Apply Chunk..."));
|
||||||
applyAction->setData(QVariant::fromValue(Internal::DiffChunkAction(chunk, false)));
|
connect(applyAction, &QAction::triggered, this, [this, chunk] {
|
||||||
connect(applyAction, &QAction::triggered, this, &VcsBaseEditorWidget::slotApplyDiffChunk);
|
slotApplyDiffChunk(chunk, false);
|
||||||
|
});
|
||||||
// Revert a chunk from a VCS diff, which might be linked to reloading the diff.
|
// Revert a chunk from a VCS diff, which might be linked to reloading the diff.
|
||||||
QAction *revertAction = menu->addAction(tr("Revert Chunk..."));
|
QAction *revertAction = menu->addAction(tr("Revert Chunk..."));
|
||||||
revertAction->setData(QVariant::fromValue(Internal::DiffChunkAction(chunk, true)));
|
connect(revertAction, &QAction::triggered, this, [this, chunk] {
|
||||||
connect(revertAction, &QAction::triggered, this, &VcsBaseEditorWidget::slotApplyDiffChunk);
|
slotApplyDiffChunk(chunk, true);
|
||||||
|
});
|
||||||
// Custom diff actions
|
// Custom diff actions
|
||||||
addDiffActions(menu, chunk);
|
addDiffActions(menu, chunk);
|
||||||
break;
|
break;
|
||||||
@@ -1624,22 +1610,19 @@ bool VcsBaseEditorWidget::hasDiff() const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void VcsBaseEditorWidget::slotApplyDiffChunk()
|
void VcsBaseEditorWidget::slotApplyDiffChunk(const DiffChunk &chunk, bool revert)
|
||||||
{
|
{
|
||||||
const QAction *a = qobject_cast<QAction *>(sender());
|
const QString title = revert ? tr("Revert Chunk") : tr("Apply Chunk");
|
||||||
QTC_ASSERT(a, return);
|
const QString question = revert ? tr("Would you like to revert the chunk?")
|
||||||
const Internal::DiffChunkAction chunkAction = qvariant_cast<Internal::DiffChunkAction>(a->data());
|
: tr("Would you like to apply the chunk?");
|
||||||
const QString title = chunkAction.revert ? tr("Revert Chunk") : tr("Apply Chunk");
|
|
||||||
const QString question = chunkAction.revert ?
|
|
||||||
tr("Would you like to revert the chunk?") : tr("Would you like to apply the chunk?");
|
|
||||||
if (QMessageBox::No == QMessageBox::question(this, title, question, QMessageBox::Yes|QMessageBox::No))
|
if (QMessageBox::No == QMessageBox::question(this, title, question, QMessageBox::Yes|QMessageBox::No))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (applyDiffChunk(chunkAction.chunk, chunkAction.revert)) {
|
if (applyDiffChunk(chunk, revert)) {
|
||||||
if (chunkAction.revert)
|
if (revert)
|
||||||
emit diffChunkReverted(chunkAction.chunk);
|
emit diffChunkReverted(chunk);
|
||||||
else
|
else
|
||||||
emit diffChunkApplied(chunkAction.chunk);
|
emit diffChunkApplied(chunk);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -274,7 +274,7 @@ private:
|
|||||||
void slotJumpToEntry(int);
|
void slotJumpToEntry(int);
|
||||||
void slotCursorPositionChanged() override;
|
void slotCursorPositionChanged() override;
|
||||||
void slotAnnotateRevision(const QString &change);
|
void slotAnnotateRevision(const QString &change);
|
||||||
void slotApplyDiffChunk();
|
void slotApplyDiffChunk(const DiffChunk &chunk, bool revert);
|
||||||
void slotPaste();
|
void slotPaste();
|
||||||
void showProgressIndicator();
|
void showProgressIndicator();
|
||||||
void hideProgressIndicator();
|
void hideProgressIndicator();
|
||||||
|
Reference in New Issue
Block a user