diff options
author | Orgad Shaneh <orgad.shaneh@audiocodes.com> | 2020-02-25 18:36:05 +0200 |
---|---|---|
committer | Orgad Shaneh <orgads@gmail.com> | 2020-02-26 10:28:34 +0000 |
commit | 5765bd8507b1e76ef61176435ce357962fb9b291 (patch) | |
tree | 567ad149d422fb5b1501bcfe2bd9e5590bc4f78e /src/plugins/git | |
parent | 4422805cec9e6568f060a7379805b9544b537730 (diff) |
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>
Diffstat (limited to 'src/plugins/git')
-rw-r--r-- | src/plugins/git/giteditor.cpp | 56 | ||||
-rw-r--r-- | src/plugins/git/giteditor.h | 3 |
2 files changed, 29 insertions, 30 deletions
diff --git a/src/plugins/git/giteditor.cpp b/src/plugins/git/giteditor.cpp index 47546d0df6..ac5735af20 100644 --- a/src/plugins/git/giteditor.cpp +++ b/src/plugins/git/giteditor.cpp @@ -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()) { diff --git a/src/plugins/git/giteditor.h b/src/plugins/git/giteditor.h index 18397d9497..b2eab5de72 100644 --- a/src/plugins/git/giteditor.h +++ b/src/plugins/git/giteditor.h @@ -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; }; |