aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--share/qtcreator/generic-highlighter/git-rebase.xml65
-rw-r--r--src/plugins/git/Git.mimetypes.xml5
-rw-r--r--src/plugins/git/gitconstants.h3
-rw-r--r--src/plugins/git/giteditor.cpp12
-rw-r--r--src/plugins/git/githighlighters.cpp56
-rw-r--r--src/plugins/git/githighlighters.h29
-rw-r--r--src/plugins/git/gitplugin.cpp5
7 files changed, 107 insertions, 68 deletions
diff --git a/share/qtcreator/generic-highlighter/git-rebase.xml b/share/qtcreator/generic-highlighter/git-rebase.xml
deleted file mode 100644
index f86667fb9f..0000000000
--- a/share/qtcreator/generic-highlighter/git-rebase.xml
+++ /dev/null
@@ -1,65 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE language SYSTEM "language.dtd">
-<language name="Git Rebase" version="1.00" kateversion="2.4" section="Other" extensions="git-rebase-todo" license="LGPL" mimetype="text/vnd.git.rebase" author="Orgad Shaneh (orgads@gmail.com)">
- <highlighting>
- <list name="pick">
- <item>p</item>
- <item>pick</item>
- </list>
- <list name="reword">
- <item>r</item>
- <item>reword</item>
- </list>
- <list name="edit">
- <item>e</item>
- <item>edit</item>
- </list>
- <list name="squash">
- <item>s</item>
- <item>squash</item>
- </list>
- <list name="fixup">
- <item>f</item>
- <item>fixup</item>
- </list>
- <list name="exec">
- <item>x</item>
- <item>exec</item>
- </list>
- <contexts>
- <context attribute="Normal Text" lineEndContext="#pop" name="Normal">
- <DetectChar char="#" attribute="Comment" context="Comment" column="0"/>
- <keyword attribute="Pick" context="Commit" String="pick" />
- <keyword attribute="Reword" context="Commit" String="reword" />
- <keyword attribute="Edit" context="Commit" String="edit" />
- <keyword attribute="Squash" context="Commit" String="squash" />
- <keyword attribute="Fixup" context="Commit" String="fixup" />
- <keyword attribute="Exec" context="Commit" String="exec" />
- </context>
- <context attribute="Commit" lineEndContext="#pop" name="Commit">
- <RegExpr attribute="Commit" context="Summary" String="[0-9a-f]{7,40}" />
- </context>
- <context attribute="Summary" lineEndContext="#pop" name="Summary" />
- <context attribute="Comment" lineEndContext="#pop" name="Comment">
- <RegExpr attribute="Commit" context="#stay" String="[0-9a-f]{7,40}" />
- </context>
- </contexts>
- <itemDatas>
- <itemData name="Normal Text" defStyleNum="dsNormal"/>
- <itemData name="Pick" defStyleNum="dsKeyword"/>
- <itemData name="Reword" defStyleNum="dsDecVal"/>
- <itemData name="Edit" defStyleNum="dsDataType"/>
- <itemData name="Squash" defStyleNum="dsChar"/>
- <itemData name="Fixup" defStyleNum="dsBaseN"/>
- <itemData name="Exec" defStyleNum="dsOthers"/>
- <itemData name="Commit" defStyleNum="dsFunction"/>
- <itemData name="Summary" defStyleNum="dsString"/>
- <itemData name="Comment" defStyleNum="dsComment"/>
- </itemDatas>
- </highlighting>
- <general>
- <comments>
- <comment name="singleLine" start="#"/>
- </comments>
- </general>
-</language>
diff --git a/src/plugins/git/Git.mimetypes.xml b/src/plugins/git/Git.mimetypes.xml
index c40c30181a..ae51ec2e9b 100644
--- a/src/plugins/git/Git.mimetypes.xml
+++ b/src/plugins/git/Git.mimetypes.xml
@@ -6,4 +6,9 @@
<glob pattern="COMMIT_MSG"/>
<glob pattern="COMMIT_EDITMSG"/>
</mime-type>
+ <mime-type type="text/vnd.qtcreator.git.rebase">
+ <sub-class-of type="text/plain"/>
+ <comment>Git Commit File</comment>
+ <glob pattern="git-rebase-todo"/>
+ </mime-type>
</mime-info>
diff --git a/src/plugins/git/gitconstants.h b/src/plugins/git/gitconstants.h
index 35cf961956..ca311cb5f1 100644
--- a/src/plugins/git/gitconstants.h
+++ b/src/plugins/git/gitconstants.h
@@ -50,6 +50,9 @@ const char C_GIT_DIFF_EDITOR[] = "Git Diff Editor";
const char GIT_COMMIT_TEXT_EDITOR_ID[] = "Git Commit Editor";
const char GIT_COMMIT_TEXT_EDITOR_DISPLAY_NAME[] = QT_TRANSLATE_NOOP("VCS", "Git Commit Editor");
const char C_GIT_COMMIT_TEXT_EDITOR[] = "Git Commit Editor";
+const char GIT_REBASE_EDITOR_ID[] = "Git Rebase Editor";
+const char GIT_REBASE_EDITOR_DISPLAY_NAME[] = QT_TRANSLATE_NOOP("VCS", "Git Rebase Editor");
+const char C_GIT_REBASE_EDITOR[] = "Git Rebase Editor";
const char C_GITSUBMITEDITOR[] = "Git Submit Editor";
const char GITSUBMITEDITOR_ID[] = "Git Submit Editor";
diff --git a/src/plugins/git/giteditor.cpp b/src/plugins/git/giteditor.cpp
index dcec98434b..165b1e7998 100644
--- a/src/plugins/git/giteditor.cpp
+++ b/src/plugins/git/giteditor.cpp
@@ -232,14 +232,19 @@ void GitEditor::revertChange()
void GitEditor::init()
{
VcsBase::VcsBaseEditorWidget::init();
- if (editor()->id() == Git::Constants::GIT_COMMIT_TEXT_EDITOR_ID)
+ Core::Id editorId = editor()->id();
+ if (editorId == Git::Constants::GIT_COMMIT_TEXT_EDITOR_ID)
new GitSubmitHighlighter(baseTextDocument().data());
+ else if (editorId == Git::Constants::GIT_REBASE_EDITOR_ID)
+ new GitRebaseHighlighter(baseTextDocument().data());
}
bool GitEditor::open(QString *errorString, const QString &fileName, const QString &realFileName)
{
bool res = VcsBaseEditorWidget::open(errorString, fileName, realFileName);
- if (editor()->id() == Git::Constants::GIT_COMMIT_TEXT_EDITOR_ID) {
+ Core::Id editorId = editor()->id();
+ if (editorId == Git::Constants::GIT_COMMIT_TEXT_EDITOR_ID
+ || editorId == Git::Constants::GIT_REBASE_EDITOR_ID) {
QFileInfo fi(fileName);
setSource(GitPlugin::instance()->gitClient()->findRepositoryForGitDir(fi.absolutePath()));
}
@@ -298,7 +303,8 @@ QString GitEditor::revisionSubject(const QTextBlock &inBlock) const
bool GitEditor::supportChangeLinks() const
{
return VcsBaseEditorWidget::supportChangeLinks()
- || (editor()->id() == Git::Constants::GIT_COMMIT_TEXT_EDITOR_ID);
+ || (editor()->id() == Git::Constants::GIT_COMMIT_TEXT_EDITOR_ID)
+ || (editor()->id() == Git::Constants::GIT_REBASE_EDITOR_ID);
}
} // namespace Internal
diff --git a/src/plugins/git/githighlighters.cpp b/src/plugins/git/githighlighters.cpp
index d223a5e524..2f00c9f2db 100644
--- a/src/plugins/git/githighlighters.cpp
+++ b/src/plugins/git/githighlighters.cpp
@@ -38,6 +38,8 @@
namespace Git {
namespace Internal {
+static const char CHANGE_PATTERN[] = "\\b[a-f0-9]{7,40}\\b";
+
// Retrieve the comment char format from the text editor.
static QTextCharFormat commentFormat()
{
@@ -104,5 +106,59 @@ void GitSubmitHighlighter::highlightBlock(const QString &text)
}
}
+GitRebaseHighlighter::RebaseAction::RebaseAction(const QString &regexp,
+ const TextEditor::FontSettings &settings,
+ TextEditor::TextStyle category)
+ : exp(regexp)
+{
+ format = settings.toTextCharFormat(category);
+}
+
+GitRebaseHighlighter::GitRebaseHighlighter(TextEditor::BaseTextDocument *parent) :
+ TextEditor::SyntaxHighlighter(parent),
+ m_hashChar(QLatin1Char('#')),
+ m_changeNumberPattern(QLatin1String(CHANGE_PATTERN))
+{
+ const TextEditor::FontSettings settings = TextEditor::TextEditorSettings::instance()->fontSettings();
+ m_commentFormat = settings.toTextCharFormat(TextEditor::C_COMMENT);
+ m_changeFormat = settings.toTextCharFormat(TextEditor::C_DOXYGEN_COMMENT);
+ m_descFormat = settings.toTextCharFormat(TextEditor::C_STRING);
+ m_actions << RebaseAction(QLatin1String("^(p|pick)\\b"), settings, TextEditor::C_KEYWORD);
+ m_actions << RebaseAction(QLatin1String("^(r|reword)\\b"), settings, TextEditor::C_FIELD);
+ m_actions << RebaseAction(QLatin1String("^(e|edit)\\b"), settings, TextEditor::C_TYPE);
+ m_actions << RebaseAction(QLatin1String("^(s|squash)\\b"), settings, TextEditor::C_ENUMERATION);
+ m_actions << RebaseAction(QLatin1String("^(f|fixup)\\b"), settings, TextEditor::C_NUMBER);
+ m_actions << RebaseAction(QLatin1String("^(x|exec)\\b"), settings, TextEditor::C_LABEL);
+}
+
+void GitRebaseHighlighter::highlightBlock(const QString &text)
+{
+ if (text.startsWith(m_hashChar)) {
+ setFormat(0, text.size(), m_commentFormat);
+ int changeIndex = 0;
+ while ((changeIndex = m_changeNumberPattern.indexIn(text, changeIndex)) != -1) {
+ const int changeLen = m_changeNumberPattern.matchedLength();
+ setFormat(changeIndex, changeLen, m_changeFormat);
+ changeIndex += changeLen;
+ }
+ return;
+ }
+
+ foreach (const RebaseAction &action, m_actions) {
+ if (action.exp.indexIn(text) != -1) {
+ const int len = action.exp.matchedLength();
+ setFormat(0, len, action.format);
+ const int changeIndex = m_changeNumberPattern.indexIn(text, len);
+ if (changeIndex != -1) {
+ const int changeLen = m_changeNumberPattern.matchedLength();
+ const int descStart = changeIndex + changeLen + 1;
+ setFormat(changeIndex, changeLen, m_changeFormat);
+ setFormat(descStart, text.size() - descStart, m_descFormat);
+ }
+ break;
+ }
+ }
+}
+
} // namespace Internal
} // namespace Git
diff --git a/src/plugins/git/githighlighters.h b/src/plugins/git/githighlighters.h
index 98a7f13fcb..3d7f6e0621 100644
--- a/src/plugins/git/githighlighters.h
+++ b/src/plugins/git/githighlighters.h
@@ -33,6 +33,10 @@
#include <texteditor/syntaxhighlighter.h>
#include <texteditor/texteditorconstants.h>
+namespace TextEditor {
+class FontSettings;
+}
+
namespace Git {
namespace Internal {
@@ -54,6 +58,31 @@ private:
QChar m_hashChar;
};
+// Highlighter for interactive rebase todo. Indicates comments as such
+// (retrieving the format from the text editor) and marks up keywords
+class GitRebaseHighlighter : public TextEditor::SyntaxHighlighter
+{
+public:
+ explicit GitRebaseHighlighter(TextEditor::BaseTextDocument *parent);
+ void highlightBlock(const QString &text);
+
+private:
+ class RebaseAction
+ {
+ public:
+ mutable QRegExp exp;
+ QTextCharFormat format;
+ RebaseAction(const QString &regexp, const TextEditor::FontSettings &settings,
+ TextEditor::TextStyle category);
+ };
+ QTextCharFormat m_commentFormat;
+ QTextCharFormat m_changeFormat;
+ QTextCharFormat m_descFormat;
+ const QChar m_hashChar;
+ QRegExp m_changeNumberPattern;
+ QList<RebaseAction> m_actions;
+};
+
} // namespace Internal
} // namespace Git
diff --git a/src/plugins/git/gitplugin.cpp b/src/plugins/git/gitplugin.cpp
index 8b3774793a..215e9e67d1 100644
--- a/src/plugins/git/gitplugin.cpp
+++ b/src/plugins/git/gitplugin.cpp
@@ -111,6 +111,11 @@ static const VcsBase::VcsBaseEditorParameters editorParameters[] = {
Git::Constants::GIT_COMMIT_TEXT_EDITOR_DISPLAY_NAME,
Git::Constants::C_GIT_COMMIT_TEXT_EDITOR,
"text/vnd.qtcreator.git.commit"},
+{ VcsBase::OtherContent,
+ Git::Constants::GIT_REBASE_EDITOR_ID,
+ Git::Constants::GIT_REBASE_EDITOR_DISPLAY_NAME,
+ Git::Constants::C_GIT_REBASE_EDITOR,
+ "text/vnd.qtcreator.git.rebase"},
};
// Utility to find a parameter set by type