forked from qt-creator/qt-creator
Git: Make addChangeActions a static function
Will move and reuse it for output window links. Change-Id: Iad5a164e9a30c38ea9bac07989196b9361384339 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
committed by
Orgad Shaneh
parent
4422805cec
commit
5765bd8507
@@ -216,12 +216,6 @@ void GitEditorWidget::setPlainText(const QString &text)
|
||||
textDocument()->setPlainText(modText);
|
||||
}
|
||||
|
||||
void GitEditorWidget::resetChange(const QByteArray &resetType)
|
||||
{
|
||||
GitPlugin::client()->reset(
|
||||
sourceWorkingDirectory(), QLatin1String("--" + resetType), m_currentChange);
|
||||
}
|
||||
|
||||
void GitEditorWidget::applyDiffChunk(const DiffChunk& chunk, bool revert)
|
||||
{
|
||||
Utils::TemporaryFile patchFile("git-apply-chunk");
|
||||
@@ -314,32 +308,28 @@ bool GitEditorWidget::isValidRevision(const QString &revision) const
|
||||
return GitPlugin::client()->isValidRevision(revision);
|
||||
}
|
||||
|
||||
void GitEditorWidget::addChangeActions(QMenu *menu, const QString &change)
|
||||
void GitEditorWidget::addChangeActions(QMenu *menu, const QString &change, const QString &workingDir)
|
||||
{
|
||||
m_currentChange = change;
|
||||
if (contentType() == OtherContent)
|
||||
return;
|
||||
|
||||
menu->addAction(tr("Cherr&y-Pick Change %1").arg(change), this, [this] {
|
||||
GitPlugin::client()->synchronousCherryPick(sourceWorkingDirectory(), m_currentChange);
|
||||
menu->addAction(tr("Cherr&y-Pick Change %1").arg(change), [workingDir, change] {
|
||||
GitPlugin::client()->synchronousCherryPick(workingDir, change);
|
||||
});
|
||||
menu->addAction(tr("Re&vert Change %1").arg(change), this, [this] {
|
||||
GitPlugin::client()->synchronousRevert(sourceWorkingDirectory(), m_currentChange);
|
||||
menu->addAction(tr("Re&vert Change %1").arg(change), [workingDir, change] {
|
||||
GitPlugin::client()->synchronousRevert(workingDir, change);
|
||||
});
|
||||
menu->addAction(tr("C&heckout Change %1").arg(change), this, [this] {
|
||||
GitPlugin::client()->checkout(sourceWorkingDirectory(), m_currentChange);
|
||||
menu->addAction(tr("C&heckout Change %1").arg(change), [workingDir, change] {
|
||||
GitPlugin::client()->checkout(workingDir, change);
|
||||
});
|
||||
connect(menu->addAction(tr("&Interactive Rebase from Change %1...").arg(change)),
|
||||
&QAction::triggered, this, [this] {
|
||||
GitPlugin::startRebaseFromCommit(sourceWorkingDirectory(), m_currentChange);
|
||||
&QAction::triggered, [workingDir, change] {
|
||||
GitPlugin::startRebaseFromCommit(workingDir, change);
|
||||
});
|
||||
menu->addAction(tr("&Log for Change %1").arg(change), this, [this] {
|
||||
GitPlugin::client()->log(sourceWorkingDirectory(), QString(), false, {m_currentChange});
|
||||
menu->addAction(tr("&Log for Change %1").arg(change), [workingDir, change] {
|
||||
GitPlugin::client()->log(workingDir, QString(), false, {change});
|
||||
});
|
||||
menu->addAction(tr("Add &Tag for Change %1...").arg(change), this, [this] {
|
||||
menu->addAction(tr("Add &Tag for Change %1...").arg(change), [workingDir, change] {
|
||||
QString output;
|
||||
QString errorMessage;
|
||||
GitPlugin::client()->synchronousTagCmd(sourceWorkingDirectory(), QStringList(),
|
||||
GitPlugin::client()->synchronousTagCmd(workingDir, QStringList(),
|
||||
&output, &errorMessage);
|
||||
|
||||
const QStringList tags = output.split('\n');
|
||||
@@ -348,21 +338,31 @@ void GitEditorWidget::addChangeActions(QMenu *menu, const QString &change)
|
||||
if (dialog.exec() == QDialog::Rejected)
|
||||
return;
|
||||
|
||||
GitPlugin::client()->synchronousTagCmd(sourceWorkingDirectory(),
|
||||
{dialog.branchName(), m_currentChange},
|
||||
GitPlugin::client()->synchronousTagCmd(workingDir,
|
||||
{dialog.branchName(), change},
|
||||
&output, &errorMessage);
|
||||
VcsOutputWindow::append(output);
|
||||
if (!errorMessage.isEmpty())
|
||||
VcsOutputWindow::append(errorMessage, VcsOutputWindow::MessageStyle::Error);
|
||||
});
|
||||
|
||||
auto resetChange = [workingDir, change](const QByteArray &resetType) {
|
||||
GitPlugin::client()->reset(
|
||||
workingDir, QLatin1String("--" + resetType), change);
|
||||
};
|
||||
auto resetMenu = new QMenu(tr("&Reset to Change %1").arg(change), menu);
|
||||
resetMenu->addAction(tr("&Hard"), this, [this] { resetChange("hard"); });
|
||||
resetMenu->addAction(tr("&Mixed"), this, [this] { resetChange("mixed"); });
|
||||
resetMenu->addAction(tr("&Soft"), this, [this] { resetChange("soft"); });
|
||||
resetMenu->addAction(tr("&Hard"), std::bind(resetChange, "hard"));
|
||||
resetMenu->addAction(tr("&Mixed"), std::bind(resetChange, "mixed"));
|
||||
resetMenu->addAction(tr("&Soft"), std::bind(resetChange, "soft"));
|
||||
menu->addMenu(resetMenu);
|
||||
}
|
||||
|
||||
void GitEditorWidget::addChangeActions(QMenu *menu, const QString &change)
|
||||
{
|
||||
if (contentType() != OtherContent)
|
||||
addChangeActions(menu, change, sourceWorkingDirectory());
|
||||
}
|
||||
|
||||
QString GitEditorWidget::revisionSubject(const QTextBlock &inBlock) const
|
||||
{
|
||||
for (QTextBlock block = inBlock.next(); block.isValid(); block = block.next()) {
|
||||
|
@@ -58,7 +58,6 @@ private:
|
||||
void applyDiffChunk(const VcsBase::DiffChunk& chunk, bool revert);
|
||||
|
||||
void init() override;
|
||||
void resetChange(const QByteArray &resetType);
|
||||
void addDiffActions(QMenu *menu, const VcsBase::DiffChunk &chunk) override;
|
||||
void aboutToOpen(const QString &fileName, const QString &realFileName) override;
|
||||
QString changeUnderCursor(const QTextCursor &) const override;
|
||||
@@ -67,13 +66,13 @@ private:
|
||||
QStringList annotationPreviousVersions(const QString &revision) const override;
|
||||
bool isValidRevision(const QString &revision) const override;
|
||||
void addChangeActions(QMenu *menu, const QString &change) override;
|
||||
static void addChangeActions(QMenu *menu, const QString &workingDir, const QString &change);
|
||||
QString revisionSubject(const QTextBlock &inBlock) const override;
|
||||
bool supportChangeLinks() const override;
|
||||
QString fileNameForLine(int line) const override;
|
||||
QString sourceWorkingDirectory() const;
|
||||
|
||||
mutable QRegExp m_changeNumberPattern;
|
||||
QString m_currentChange;
|
||||
GitLogFilterWidget *m_logFilterWidget = nullptr;
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user