diff --git a/src/plugins/git/gitsubmiteditorwidget.cpp b/src/plugins/git/gitsubmiteditorwidget.cpp index ab7240fa3d65b939c948cc398af0df7361982e16..4e2689ffdc01d4599126132d51716c275ff45fd2 100644 --- a/src/plugins/git/gitsubmiteditorwidget.cpp +++ b/src/plugins/git/gitsubmiteditorwidget.cpp @@ -55,28 +55,23 @@ static QTextCharFormat commentFormat() return settings.toTextCharFormat(TextEditor::C_COMMENT); } -// 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 : QSyntaxHighlighter { -public: - explicit GitSubmitHighlighter(QTextEdit *parent); - void highlightBlock(const QString &text); - -private: - enum State { None = -1, Header, Other }; - const QTextCharFormat m_commentFormat; - QRegExp m_keywordPattern; - const QChar m_hashChar; -}; - GitSubmitHighlighter::GitSubmitHighlighter(QTextEdit * parent) : - QSyntaxHighlighter(parent), - m_commentFormat(commentFormat()), - m_keywordPattern(QLatin1String("^[\\w-]+:")), - m_hashChar(QLatin1Char('#')) + TextEditor::SyntaxHighlighter(parent) +{ + initialize(); +} + +GitSubmitHighlighter::GitSubmitHighlighter(TextEditor::BaseTextDocument *parent) : + TextEditor::SyntaxHighlighter(parent) +{ + initialize(); +} + +void GitSubmitHighlighter::initialize() { + m_commentFormat = commentFormat(); + m_keywordPattern.setPattern(QLatin1String("^[\\w-]+:")); + m_hashChar = QLatin1Char('#'); QTC_CHECK(m_keywordPattern.isValid()); } diff --git a/src/plugins/git/gitsubmiteditorwidget.h b/src/plugins/git/gitsubmiteditorwidget.h index 62bc8eda734362bba1c0bf258e537dfe97037b17..3872786ebea270e05be677fadd36ce5eb3be0ae0 100644 --- a/src/plugins/git/gitsubmiteditorwidget.h +++ b/src/plugins/git/gitsubmiteditorwidget.h @@ -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