summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOrgad Shaneh <orgad.shaneh@audiocodes.com>2013-01-23 17:06:43 +0200
committerOrgad Shaneh <orgads@gmail.com>2013-01-23 18:50:45 +0100
commitb53d398e2c15c1c31d9a3ca0104c936257466f2e (patch)
tree34367e1fe3e8f5d1e70babe6adefe0f2e00a24b4
parent5e5831bb12d583c68a203fb36e3f50add979c7e7 (diff)
downloadqt-creator-b53d398e2c15c1c31d9a3ca0104c936257466f2e.tar.gz
Git: Add context-menu actions for cherry-pick and revert
Change-Id: Ic266fe039423a37df2fc347ead7530322ac47bb8 Reviewed-by: Tobias Hunger <tobias.hunger@digia.com>
-rw-r--r--doc/src/howto/creator-vcs.qdoc1
-rw-r--r--src/plugins/git/giteditor.cpp22
-rw-r--r--src/plugins/git/giteditor.h6
-rw-r--r--src/plugins/vcsbase/vcsbaseeditor.cpp5
-rw-r--r--src/plugins/vcsbase/vcsbaseeditor.h3
5 files changed, 36 insertions, 1 deletions
diff --git a/doc/src/howto/creator-vcs.qdoc b/doc/src/howto/creator-vcs.qdoc
index f045ae67e2..edea52b557 100644
--- a/doc/src/howto/creator-vcs.qdoc
+++ b/doc/src/howto/creator-vcs.qdoc
@@ -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
diff --git a/src/plugins/git/giteditor.cpp b/src/plugins/git/giteditor.cpp
index 69e0b52cb1..d9413d550e 100644
--- a/src/plugins/git/giteditor.cpp
+++ b/src/plugins/git/giteditor.cpp
@@ -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
-
diff --git a/src/plugins/git/giteditor.h b/src/plugins/git/giteditor.h
index 6b55f0b3ef..f51e15e41a 100644
--- a/src/plugins/git/giteditor.h
+++ b/src/plugins/git/giteditor.h
@@ -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
diff --git a/src/plugins/vcsbase/vcsbaseeditor.cpp b/src/plugins/vcsbase/vcsbaseeditor.cpp
index a4751bc6ba..38b74cc590 100644
--- a/src/plugins/vcsbase/vcsbaseeditor.cpp
+++ b/src/plugins/vcsbase/vcsbaseeditor.cpp
@@ -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;
diff --git a/src/plugins/vcsbase/vcsbaseeditor.h b/src/plugins/vcsbase/vcsbaseeditor.h
index ff87092389..1b2ad08fe8 100644
--- a/src/plugins/vcsbase/vcsbaseeditor.h
+++ b/src/plugins/vcsbase/vcsbaseeditor.h
@@ -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;