From 5832945835fbda5a343fa259fa169ac011ef8fb8 Mon Sep 17 00:00:00 2001 From: Orgad Shaneh Date: Mon, 20 May 2013 06:00:08 +0300 Subject: [PATCH] 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 --- src/plugins/git/gitsubmiteditorwidget.cpp | 35 ++++++++++------------- src/plugins/git/gitsubmiteditorwidget.h | 23 +++++++++++++++ 2 files changed, 38 insertions(+), 20 deletions(-) diff --git a/src/plugins/git/gitsubmiteditorwidget.cpp b/src/plugins/git/gitsubmiteditorwidget.cpp index ab7240fa3d6..4e2689ffdc0 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: '). - -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 62bc8eda734..3872786ebea 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 #include +#include +#include + 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: '). + +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