Git: Move GitSubmitHighlighter to header

And change it to derive TextEditor::SyntaxHighlighter

Required for reusing for a BaseTextDocument

Change-Id: I034b76e03e447bcc47f11833367f7bba9cc031c1
Reviewed-by: Tobias Hunger <tobias.hunger@digia.com>
This commit is contained in:
Orgad Shaneh
2013-05-20 06:00:08 +03:00
committed by Orgad Shaneh
parent 7bfaf7a946
commit 5832945835
2 changed files with 38 additions and 20 deletions

View File

@@ -33,8 +33,12 @@
#include "ui_gitsubmitpanel.h"
#include "gitsettings.h"
#include <texteditor/syntaxhighlighter.h>
#include <vcsbase/submiteditorwidget.h>
#include <QRegExp>
#include <QSyntaxHighlighter>
QT_BEGIN_NAMESPACE
class QValidator;
QT_END_NAMESPACE
@@ -89,6 +93,25 @@ private:
bool m_isInitialized;
};
// Highlighter for git submit messages. Make the first line bold, indicates
// comments as such (retrieving the format from the text editor) and marks up
// keywords (words in front of a colon as in 'Task: <bla>').
class GitSubmitHighlighter : public TextEditor::SyntaxHighlighter
{
public:
explicit GitSubmitHighlighter(QTextEdit *parent);
explicit GitSubmitHighlighter(TextEditor::BaseTextDocument *parent);
void highlightBlock(const QString &text);
void initialize();
private:
enum State { None = -1, Header, Other };
QTextCharFormat m_commentFormat;
QRegExp m_keywordPattern;
QChar m_hashChar;
};
} // namespace Internal
} // namespace Git