forked from qt-creator/qt-creator
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:
committed by
Orgad Shaneh
parent
7bfaf7a946
commit
5832945835
@@ -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());
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user