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);
|
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)
|
void GitEditorWidget::applyDiffChunk(const DiffChunk& chunk, bool revert)
|
||||||
{
|
{
|
||||||
Utils::TemporaryFile patchFile("git-apply-chunk");
|
Utils::TemporaryFile patchFile("git-apply-chunk");
|
||||||
@@ -314,32 +308,28 @@ bool GitEditorWidget::isValidRevision(const QString &revision) const
|
|||||||
return GitPlugin::client()->isValidRevision(revision);
|
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;
|
menu->addAction(tr("Cherr&y-Pick Change %1").arg(change), [workingDir, change] {
|
||||||
if (contentType() == OtherContent)
|
GitPlugin::client()->synchronousCherryPick(workingDir, change);
|
||||||
return;
|
|
||||||
|
|
||||||
menu->addAction(tr("Cherr&y-Pick Change %1").arg(change), this, [this] {
|
|
||||||
GitPlugin::client()->synchronousCherryPick(sourceWorkingDirectory(), m_currentChange);
|
|
||||||
});
|
});
|
||||||
menu->addAction(tr("Re&vert Change %1").arg(change), this, [this] {
|
menu->addAction(tr("Re&vert Change %1").arg(change), [workingDir, change] {
|
||||||
GitPlugin::client()->synchronousRevert(sourceWorkingDirectory(), m_currentChange);
|
GitPlugin::client()->synchronousRevert(workingDir, change);
|
||||||
});
|
});
|
||||||
menu->addAction(tr("C&heckout Change %1").arg(change), this, [this] {
|
menu->addAction(tr("C&heckout Change %1").arg(change), [workingDir, change] {
|
||||||
GitPlugin::client()->checkout(sourceWorkingDirectory(), m_currentChange);
|
GitPlugin::client()->checkout(workingDir, change);
|
||||||
});
|
});
|
||||||
connect(menu->addAction(tr("&Interactive Rebase from Change %1...").arg(change)),
|
connect(menu->addAction(tr("&Interactive Rebase from Change %1...").arg(change)),
|
||||||
&QAction::triggered, this, [this] {
|
&QAction::triggered, [workingDir, change] {
|
||||||
GitPlugin::startRebaseFromCommit(sourceWorkingDirectory(), m_currentChange);
|
GitPlugin::startRebaseFromCommit(workingDir, change);
|
||||||
});
|
});
|
||||||
menu->addAction(tr("&Log for Change %1").arg(change), this, [this] {
|
menu->addAction(tr("&Log for Change %1").arg(change), [workingDir, change] {
|
||||||
GitPlugin::client()->log(sourceWorkingDirectory(), QString(), false, {m_currentChange});
|
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 output;
|
||||||
QString errorMessage;
|
QString errorMessage;
|
||||||
GitPlugin::client()->synchronousTagCmd(sourceWorkingDirectory(), QStringList(),
|
GitPlugin::client()->synchronousTagCmd(workingDir, QStringList(),
|
||||||
&output, &errorMessage);
|
&output, &errorMessage);
|
||||||
|
|
||||||
const QStringList tags = output.split('\n');
|
const QStringList tags = output.split('\n');
|
||||||
@@ -348,21 +338,31 @@ void GitEditorWidget::addChangeActions(QMenu *menu, const QString &change)
|
|||||||
if (dialog.exec() == QDialog::Rejected)
|
if (dialog.exec() == QDialog::Rejected)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
GitPlugin::client()->synchronousTagCmd(sourceWorkingDirectory(),
|
GitPlugin::client()->synchronousTagCmd(workingDir,
|
||||||
{dialog.branchName(), m_currentChange},
|
{dialog.branchName(), change},
|
||||||
&output, &errorMessage);
|
&output, &errorMessage);
|
||||||
VcsOutputWindow::append(output);
|
VcsOutputWindow::append(output);
|
||||||
if (!errorMessage.isEmpty())
|
if (!errorMessage.isEmpty())
|
||||||
VcsOutputWindow::append(errorMessage, VcsOutputWindow::MessageStyle::Error);
|
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);
|
auto resetMenu = new QMenu(tr("&Reset to Change %1").arg(change), menu);
|
||||||
resetMenu->addAction(tr("&Hard"), this, [this] { resetChange("hard"); });
|
resetMenu->addAction(tr("&Hard"), std::bind(resetChange, "hard"));
|
||||||
resetMenu->addAction(tr("&Mixed"), this, [this] { resetChange("mixed"); });
|
resetMenu->addAction(tr("&Mixed"), std::bind(resetChange, "mixed"));
|
||||||
resetMenu->addAction(tr("&Soft"), this, [this] { resetChange("soft"); });
|
resetMenu->addAction(tr("&Soft"), std::bind(resetChange, "soft"));
|
||||||
menu->addMenu(resetMenu);
|
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
|
QString GitEditorWidget::revisionSubject(const QTextBlock &inBlock) const
|
||||||
{
|
{
|
||||||
for (QTextBlock block = inBlock.next(); block.isValid(); block = block.next()) {
|
for (QTextBlock block = inBlock.next(); block.isValid(); block = block.next()) {
|
||||||
|
@@ -58,7 +58,6 @@ private:
|
|||||||
void applyDiffChunk(const VcsBase::DiffChunk& chunk, bool revert);
|
void applyDiffChunk(const VcsBase::DiffChunk& chunk, bool revert);
|
||||||
|
|
||||||
void init() override;
|
void init() override;
|
||||||
void resetChange(const QByteArray &resetType);
|
|
||||||
void addDiffActions(QMenu *menu, const VcsBase::DiffChunk &chunk) override;
|
void addDiffActions(QMenu *menu, const VcsBase::DiffChunk &chunk) override;
|
||||||
void aboutToOpen(const QString &fileName, const QString &realFileName) override;
|
void aboutToOpen(const QString &fileName, const QString &realFileName) override;
|
||||||
QString changeUnderCursor(const QTextCursor &) const override;
|
QString changeUnderCursor(const QTextCursor &) const override;
|
||||||
@@ -67,13 +66,13 @@ private:
|
|||||||
QStringList annotationPreviousVersions(const QString &revision) const override;
|
QStringList annotationPreviousVersions(const QString &revision) const override;
|
||||||
bool isValidRevision(const QString &revision) const override;
|
bool isValidRevision(const QString &revision) const override;
|
||||||
void addChangeActions(QMenu *menu, const QString &change) 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;
|
QString revisionSubject(const QTextBlock &inBlock) const override;
|
||||||
bool supportChangeLinks() const override;
|
bool supportChangeLinks() const override;
|
||||||
QString fileNameForLine(int line) const override;
|
QString fileNameForLine(int line) const override;
|
||||||
QString sourceWorkingDirectory() const;
|
QString sourceWorkingDirectory() const;
|
||||||
|
|
||||||
mutable QRegExp m_changeNumberPattern;
|
mutable QRegExp m_changeNumberPattern;
|
||||||
QString m_currentChange;
|
|
||||||
GitLogFilterWidget *m_logFilterWidget = nullptr;
|
GitLogFilterWidget *m_logFilterWidget = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user