summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLeandro Melo <leandro.melo@nokia.com>2010-09-29 09:14:30 +0200
committerLeandro Melo <leandro.melo@nokia.com>2010-09-29 09:18:42 +0200
commitcfe61f6431bfe7f09f00bf548e21ad8ad0aea620 (patch)
treef1a34c45d81ccd1308f82087cd31b127f8b2e914 /src
parentd7fec2ae1e48eff1dffdf9c8e8efce9b647cb1ad (diff)
downloadqt-creator-cfe61f6431bfe7f09f00bf548e21ad8ad0aea620.tar.gz
Generic highlighter: Make the editor more flexible concerning highlighting.
Now the plain text editor only tries to apply a highlight configuration if the MIME type passed is valid. Otherwise, it should behave as an ordinary trivial editor and should not miss a highlight definition.
Diffstat (limited to 'src')
-rw-r--r--src/plugins/texteditor/plaintexteditor.cpp50
1 files changed, 26 insertions, 24 deletions
diff --git a/src/plugins/texteditor/plaintexteditor.cpp b/src/plugins/texteditor/plaintexteditor.cpp
index 67b99faabf..81b30c9e32 100644
--- a/src/plugins/texteditor/plaintexteditor.cpp
+++ b/src/plugins/texteditor/plaintexteditor.cpp
@@ -62,7 +62,7 @@ PlainTextEditorEditable::PlainTextEditorEditable(PlainTextEditor *editor)
PlainTextEditor::PlainTextEditor(QWidget *parent)
: BaseTextEditor(parent),
- m_isMissingSyntaxDefinition(true)
+ m_isMissingSyntaxDefinition(false)
{
setRevisionsVisible(true);
setMarksVisible(true);
@@ -164,8 +164,10 @@ void PlainTextEditor::setTabSettings(const TextEditor::TabSettings &ts)
void PlainTextEditor::configure()
{
+ Core::MimeType mimeType;
if (file())
- configure(Core::ICore::instance()->mimeDatabase()->findByFile(file()->fileName()));
+ mimeType = Core::ICore::instance()->mimeDatabase()->findByFile(file()->fileName());
+ configure(mimeType);
}
void PlainTextEditor::configure(const Core::MimeType &mimeType)
@@ -173,39 +175,39 @@ void PlainTextEditor::configure(const Core::MimeType &mimeType)
Highlighter *highlighter = new Highlighter();
baseTextDocument()->setSyntaxHighlighter(highlighter);
- m_isMissingSyntaxDefinition = true;
setCodeFoldingSupported(false);
setCodeFoldingVisible(false);
- QString definitionId;
if (!mimeType.isNull()) {
+ m_isMissingSyntaxDefinition = true;
+
const QString &type = mimeType.type();
setMimeType(type);
- definitionId = Manager::instance()->definitionIdByMimeType(type);
+ QString definitionId = Manager::instance()->definitionIdByMimeType(type);
if (definitionId.isEmpty())
definitionId = findDefinitionId(mimeType, true);
- }
-
- if (!definitionId.isEmpty()) {
- m_isMissingSyntaxDefinition = false;
- const QSharedPointer<HighlightDefinition> &definition =
- Manager::instance()->definition(definitionId);
- if (!definition.isNull()) {
- highlighter->setDefaultContext(definition->initialContext());
-
- m_commentDefinition.setAfterWhiteSpaces(definition->isCommentAfterWhiteSpaces());
- m_commentDefinition.setSingleLine(definition->singleLineComment());
- m_commentDefinition.setMultiLineStart(definition->multiLineCommentStart());
- m_commentDefinition.setMultiLineEnd(definition->multiLineCommentEnd());
- setCodeFoldingSupported(true);
- setCodeFoldingVisible(true);
- }
- } else if (file()) {
- const QString &fileName = file()->fileName();
- if (TextEditorSettings::instance()->highlighterSettings().isIgnoredFilePattern(fileName))
+ if (!definitionId.isEmpty()) {
m_isMissingSyntaxDefinition = false;
+ const QSharedPointer<HighlightDefinition> &definition =
+ Manager::instance()->definition(definitionId);
+ if (!definition.isNull()) {
+ highlighter->setDefaultContext(definition->initialContext());
+
+ m_commentDefinition.setAfterWhiteSpaces(definition->isCommentAfterWhiteSpaces());
+ m_commentDefinition.setSingleLine(definition->singleLineComment());
+ m_commentDefinition.setMultiLineStart(definition->multiLineCommentStart());
+ m_commentDefinition.setMultiLineEnd(definition->multiLineCommentEnd());
+
+ setCodeFoldingSupported(true);
+ setCodeFoldingVisible(true);
+ }
+ } else if (file()) {
+ const QString &fileName = file()->fileName();
+ if (TextEditorSettings::instance()->highlighterSettings().isIgnoredFilePattern(fileName))
+ m_isMissingSyntaxDefinition = false;
+ }
}
setFontSettings(TextEditorSettings::instance()->fontSettings());