Commit b53d398e authored by Orgad Shaneh's avatar Orgad Shaneh Committed by Orgad Shaneh

Git: Add context-menu actions for cherry-pick and revert

Change-Id: Ic266fe039423a37df2fc347ead7530322ac47bb8
Reviewed-by: default avatarTobias Hunger <tobias.hunger@digia.com>
parent 5e5831bb
......@@ -199,6 +199,7 @@
display a description of the change including the diff.
Right-clicking on an identifier brings up a context menu that lets you
show annotation views of previous versions (see \l{Annotating Files}).
With Git you can also choose to cherry-pick or revert a change.
\image qtcreator-vcs-log.png
......
......@@ -219,6 +219,20 @@ void GitEditor::commandFinishedGotoLine(bool ok, int /* exitCode */, const QVari
}
}
void GitEditor::cherryPickChange()
{
const QFileInfo fi(source());
const QString workingDirectory = fi.isDir() ? fi.absoluteFilePath() : fi.absolutePath();
GitPlugin::instance()->gitClient()->cherryPickCommit(workingDirectory, m_currentChange);
}
void GitEditor::revertChange()
{
const QFileInfo fi(source());
const QString workingDirectory = fi.isDir() ? fi.absoluteFilePath() : fi.absolutePath();
GitPlugin::instance()->gitClient()->revertCommit(workingDirectory, m_currentChange);
}
QString GitEditor::decorateVersion(const QString &revision) const
{
const QFileInfo fi(source());
......@@ -249,6 +263,12 @@ bool GitEditor::isValidRevision(const QString &revision) const
return GitPlugin::instance()->gitClient()->isValidRevision(revision);
}
void GitEditor::addChangeActions(QMenu *menu, const QString &change)
{
m_currentChange = change;
menu->addAction(tr("Cherry-pick Change %1").arg(change), this, SLOT(cherryPickChange()));
menu->addAction(tr("Revert Change %1").arg(change), this, SLOT(revertChange()));
}
} // namespace Internal
} // namespace Git
......@@ -54,6 +54,10 @@ public slots:
// Matches the signature of the finished signal of GitCommand
void commandFinishedGotoLine(bool ok, int exitCode, const QVariant &v);
private slots:
void cherryPickChange();
void revertChange();
private:
QSet<QString> annotationChanges() const;
QString changeUnderCursor(const QTextCursor &) const;
......@@ -61,9 +65,11 @@ private:
QString decorateVersion(const QString &revision) const;
QStringList annotationPreviousVersions(const QString &revision) const;
bool isValidRevision(const QString &revision) const;
void addChangeActions(QMenu *menu, const QString &change);
mutable QRegExp m_changeNumberPattern8;
mutable QRegExp m_changeNumberPattern40;
QString m_currentChange;
};
} // namespace Git
......
......@@ -365,6 +365,7 @@ void ChangeTextCursorHandler::fillContextMenu(QMenu *menu, EditorContentType typ
default:
break;
}
widget->addChangeActions(menu, m_currentChange);
}
QString ChangeTextCursorHandler::currentContents() const
......@@ -1449,6 +1450,10 @@ QString VcsBaseEditorWidget::fileNameFromDiffSpecification(const QTextBlock &inB
return QString();
}
void VcsBaseEditorWidget::addChangeActions(QMenu *, const QString &)
{
}
QString VcsBaseEditorWidget::decorateVersion(const QString &revision) const
{
return revision;
......
......@@ -236,6 +236,9 @@ protected:
// Revert a patch chunk. Default implementation uses patch.exe
virtual bool applyDiffChunk(const DiffChunk &dc, bool revert = false) const;
virtual void addChangeActions(QMenu *menu, const QString &change);
private:
// Implement to return a set of change identifiers in
// annotation mode
virtual QSet<QString> annotationChanges() const = 0;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment