forked from qt-creator/qt-creator
Mercurial: Use TextEditor::SyntaxHighlighter
Change-Id: Ic215b778a6365d8bce5cb8eeb0d016d8ce80e476 Reviewed-by: Christian Stenger <christian.stenger@digia.com>
This commit is contained in:
committed by
Orgad Shaneh
parent
697f70cb33
commit
f0a6345fde
@@ -32,6 +32,7 @@
|
|||||||
|
|
||||||
#include <texteditor/texteditorsettings.h>
|
#include <texteditor/texteditorsettings.h>
|
||||||
#include <texteditor/fontsettings.h>
|
#include <texteditor/fontsettings.h>
|
||||||
|
#include <texteditor/syntaxhighlighter.h>
|
||||||
#include <texteditor/texteditorconstants.h>
|
#include <texteditor/texteditorconstants.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
@@ -43,21 +44,13 @@
|
|||||||
|
|
||||||
//see the git submit widget for details of the syntax Highlighter
|
//see the git submit widget for details of the syntax Highlighter
|
||||||
|
|
||||||
//TODO Check to see when the Highlighter has been moved to a base class and use that instead
|
|
||||||
|
|
||||||
namespace Mercurial {
|
namespace Mercurial {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
// Retrieve the comment char format from the text editor.
|
|
||||||
static QTextCharFormat commentFormat()
|
|
||||||
{
|
|
||||||
return TextEditor::TextEditorSettings::fontSettings().toTextCharFormat(TextEditor::C_COMMENT);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Highlighter for Mercurial submit messages. Make the first line bold, indicates
|
// Highlighter for Mercurial submit messages. Make the first line bold, indicates
|
||||||
// comments as such (retrieving the format from the text editor) and marks up
|
// comments as such (retrieving the format from the text editor) and marks up
|
||||||
// keywords (words in front of a colon as in 'Task: <bla>').
|
// keywords (words in front of a colon as in 'Task: <bla>').
|
||||||
class MercurialSubmitHighlighter : QSyntaxHighlighter
|
class MercurialSubmitHighlighter : TextEditor::SyntaxHighlighter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit MercurialSubmitHighlighter(QTextEdit *parent);
|
explicit MercurialSubmitHighlighter(QTextEdit *parent);
|
||||||
@@ -65,17 +58,21 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
enum State { Header, Comment, Other };
|
enum State { Header, Comment, Other };
|
||||||
const QTextCharFormat m_commentFormat;
|
enum Format { Format_Comment };
|
||||||
QRegExp m_keywordPattern;
|
QRegExp m_keywordPattern;
|
||||||
const QChar m_hashChar;
|
const QChar m_hashChar;
|
||||||
};
|
};
|
||||||
|
|
||||||
MercurialSubmitHighlighter::MercurialSubmitHighlighter(QTextEdit *parent) :
|
MercurialSubmitHighlighter::MercurialSubmitHighlighter(QTextEdit *parent) :
|
||||||
QSyntaxHighlighter(parent),
|
TextEditor::SyntaxHighlighter(parent),
|
||||||
m_commentFormat(commentFormat()),
|
|
||||||
m_keywordPattern(QLatin1String("^\\w+:")),
|
m_keywordPattern(QLatin1String("^\\w+:")),
|
||||||
m_hashChar(QLatin1Char('#'))
|
m_hashChar(QLatin1Char('#'))
|
||||||
{
|
{
|
||||||
|
static QVector<TextEditor::TextStyle> categories;
|
||||||
|
if (categories.isEmpty())
|
||||||
|
categories << TextEditor::C_COMMENT;
|
||||||
|
|
||||||
|
setTextFormatCategories(categories);
|
||||||
QTC_CHECK(m_keywordPattern.isValid());
|
QTC_CHECK(m_keywordPattern.isValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,13 +90,13 @@ void MercurialSubmitHighlighter::highlightBlock(const QString &text)
|
|||||||
// Apply format.
|
// Apply format.
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case Header: {
|
case Header: {
|
||||||
QTextCharFormat charFormat = format(0);
|
QTextCharFormat charFormat = format(0);
|
||||||
charFormat.setFontWeight(QFont::Bold);
|
charFormat.setFontWeight(QFont::Bold);
|
||||||
setFormat(0, text.size(), charFormat);
|
setFormat(0, text.size(), charFormat);
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case Comment:
|
case Comment:
|
||||||
setFormat(0, text.size(), m_commentFormat);
|
setFormat(0, text.size(), formatForCategory(Format_Comment));
|
||||||
break;
|
break;
|
||||||
case Other:
|
case Other:
|
||||||
// Format key words ("Task:") italic
|
// Format key words ("Task:") italic
|
||||||
|
|||||||
Reference in New Issue
Block a user