diff --git a/src/plugins/genericeditor/XML/java.xml b/src/plugins/genericeditor/XML/java.xml
index c7f0f396732..a5e30dcbb6e 100644
--- a/src/plugins/genericeditor/XML/java.xml
+++ b/src/plugins/genericeditor/XML/java.xml
@@ -3838,8 +3838,8 @@
-
-
+
+
diff --git a/src/plugins/genericeditor/editor.cpp b/src/plugins/genericeditor/editor.cpp
index 1d50eb1ec3d..3a19588a5f0 100644
--- a/src/plugins/genericeditor/editor.cpp
+++ b/src/plugins/genericeditor/editor.cpp
@@ -39,6 +39,8 @@
#include
#include
#include
+#include
+#include
#include
#include
@@ -64,6 +66,18 @@ TextEditor::BaseTextEditorEditable *Editor::createEditableInterface()
return editable;
}
+void Editor::setFontSettings(const TextEditor::FontSettings & fs)
+{
+ TextEditor::BaseTextEditor::setFontSettings(fs);
+
+ Highlighter *highlighter = static_cast(baseTextDocument()->syntaxHighlighter());
+ if (!highlighter)
+ return;
+
+ highlighter->configureFormats(fs);
+ highlighter->rehighlight();
+}
+
void Editor::configure()
{
const QString &mimeType = Core::ICore::instance()->mimeDatabase()->findByFile(
@@ -76,7 +90,10 @@ void Editor::configure()
QSharedPointer definition =
GenericEditorPlugin::instance()->definition(definitionId);
- baseTextDocument()->setSyntaxHighlighter(new Highlighter(definition->initialContext()));
+ Highlighter *highlighter = new Highlighter(definition->initialContext());
+ highlighter->configureFormats(TextEditor::TextEditorSettings::instance()->fontSettings());
+
+ baseTextDocument()->setSyntaxHighlighter(highlighter);
m_commentDefinition.setAfterWhiteSpaces(definition->isCommentAfterWhiteSpaces());
m_commentDefinition.setSingleLine(definition->singleLineComment());
diff --git a/src/plugins/genericeditor/editor.h b/src/plugins/genericeditor/editor.h
index b8bd9aa6d24..a1317aca956 100644
--- a/src/plugins/genericeditor/editor.h
+++ b/src/plugins/genericeditor/editor.h
@@ -53,6 +53,9 @@ public:
protected:
virtual TextEditor::BaseTextEditorEditable *createEditableInterface();
+public slots:
+ virtual void setFontSettings(const TextEditor::FontSettings &);
+
private slots:
void configure();
diff --git a/src/plugins/genericeditor/genericeditorplugin.cpp b/src/plugins/genericeditor/genericeditorplugin.cpp
index 2b5e0c3eb0b..eea12541a45 100644
--- a/src/plugins/genericeditor/genericeditorplugin.cpp
+++ b/src/plugins/genericeditor/genericeditorplugin.cpp
@@ -38,6 +38,7 @@
#include
#include
+#include
#include
#include
@@ -142,6 +143,7 @@ bool GenericEditorPlugin::initialize(const QStringList &arguments, QString *erro
m_actionHandler = new TextEditor::TextEditorActionHandler(
GenericEditor::Constants::GENERIC_EDITOR,
+ TextEditor::TextEditorActionHandler::Format |
TextEditor::TextEditorActionHandler::UnCommentSelection);
m_actionHandler->initializeActions();
@@ -154,6 +156,8 @@ void GenericEditorPlugin::extensionsInitialized()
void GenericEditorPlugin::initializeEditor(Editor *editor)
{
m_actionHandler->setupActions(editor);
+
+ TextEditor::TextEditorSettings::instance()->initializeEditor(editor);
}
QString GenericEditorPlugin::definitionIdByName(const QString &name) const
diff --git a/src/plugins/genericeditor/highlightdefinitionhandler.cpp b/src/plugins/genericeditor/highlightdefinitionhandler.cpp
index ff4717474ec..85313b528c6 100644
--- a/src/plugins/genericeditor/highlightdefinitionhandler.cpp
+++ b/src/plugins/genericeditor/highlightdefinitionhandler.cpp
@@ -275,7 +275,6 @@ void HighlightDefinitionHandler::itemDataElementStarted(const QXmlAttributes &at
itemData->setBold(atts.value(kBold));
itemData->setUnderlined(atts.value(kUnderline));
itemData->setStrikedOut(atts.value(kStrikeout));
- itemData->configureFormat();
}
void HighlightDefinitionHandler::commentElementStarted(const QXmlAttributes &atts) const
@@ -434,8 +433,8 @@ void HighlightDefinitionHandler::processIncludeRules(const QSharedPointer
+#include
+#include
+
+#include
+#include
using namespace GenericEditor;
using namespace Internal;
@@ -91,11 +96,13 @@ void Highlighter::highlightBlock(const QString &text)
handleContextChange(m_currentContext->lineEndContext(), m_currentContext->definition(),
false);
-
- m_contexts.clear();
} catch (const HighlighterException &) {
m_isBroken = true;
+ return;
}
+
+ m_contexts.clear();
+ applyVisualWhitespaceFormat(text);
}
void Highlighter::setupDataForBlock(const QString &text)
@@ -283,18 +290,53 @@ void Highlighter::handleContextChange(const QString &contextName,
void Highlighter::applyFormat(int offset,
int count,
- const QString &itemData,
+ const QString &itemDataName,
const QSharedPointer &definition)
{
if (count == 0)
return;
+ QSharedPointer itemData;
try {
- setFormat(offset, count, definition->itemData(itemData)->format());
+ itemData = definition->itemData(itemDataName);
} catch (const HighlighterException &) {
- // This case does not break the highlighter. In fact, currently there are broken xml
- // definition files which Kate can cope with. For instance, the Printf context in java.xml
- // points to an inexistent Printf item data.
+ // Although the formatting is skipped this case does not break the highlighter. In fact,
+ // currently there are broken xml definition files which Kate can cope with. For instance,
+ // the Printf context in java.xml points to an inexistent Printf item data.
+ return;
+ }
+
+ QTextCharFormat format = m_genericFormats.value(itemData->style());
+
+ // Apply personalizations (if specified) for this particular item data from the current
+ // definition only.
+ if (itemData->color().isValid())
+ format.setForeground(itemData->color());
+ if (itemData->isItalicSpecified())
+ format.setFontItalic(itemData->isItalic());
+ if (itemData->isBoldSpecified())
+ format.setFontWeight(toFontWeight(itemData->isBold()));
+ if (itemData->isUnderlinedSpecified())
+ format.setFontUnderline(itemData->isUnderlined());
+ if (itemData->isStrikedOutSpecified())
+ format.setFontStrikeOut(itemData->isStrikedOut());
+
+ setFormat(offset, count, format);
+}
+
+void Highlighter::applyVisualWhitespaceFormat(const QString &text)
+{
+ int offset = 0;
+ const int length = text.length();
+ while (offset < length) {
+ if (text.at(offset).isSpace()) {
+ int start = offset++;
+ while (offset < length && text.at(offset).isSpace())
+ ++offset;
+ setFormat(start, offset - start, m_visualWhitespaceFormat);
+ } else {
+ ++offset;
+ }
}
}
@@ -384,3 +426,42 @@ void Highlighter::setCurrentContext()
throw HighlighterException();
m_currentContext = m_contexts.back();
}
+
+void Highlighter::configureFormats(const TextEditor::FontSettings & fs)
+{
+ m_visualWhitespaceFormat = fs.toTextCharFormat(
+ QLatin1String(TextEditor::Constants::C_VISUAL_WHITESPACE));
+
+ m_genericFormats[ItemData::kDsNormal] = fs.toTextCharFormat(
+ QLatin1String(TextEditor::Constants::C_TEXT));
+ m_genericFormats[ItemData::kDsKeyword] = fs.toTextCharFormat(
+ QLatin1String(TextEditor::Constants::C_KEYWORD));
+ m_genericFormats[ItemData::kDsDataType] = fs.toTextCharFormat(
+ QLatin1String(TextEditor::Constants::C_TYPE));
+ m_genericFormats[ItemData::kDsDecVal] = fs.toTextCharFormat(
+ QLatin1String(TextEditor::Constants::C_NUMBER));
+ m_genericFormats[ItemData::kDsBaseN] = fs.toTextCharFormat(
+ QLatin1String(TextEditor::Constants::C_NUMBER));
+ m_genericFormats[ItemData::kDsFloat] = fs.toTextCharFormat(
+ QLatin1String(TextEditor::Constants::C_NUMBER));
+ m_genericFormats[ItemData::kDsChar] = fs.toTextCharFormat(
+ QLatin1String(TextEditor::Constants::C_STRING));
+ m_genericFormats[ItemData::kDsString] = fs.toTextCharFormat(
+ QLatin1String(TextEditor::Constants::C_STRING));
+ m_genericFormats[ItemData::kDsComment] = fs.toTextCharFormat(
+ QLatin1String(TextEditor::Constants::C_COMMENT));
+
+ // Currently Creator does not have corresponding formats for the following items. We can
+ // implement them... Just for now I will leave hardcoded colors.
+ QTextCharFormat format;
+ format.setForeground(Qt::blue);
+ m_genericFormats[ItemData::kDsOthers] = format;
+ format.setForeground(Qt::red);
+ m_genericFormats[ItemData::kDsAlert] = format;
+ format.setForeground(Qt::darkBlue);
+ m_genericFormats[ItemData::kDsFunction] = format;
+ format.setForeground(Qt::darkGray);
+ m_genericFormats[ItemData::kDsRegionMarker] = format;
+ format.setForeground(Qt::darkRed);
+ m_genericFormats[ItemData::kDsError] = format;
+}
diff --git a/src/plugins/genericeditor/highlighter.h b/src/plugins/genericeditor/highlighter.h
index 0bc43526c90..e52bf8e0554 100644
--- a/src/plugins/genericeditor/highlighter.h
+++ b/src/plugins/genericeditor/highlighter.h
@@ -30,6 +30,7 @@
#ifndef HIGHLIGHTER_H
#define HIGHLIGHTER_H
+#include
#include
#include
#include
@@ -39,6 +40,10 @@
#include
+namespace TextEditor {
+class FontSettings;
+}
+
namespace GenericEditor {
namespace Internal {
@@ -53,6 +58,8 @@ public:
Highlighter(const QSharedPointer &defaultContext, QTextDocument *parent = 0);
virtual ~Highlighter();
+ void configureFormats(const TextEditor::FontSettings & fs);
+
protected:
virtual void highlightBlock(const QString &text);
@@ -80,8 +87,9 @@ private:
void applyFormat(int offset,
int count,
- const QString &itemData,
+ const QString &itemDataName,
const QSharedPointer &definition);
+ void applyVisualWhitespaceFormat(const QString &text);
QString currentContextSequence() const;
void mapContextSequence(const QString &contextSequence);
@@ -136,6 +144,9 @@ private:
// Captures used in dynamic rules.
QStringList m_currentCaptures;
+
+ QTextCharFormat m_visualWhitespaceFormat;
+ QHash m_genericFormats;
};
} // namespace Internal
diff --git a/src/plugins/genericeditor/itemdata.cpp b/src/plugins/genericeditor/itemdata.cpp
index 62ed36f01c1..b7e42980454 100644
--- a/src/plugins/genericeditor/itemdata.cpp
+++ b/src/plugins/genericeditor/itemdata.cpp
@@ -33,95 +33,98 @@
using namespace GenericEditor;
using namespace Internal;
-namespace {
- static const QLatin1String kDsNormal("dsNormal");
- static const QLatin1String kDsKeyword("dsKeyword");
- static const QLatin1String kDsDataType("dsDataType");
- static const QLatin1String kDsDecVal("dsDecVal");
- static const QLatin1String kDsBaseN("dsBaseN");
- static const QLatin1String kDsFloat("dsFloat");
- static const QLatin1String kDsChar("dsChar");
- static const QLatin1String kDsString("dsString");
- static const QLatin1String kDsComment("dsComment");
- static const QLatin1String kDsOthers("dsOthers");
- static const QLatin1String kDsAlert("dsAlert");
- static const QLatin1String kDsFunction("dsFunction");
- static const QLatin1String kDsRegionMarker("dsRegionMarker");
- static const QLatin1String kDsError("dsError");
-}
+const QLatin1String ItemData::kDsNormal("dsNormal");
+const QLatin1String ItemData::kDsKeyword("dsKeyword");
+const QLatin1String ItemData::kDsDataType("dsDataType");
+const QLatin1String ItemData::kDsDecVal("dsDecVal");
+const QLatin1String ItemData::kDsBaseN("dsBaseN");
+const QLatin1String ItemData::kDsFloat("dsFloat");
+const QLatin1String ItemData::kDsChar("dsChar");
+const QLatin1String ItemData::kDsString("dsString");
+const QLatin1String ItemData::kDsComment("dsComment");
+const QLatin1String ItemData::kDsOthers("dsOthers");
+const QLatin1String ItemData::kDsAlert("dsAlert");
+const QLatin1String ItemData::kDsFunction("dsFunction");
+const QLatin1String ItemData::kDsRegionMarker("dsRegionMarker");
+const QLatin1String ItemData::kDsError("dsError");
-ItemData::ItemData()
+ItemData::ItemData() :
+ m_italicSpecified(false),
+ m_boldSpecified(false),
+ m_underlinedSpecified(false),
+ m_strikedOutSpecified(false)
{}
void ItemData::setStyle(const QString &style)
{ m_style = style; }
+const QString &ItemData::style() const
+{ return m_style; }
+
void ItemData::setColor(const QString &color)
{ m_color.setNamedColor(color); }
+const QColor &ItemData::color() const
+{ return m_color; }
+
void ItemData::setSelectionColor(const QString &color)
{ m_selectionColor.setNamedColor(color); }
+const QColor &ItemData::selectionColor() const
+{ return m_selectionColor; }
+
void ItemData::setItalic(const QString &italic)
-{ m_font.setItalic(toBool(italic)); }
-
-void ItemData::setBold(const QString &bold)
-{ m_font.setBold(toBool(bold)); }
-
-void ItemData::setUnderlined(const QString &underlined)
-{ m_font.setUnderline(toBool(underlined)); }
-
-void ItemData::setStrikedOut(const QString &striked)
-{ m_font.setStrikeOut(toBool(striked)); }
-
-void ItemData::configureFormat()
{
- //Todo: Overwrite defaults when true?
- m_format.setFont(m_font);
-
- if (m_style == kDsNormal) {
- m_format.setForeground(Qt::black);
- } else if (m_style == kDsKeyword) {
- m_format.setForeground(Qt::black);
- m_format.setFontWeight(QFont::Bold);
- } else if (m_style == kDsDataType) {
- m_format.setForeground(Qt::blue);
- } else if (m_style == kDsDecVal) {
- m_format.setForeground(Qt::darkYellow);
- } else if (m_style == kDsBaseN) {
- m_format.setForeground(Qt::darkYellow);
- m_format.setFontWeight(QFont::Bold);
- } else if (m_style == kDsFloat) {
- m_format.setForeground(Qt::darkYellow);
- m_format.setFontUnderline(true);
- } else if (m_style == kDsChar) {
- m_format.setForeground(Qt::magenta);
- } else if (m_style == kDsString) {
- m_format.setForeground(Qt::red);
- } else if (m_style == kDsComment) {
- m_format.setForeground(Qt::darkGray);
- m_format.setFontItalic(true);
- m_format.setFontWeight(QFont::Bold);
- } else if (m_style == kDsOthers) {
- m_format.setForeground(Qt::darkGreen);
- } else if (m_style == kDsAlert) {
- m_format.setForeground(Qt::darkRed);
- m_format.setFontWeight(QFont::Bold);
- } else if (m_style == kDsFunction) {
- m_format.setForeground(Qt::darkBlue);
- m_format.setFontWeight(QFont::Bold);
- } else if (m_style == kDsRegionMarker) {
- m_format.setForeground(Qt::yellow);
- } else if (m_style == kDsError) {
- m_format.setForeground(Qt::darkRed);
- m_format.setFontUnderline(true);
+ if (!italic.isEmpty()) {
+ m_italic = toBool(italic);
+ m_italicSpecified = true;
}
-
- if (m_color.isValid())
- m_format.setForeground(QColor(m_color));
- //if (m_selectionColor.isValid())
- //m_format.setBackground(QColor(m_selectionColor));
}
-const QTextCharFormat &ItemData::format() const
-{ return m_format; }
+bool ItemData::isItalic() const
+{ return m_italic; }
+
+bool ItemData::isItalicSpecified() const
+{ return m_italicSpecified; }
+
+void ItemData::setBold(const QString &bold)
+{
+ if (!bold.isEmpty()) {
+ m_bold = toBool(bold);
+ m_boldSpecified = true;
+ }
+}
+
+bool ItemData::isBold() const
+{ return m_bold; }
+
+bool ItemData::isBoldSpecified() const
+{ return m_boldSpecified; }
+
+void ItemData::setUnderlined(const QString &underlined)
+{
+ if (!underlined.isEmpty()) {
+ m_underlined = toBool(underlined);
+ m_underlinedSpecified = true;
+ }
+}
+
+bool ItemData::isUnderlined() const
+{ return m_underlined; }
+
+bool ItemData::isUnderlinedSpecified() const
+{ return m_underlinedSpecified; }
+
+void ItemData::setStrikedOut(const QString &striked)
+{
+ if (!striked.isEmpty()) {
+ m_strikedOut = toBool(striked);
+ m_strikedOutSpecified = true;
+ }
+}
+
+bool ItemData::isStrikedOut() const
+{ return m_strikedOut; }
+
+bool ItemData::isStrikedOutSpecified() const
+{ return m_strikedOutSpecified; }
diff --git a/src/plugins/genericeditor/itemdata.h b/src/plugins/genericeditor/itemdata.h
index 67a968a4bcf..62819acb21b 100644
--- a/src/plugins/genericeditor/itemdata.h
+++ b/src/plugins/genericeditor/itemdata.h
@@ -45,22 +45,57 @@ public:
ItemData();
void setStyle(const QString &style);
- void setColor(const QString &color);
- void setSelectionColor(const QString &color);
- void setItalic(const QString &italic);
- void setBold(const QString &bold);
- void setUnderlined(const QString &underlined);
- void setStrikedOut(const QString &striked);
- void configureFormat();
+ const QString &style() const;
- const QTextCharFormat &format() const;
+ void setColor(const QString &color);
+ const QColor &color() const;
+
+ void setSelectionColor(const QString &color);
+ const QColor &selectionColor() const;
+
+ void setItalic(const QString &italic);
+ bool isItalic() const;
+ bool isItalicSpecified() const;
+
+ void setBold(const QString &bold);
+ bool isBold() const;
+ bool isBoldSpecified() const;
+
+ void setUnderlined(const QString &underlined);
+ bool isUnderlined() const;
+ bool isUnderlinedSpecified() const;
+
+ void setStrikedOut(const QString &striked);
+ bool isStrikedOut() const;
+ bool isStrikedOutSpecified() const;
+
+ static const QLatin1String kDsNormal;
+ static const QLatin1String kDsKeyword;
+ static const QLatin1String kDsDataType;
+ static const QLatin1String kDsDecVal;
+ static const QLatin1String kDsBaseN;
+ static const QLatin1String kDsFloat;
+ static const QLatin1String kDsChar;
+ static const QLatin1String kDsString;
+ static const QLatin1String kDsComment;
+ static const QLatin1String kDsOthers;
+ static const QLatin1String kDsAlert;
+ static const QLatin1String kDsFunction;
+ static const QLatin1String kDsRegionMarker;
+ static const QLatin1String kDsError;
private:
QString m_style;
QColor m_color;
QColor m_selectionColor;
- QFont m_font;
- QTextCharFormat m_format;
+ bool m_italic;
+ bool m_italicSpecified;
+ bool m_bold;
+ bool m_boldSpecified;
+ bool m_underlined;
+ bool m_underlinedSpecified;
+ bool m_strikedOut;
+ bool m_strikedOutSpecified;
};
} // namespace Internal
diff --git a/src/plugins/genericeditor/reuse.h b/src/plugins/genericeditor/reuse.h
index f6c66f4a10a..019f0e0e443 100644
--- a/src/plugins/genericeditor/reuse.h
+++ b/src/plugins/genericeditor/reuse.h
@@ -34,6 +34,7 @@
#include
#include
#include
+#include
namespace GenericEditor {
namespace Internal {
@@ -56,6 +57,14 @@ inline Qt::CaseSensitivity toCaseSensitivity(const bool sensitive)
return Qt::CaseInsensitive;
}
+inline QFont::Weight toFontWeight(const bool bold)
+{
+ if (bold)
+ return QFont::Bold;
+ else
+ return QFont::Normal;
+}
+
inline bool isOctalDigit(const QChar &c)
{
static const QLatin1Char k0('0');