diff --git a/src/libs/utils/uncommentselection.cpp b/src/libs/utils/uncommentselection.cpp index 7c00ba22e7c..761a040ca45 100644 --- a/src/libs/utils/uncommentselection.cpp +++ b/src/libs/utils/uncommentselection.cpp @@ -85,6 +85,13 @@ bool CommentDefinition::hasSingleLineStyle() const bool CommentDefinition::hasMultiLineStyle() const { return !m_multiLineStart.isEmpty() && !m_multiLineEnd.isEmpty(); } +void CommentDefinition::clearCommentStyles() +{ + m_singleLine.clear(); + m_multiLineStart.clear(); + m_multiLineEnd.clear(); +} + namespace { bool isComment(const QString &text, diff --git a/src/libs/utils/uncommentselection.h b/src/libs/utils/uncommentselection.h index a984d512b32..42a7dc10669 100644 --- a/src/libs/utils/uncommentselection.h +++ b/src/libs/utils/uncommentselection.h @@ -58,6 +58,8 @@ public: bool hasSingleLineStyle() const; bool hasMultiLineStyle() const; + void clearCommentStyles(); + private: bool m_afterWhiteSpaces; QString m_singleLine; diff --git a/src/plugins/genericeditor/GenericEditor.pluginspec b/src/plugins/genericeditor/GenericEditor.pluginspec deleted file mode 100644 index 015b17b2c55..00000000000 --- a/src/plugins/genericeditor/GenericEditor.pluginspec +++ /dev/null @@ -1,20 +0,0 @@ - - Nokia Corporation - (C) 2010 Nokia Corporation - -Commercial Usage - -Licensees holding valid Qt Commercial licenses may use this plugin in accordance with the Qt Commercial License Agreement provided with the Software or, alternatively, in accordance with the terms contained in a written agreement between you and Nokia. - -GNU Lesser General Public License Usage - -Alternatively, this plugin may be used under the terms of the GNU Lesser General Public License version 2.1 as published by the Free Software Foundation. Please review the following information to ensure the GNU Lesser General Public License version 2.1 requirements will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. - - Qt Creator - Generic editor with highlighting for a variety of languages. - http://qt.nokia.com - - - - - diff --git a/src/plugins/genericeditor/editor.cpp b/src/plugins/genericeditor/editor.cpp deleted file mode 100644 index 11862e524a4..00000000000 --- a/src/plugins/genericeditor/editor.cpp +++ /dev/null @@ -1,148 +0,0 @@ -/************************************************************************** -** -** This file is part of Qt Creator -** -** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). -** -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** Commercial Usage -** -** Licensees holding valid Qt Commercial licenses may use this file in -** accordance with the Qt Commercial License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Nokia. -** -** GNU Lesser General Public License Usage -** -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at http://qt.nokia.com/contact. -** -**************************************************************************/ - -#include "editor.h" -#include "genericeditorconstants.h" -#include "genericeditorplugin.h" -#include "highlightdefinition.h" -#include "highlighter.h" -#include "highlighterexception.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -using namespace GenericEditor; -using namespace Internal; - -Editor::Editor(QWidget *parent) : TextEditor::BaseTextEditor(parent) -{ - connect(file(), SIGNAL(changed()), this, SLOT(configure())); -} - -Editor::~Editor() -{} - -void Editor::unCommentSelection() -{ - Utils::unCommentSelection(this, m_commentDefinition); -} - -TextEditor::BaseTextEditorEditable *Editor::createEditableInterface() -{ - EditorEditable *editable = new EditorEditable(this); - 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::indentBlock(QTextDocument *doc, QTextBlock block, QChar typedChar) -{ - m_indenter->indentBlock(doc, block, typedChar, tabSettings()); -} - -void Editor::configure() -{ - const QString &mimeType = Core::ICore::instance()->mimeDatabase()->findByFile( - QFileInfo(file()->fileName())).type(); - baseTextDocument()->setMimeType(mimeType); - - try { - const QString &definitionId = - GenericEditorPlugin::instance()->definitionIdByMimeType(mimeType); - const QSharedPointer &definition = - GenericEditorPlugin::instance()->definition(definitionId); - - 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()); - m_commentDefinition.setMultiLineStart(definition->multiLineCommentStart()); - m_commentDefinition.setMultiLineEnd(definition->multiLineCommentEnd()); - - // @todo: It's possible to specify an indenter style in the definition file. However, this - // is not really being used because Kate recommends to configure indentation through - // another feature. Maybe we should provide something similar in Creator? For now the - // normal indenter is used. - m_indenter.reset(new TextEditor::NormalIndenter); - - } catch (const HighlighterException &) { - // No highlighter will be set. - } -} - -EditorEditable::EditorEditable(Editor *editor) : - TextEditor::BaseTextEditorEditable(editor) -{ - Core::UniqueIDManager *uidm = Core::UniqueIDManager::instance(); - m_context << uidm->uniqueIdentifier(GenericEditor::Constants::GENERIC_EDITOR); - m_context << uidm->uniqueIdentifier(TextEditor::Constants::C_TEXTEDITOR); -} - -QString EditorEditable::id() const -{ return QLatin1String(GenericEditor::Constants::GENERIC_EDITOR); } - -QList EditorEditable::context() const -{ return m_context; } - -bool EditorEditable::isTemporary() const -{ return false; } - -bool EditorEditable::duplicateSupported() const -{ return true; } - -Core::IEditor *EditorEditable::duplicate(QWidget *parent) -{ - Editor *newEditor = new Editor(parent); - newEditor->duplicateFrom(editor()); - GenericEditorPlugin::instance()->initializeEditor(newEditor); - return newEditor->editableInterface(); -} diff --git a/src/plugins/genericeditor/editor.h b/src/plugins/genericeditor/editor.h deleted file mode 100644 index b50d4f11a7c..00000000000 --- a/src/plugins/genericeditor/editor.h +++ /dev/null @@ -1,101 +0,0 @@ -/************************************************************************** -** -** This file is part of Qt Creator -** -** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). -** -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** Commercial Usage -** -** Licensees holding valid Qt Commercial licenses may use this file in -** accordance with the Qt Commercial License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Nokia. -** -** GNU Lesser General Public License Usage -** -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at http://qt.nokia.com/contact. -** -**************************************************************************/ - -#ifndef GENERICEDITOR_H -#define GENERICEDITOR_H - -#include -#include - -#include -#include -#include - -QT_BEGIN_NAMESPACE -class QString; -class QTextDocument; -QT_END_NAMESPACE - -namespace TextEditor { -class Indenter; -} - -namespace GenericEditor { -namespace Internal { - -class Editor : public TextEditor::BaseTextEditor -{ - Q_OBJECT -public: - Editor(QWidget *parent = 0); - virtual ~Editor(); - - virtual void unCommentSelection(); - -protected: - virtual TextEditor::BaseTextEditorEditable *createEditableInterface(); - -public slots: - virtual void setFontSettings(const TextEditor::FontSettings &); - -private slots: - void configure(); - -private: - Q_DISABLE_COPY(Editor) - - virtual void indentBlock(QTextDocument *doc, QTextBlock block, QChar typedChar); - - Utils::CommentDefinition m_commentDefinition; - QScopedPointer m_indenter; -}; - -class EditorEditable : public TextEditor::BaseTextEditorEditable -{ - Q_OBJECT -public: - EditorEditable(Editor *editor); - -protected: - virtual QString id() const; - virtual QList context() const; - virtual bool isTemporary() const; - virtual bool duplicateSupported() const; - virtual Core::IEditor *duplicate(QWidget *parent); - -private: - QList m_context; -}; - - - -} // namespace Internal -} // namespace GenericEditor - -#endif // GENERICEDITOR_H diff --git a/src/plugins/genericeditor/editorfactory.cpp b/src/plugins/genericeditor/editorfactory.cpp deleted file mode 100644 index dcb2285cb58..00000000000 --- a/src/plugins/genericeditor/editorfactory.cpp +++ /dev/null @@ -1,70 +0,0 @@ -/************************************************************************** -** -** This file is part of Qt Creator -** -** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). -** -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** Commercial Usage -** -** Licensees holding valid Qt Commercial licenses may use this file in -** accordance with the Qt Commercial License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Nokia. -** -** GNU Lesser General Public License Usage -** -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at http://qt.nokia.com/contact. -** -**************************************************************************/ - -#include "editorfactory.h" -#include "genericeditorconstants.h" -#include "editor.h" -#include "genericeditorplugin.h" - -#include - -using namespace GenericEditor; -using namespace Internal; - -EditorFactory::EditorFactory(QObject *parent) : Core::IEditorFactory(parent) -{} - -EditorFactory::~EditorFactory() -{} - -Core::IEditor *EditorFactory::createEditor(QWidget *parent) -{ - Editor *genericEditor = new Editor(parent); - GenericEditorPlugin::instance()->initializeEditor(genericEditor); - return genericEditor->editableInterface(); -} - -QStringList EditorFactory::mimeTypes() const -{ return m_mimeTypes; } - -QString EditorFactory::id() const -{ - return QLatin1String(GenericEditor::Constants::GENERIC_EDITOR); -} - -QString EditorFactory::displayName() const -{ - return tr(GenericEditor::Constants::GENERIC_EDITOR_DISPLAY_NAME); -} - -Core::IFile *EditorFactory::open(const QString &fileName) -{ - Core::IEditor *iface = Core::EditorManager::instance()->openEditor(fileName, id()); - return iface ? iface->file() : 0; -} diff --git a/src/plugins/genericeditor/editorfactory.h b/src/plugins/genericeditor/editorfactory.h deleted file mode 100644 index f4e44db9729..00000000000 --- a/src/plugins/genericeditor/editorfactory.h +++ /dev/null @@ -1,64 +0,0 @@ -/************************************************************************** -** -** This file is part of Qt Creator -** -** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). -** -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** Commercial Usage -** -** Licensees holding valid Qt Commercial licenses may use this file in -** accordance with the Qt Commercial License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Nokia. -** -** GNU Lesser General Public License Usage -** -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at http://qt.nokia.com/contact. -** -**************************************************************************/ - -#ifndef GENERICEDITORFACTORY_H -#define GENERICEDITORFACTORY_H - -#include - -#include - -namespace GenericEditor { -namespace Internal { - -class Editor; - -class EditorFactory : public Core::IEditorFactory -{ - Q_OBJECT - - friend class GenericEditorPlugin; -public: - EditorFactory(QObject *parent = 0); - virtual ~EditorFactory(); - - virtual Core::IEditor *createEditor(QWidget *parent); - virtual QStringList mimeTypes() const; - virtual QString id() const; - virtual QString displayName() const; - virtual Core::IFile *open(const QString &fileName); - -private: - QStringList m_mimeTypes; -}; - -} // namespace Internal -} // namespace GenericEditor - -#endif // GENERICEDITORFACTORY_H diff --git a/src/plugins/genericeditor/genericeditor.pri b/src/plugins/genericeditor/genericeditor.pri deleted file mode 100644 index cd4a9337c6a..00000000000 --- a/src/plugins/genericeditor/genericeditor.pri +++ /dev/null @@ -1,3 +0,0 @@ -include(genericeditor_dependencies.pri) - -LIBS *= -l$$qtLibraryTarget(GenericEditor) diff --git a/src/plugins/genericeditor/genericeditor.pro b/src/plugins/genericeditor/genericeditor.pro deleted file mode 100644 index 55bda44b08f..00000000000 --- a/src/plugins/genericeditor/genericeditor.pro +++ /dev/null @@ -1,43 +0,0 @@ -TEMPLATE = lib -TARGET = GenericEditor -include(../../qtcreatorplugin.pri) -include(genericeditor_dependencies.pri) - -CONFIG += help - -HEADERS += \ - genericeditorplugin.h \ - progressdata.h \ - specificrules.h \ - rule.h \ - reuse.h \ - keywordlist.h \ - itemdata.h \ - includerulesinstruction.h \ - highlighterexception.h \ - highlighter.h \ - highlightdefinitionhandler.h \ - highlightdefinition.h \ - dynamicrule.h \ - context.h \ - genericeditorconstants.h \ - editor.h \ - editorfactory.h - -SOURCES += \ - genericeditorplugin.cpp \ - progressdata.cpp \ - specificrules.cpp \ - rule.cpp \ - keywordlist.cpp \ - itemdata.cpp \ - includerulesinstruction.cpp \ - highlighter.cpp \ - highlightdefinitionhandler.cpp \ - highlightdefinition.cpp \ - dynamicrule.cpp \ - context.cpp \ - editor.cpp \ - editorfactory.cpp - -OTHER_FILES += GenericEditor.pluginspec diff --git a/src/plugins/genericeditor/genericeditor_dependencies.pri b/src/plugins/genericeditor/genericeditor_dependencies.pri deleted file mode 100644 index accac405003..00000000000 --- a/src/plugins/genericeditor/genericeditor_dependencies.pri +++ /dev/null @@ -1,3 +0,0 @@ -include(../../plugins/coreplugin/coreplugin.pri) -include(../../plugins/texteditor/texteditor.pri) -include(../../libs/utils/utils.pri) diff --git a/src/plugins/genericeditor/genericeditorconstants.h b/src/plugins/genericeditor/genericeditorconstants.h deleted file mode 100644 index 2d9ec05766c..00000000000 --- a/src/plugins/genericeditor/genericeditorconstants.h +++ /dev/null @@ -1,45 +0,0 @@ -/************************************************************************** -** -** This file is part of Qt Creator -** -** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). -** -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** Commercial Usage -** -** Licensees holding valid Qt Commercial licenses may use this file in -** accordance with the Qt Commercial License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Nokia. -** -** GNU Lesser General Public License Usage -** -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at http://qt.nokia.com/contact. -** -**************************************************************************/ - -#ifndef GENERICEDITORCONSTANTS_H -#define GENERICEDITORCONSTANTS_H - -#include - -namespace GenericEditor { -namespace Constants { - -const char * const GENERIC_EDITOR = "GenericEditorPlugin.GenericEditor"; -const char * const GENERIC_EDITOR_DISPLAY_NAME = - QT_TRANSLATE_NOOP("OpenWith::Editors", "Generic Editor"); - -} // namespace Constants -} // namespace GenericEditor - -#endif // GENERICEDITORCONSTANTS_H diff --git a/src/plugins/plugins.pro b/src/plugins/plugins.pro index 9928857b823..156d5ce9f8f 100644 --- a/src/plugins/plugins.pro +++ b/src/plugins/plugins.pro @@ -33,7 +33,6 @@ SUBDIRS = plugin_coreplugin \ plugin_genericprojectmanager \ plugin_qmljseditor \ plugin_mercurial \ - plugin_genericeditor \ debugger/dumper.pro contains(QT_CONFIG, declarative) { @@ -209,7 +208,3 @@ plugin_mercurial.subdir = mercurial plugin_mercurial.depends = plugin_vcsbase plugin_mercurial.depends += plugin_projectexplorer plugin_mercurial.depends += plugin_coreplugin - -plugin_genericeditor.subdir = genericeditor -plugin_genericeditor.depends = plugin_coreplugin -plugin_genericeditor.depends += plugin_texteditor diff --git a/src/plugins/genericeditor/context.cpp b/src/plugins/texteditor/generichighlighter/context.cpp similarity index 97% rename from src/plugins/genericeditor/context.cpp rename to src/plugins/texteditor/generichighlighter/context.cpp index 75ad3b50402..d9fea72fd55 100644 --- a/src/plugins/genericeditor/context.cpp +++ b/src/plugins/texteditor/generichighlighter/context.cpp @@ -33,7 +33,7 @@ #include "dynamicrule.h" #include "highlightdefinition.h" -using namespace GenericEditor; +using namespace TextEditor; using namespace Internal; Context::Context() : m_fallthrough(false), m_dynamic(false) @@ -128,7 +128,7 @@ bool Context::isDynamic() const void Context::updateDynamicRules(const QStringList &captures) const { - GenericEditor::Internal::updateDynamicRules(m_rules, captures); + TextEditor::Internal::updateDynamicRules(m_rules, captures); } void Context::addRule(const QSharedPointer &rule) diff --git a/src/plugins/genericeditor/context.h b/src/plugins/texteditor/generichighlighter/context.h similarity index 98% rename from src/plugins/genericeditor/context.h rename to src/plugins/texteditor/generichighlighter/context.h index aa9db961b92..1d800ca2e58 100644 --- a/src/plugins/genericeditor/context.h +++ b/src/plugins/texteditor/generichighlighter/context.h @@ -36,7 +36,7 @@ #include #include -namespace GenericEditor { +namespace TextEditor { namespace Internal { class Rule; @@ -105,6 +105,6 @@ private: }; } // namespace Internal -} // namespace GenericEditor +} // namespace TextEditor #endif // CONTEXT_H diff --git a/src/plugins/genericeditor/dynamicrule.cpp b/src/plugins/texteditor/generichighlighter/dynamicrule.cpp similarity index 95% rename from src/plugins/genericeditor/dynamicrule.cpp rename to src/plugins/texteditor/generichighlighter/dynamicrule.cpp index 1bb06354947..24d7414dd7d 100644 --- a/src/plugins/genericeditor/dynamicrule.cpp +++ b/src/plugins/texteditor/generichighlighter/dynamicrule.cpp @@ -30,7 +30,7 @@ #include "dynamicrule.h" #include "reuse.h" -using namespace GenericEditor; +using namespace TextEditor; using namespace Internal; DynamicRule::DynamicRule() : m_active(false) @@ -51,7 +51,7 @@ void DynamicRule::replaceExpressions(const QStringList &captures) updateDynamicRules(childs(), captures); } -namespace GenericEditor { +namespace TextEditor { namespace Internal { void updateDynamicRules(const QList > &rules, const QStringList &captures) @@ -64,4 +64,4 @@ void updateDynamicRules(const QList > &rules, const QString } } // namespace Internal -} // namespace GenericEditor +} // namespace TextEditor diff --git a/src/plugins/genericeditor/dynamicrule.h b/src/plugins/texteditor/generichighlighter/dynamicrule.h similarity index 97% rename from src/plugins/genericeditor/dynamicrule.h rename to src/plugins/texteditor/generichighlighter/dynamicrule.h index 1fdeb1ff0b1..1e116d31bd5 100644 --- a/src/plugins/genericeditor/dynamicrule.h +++ b/src/plugins/texteditor/generichighlighter/dynamicrule.h @@ -36,7 +36,7 @@ QT_BEGIN_NAMESPACE class QStringList; QT_END_NAMESPACE -namespace GenericEditor { +namespace TextEditor { namespace Internal { class DynamicRule : public Rule @@ -59,6 +59,6 @@ private: void updateDynamicRules(const QList > &rules, const QStringList &captures); } // namespace Internal -} // namespace GenericEditor +} // namespace TextEditor #endif // DYNAMICRULE_H diff --git a/src/plugins/genericeditor/highlightdefinition.cpp b/src/plugins/texteditor/generichighlighter/highlightdefinition.cpp similarity index 99% rename from src/plugins/genericeditor/highlightdefinition.cpp rename to src/plugins/texteditor/generichighlighter/highlightdefinition.cpp index 90481566f6f..7c723229d95 100644 --- a/src/plugins/genericeditor/highlightdefinition.cpp +++ b/src/plugins/texteditor/generichighlighter/highlightdefinition.cpp @@ -36,7 +36,7 @@ #include -using namespace GenericEditor; +using namespace TextEditor; using namespace Internal; HighlightDefinition::HighlightDefinition() : diff --git a/src/plugins/genericeditor/highlightdefinition.h b/src/plugins/texteditor/generichighlighter/highlightdefinition.h similarity index 98% rename from src/plugins/genericeditor/highlightdefinition.h rename to src/plugins/texteditor/generichighlighter/highlightdefinition.h index ea3278dea3e..2f48bc24c8f 100644 --- a/src/plugins/genericeditor/highlightdefinition.h +++ b/src/plugins/texteditor/generichighlighter/highlightdefinition.h @@ -34,7 +34,7 @@ #include #include -namespace GenericEditor { +namespace TextEditor { namespace Internal { class KeywordList; @@ -112,6 +112,6 @@ private: }; } // namespace Internal -} // namespace GenericEditor +} // namespace TextEditor #endif // HIGHLIGHTDEFINITION_H diff --git a/src/plugins/genericeditor/highlightdefinitionhandler.cpp b/src/plugins/texteditor/generichighlighter/highlightdefinitionhandler.cpp similarity index 98% rename from src/plugins/genericeditor/highlightdefinitionhandler.cpp rename to src/plugins/texteditor/generichighlighter/highlightdefinitionhandler.cpp index 0b959fa78ac..f18d3de8f2f 100644 --- a/src/plugins/genericeditor/highlightdefinitionhandler.cpp +++ b/src/plugins/texteditor/generichighlighter/highlightdefinitionhandler.cpp @@ -34,12 +34,12 @@ #include "keywordlist.h" #include "context.h" #include "reuse.h" -#include "genericeditorplugin.h" +#include "manager.h" #include "highlighterexception.h" #include -using namespace GenericEditor; +using namespace TextEditor; using namespace Internal; namespace { @@ -430,14 +430,14 @@ void HighlightDefinitionHandler::processIncludeRules(const QSharedPointerdefinitionIdByName(externalName); + const QString &id = Manager::instance()->definitionIdByName(externalName); // If there is an incorrect circular dependency among definitions this is skipped. - if (GenericEditorPlugin::instance()->isBuildingDefinition(id)) + if (Manager::instance()->isBuildingDefinition(id)) continue; const QSharedPointer &externalDefinition = - GenericEditorPlugin::instance()->definition(id); + Manager::instance()->definition(id); sourceContext = externalDefinition->initialContext(); } else if (!sourceName.startsWith(kHash)) { sourceContext = m_definition->context(sourceName); diff --git a/src/plugins/genericeditor/highlightdefinitionhandler.h b/src/plugins/texteditor/generichighlighter/highlightdefinitionhandler.h similarity index 98% rename from src/plugins/genericeditor/highlightdefinitionhandler.h rename to src/plugins/texteditor/generichighlighter/highlightdefinitionhandler.h index 6a460c0f74b..e08be97649f 100644 --- a/src/plugins/genericeditor/highlightdefinitionhandler.h +++ b/src/plugins/texteditor/generichighlighter/highlightdefinitionhandler.h @@ -37,7 +37,7 @@ #include -namespace GenericEditor { +namespace TextEditor { namespace Internal { class KeywordList; @@ -101,6 +101,6 @@ private: }; } // namespace Internal -} // namespace GenericEditor +} // namespace TextEditor #endif // HIGHLIGHTDEFINITIONHANDLER_H diff --git a/src/plugins/genericeditor/highlighter.cpp b/src/plugins/texteditor/generichighlighter/highlighter.cpp similarity index 96% rename from src/plugins/genericeditor/highlighter.cpp rename to src/plugins/texteditor/generichighlighter/highlighter.cpp index 71865eadf92..27b0309795c 100644 --- a/src/plugins/genericeditor/highlighter.cpp +++ b/src/plugins/texteditor/generichighlighter/highlighter.cpp @@ -35,14 +35,13 @@ #include "highlighterexception.h" #include "progressdata.h" #include "reuse.h" - -#include -#include +#include "texteditorconstants.h" +#include "fontsettings.h" #include #include -using namespace GenericEditor; +using namespace TextEditor; using namespace Internal; namespace { @@ -300,8 +299,8 @@ void Highlighter::applyFormat(int offset, try { itemData = definition->itemData(itemDataName); } catch (const HighlighterException &) { - // There are broken files which Kate can cope with. For instance the Printf context in - // java.xml points to an inexistent Printf item data. These are taken as normal text. + // There are some broken files. For instance, the Printf context in java.xml points to an + // inexistent Printf item data. These cases are considered to have normal text style. return; } @@ -431,15 +430,15 @@ void Highlighter::pushDynamicContext(const QSharedPointer &baseContext) void Highlighter::setCurrentContext() { if (m_contexts.isEmpty()) { - // This is not supposed to happen. However, there might be broken files (for example, the - // php.xml) which will cause this behaviour. In such cases just pushing the default - // context is enough to keep highlighter working. + // This is not supposed to happen. However, there are broken files (for example, php.xml) + // which will cause this behaviour. In such cases pushing the default context is enough to + // keep highlighter working. m_contexts.push_back(m_defaultContext); } m_currentContext = m_contexts.back(); } -void Highlighter::configureFormats(const TextEditor::FontSettings & fs) +void Highlighter::configureFormats(const FontSettings & fs) { m_visualWhitespaceFormat = fs.toTextCharFormat( QLatin1String(TextEditor::Constants::C_VISUAL_WHITESPACE)); diff --git a/src/plugins/genericeditor/highlighter.h b/src/plugins/texteditor/generichighlighter/highlighter.h similarity index 95% rename from src/plugins/genericeditor/highlighter.h rename to src/plugins/texteditor/generichighlighter/highlighter.h index e068af9d28e..bbf7e769923 100644 --- a/src/plugins/genericeditor/highlighter.h +++ b/src/plugins/texteditor/generichighlighter/highlighter.h @@ -30,6 +30,8 @@ #ifndef HIGHLIGHTER_H #define HIGHLIGHTER_H +#include "basetextdocumentlayout.h" + #include #include #include @@ -37,13 +39,11 @@ #include -#include - namespace TextEditor { class FontSettings; } -namespace GenericEditor { +namespace TextEditor { namespace Internal { class Rule; @@ -57,7 +57,7 @@ public: Highlighter(const QSharedPointer &defaultContext, QTextDocument *parent = 0); virtual ~Highlighter(); - void configureFormats(const TextEditor::FontSettings & fs); + void configureFormats(const FontSettings & fs); protected: virtual void highlightBlock(const QString &text); @@ -100,7 +100,7 @@ private: void createWillContinueBlock(); void analyseConsistencyOfWillContinueBlock(const QString &text); - struct BlockData : TextEditor::TextBlockUserData + struct BlockData : TextBlockUserData { BlockData(); virtual ~BlockData(); @@ -149,6 +149,6 @@ private: }; } // namespace Internal -} // namespace GenericEditor +} // namespace TextEditor #endif // HIGHLIGHTER_H diff --git a/src/plugins/genericeditor/highlighterexception.h b/src/plugins/texteditor/generichighlighter/highlighterexception.h similarity index 96% rename from src/plugins/genericeditor/highlighterexception.h rename to src/plugins/texteditor/generichighlighter/highlighterexception.h index c25f34795bc..13310402faa 100644 --- a/src/plugins/genericeditor/highlighterexception.h +++ b/src/plugins/texteditor/generichighlighter/highlighterexception.h @@ -30,12 +30,12 @@ #ifndef HIGHLIGHTEREXCEPTION_H #define HIGHLIGHTEREXCEPTION_H -namespace GenericEditor { +namespace TextEditor { namespace Internal { class HighlighterException {}; } // namespace Internal -} // namespace GenericEditor +} // namespace TextEditor #endif // HIGHLIGHTEREXCEPTION_H diff --git a/src/plugins/genericeditor/includerulesinstruction.cpp b/src/plugins/texteditor/generichighlighter/includerulesinstruction.cpp similarity index 98% rename from src/plugins/genericeditor/includerulesinstruction.cpp rename to src/plugins/texteditor/generichighlighter/includerulesinstruction.cpp index 85c99e02627..8b048266333 100644 --- a/src/plugins/genericeditor/includerulesinstruction.cpp +++ b/src/plugins/texteditor/generichighlighter/includerulesinstruction.cpp @@ -30,7 +30,7 @@ #include "includerulesinstruction.h" #include "reuse.h" -using namespace GenericEditor; +using namespace TextEditor; using namespace Internal; IncludeRulesInstruction::IncludeRulesInstruction(const QString &context, diff --git a/src/plugins/genericeditor/includerulesinstruction.h b/src/plugins/texteditor/generichighlighter/includerulesinstruction.h similarity index 96% rename from src/plugins/genericeditor/includerulesinstruction.h rename to src/plugins/texteditor/generichighlighter/includerulesinstruction.h index 66823d737f5..c0f5d6e498b 100644 --- a/src/plugins/genericeditor/includerulesinstruction.h +++ b/src/plugins/texteditor/generichighlighter/includerulesinstruction.h @@ -32,7 +32,7 @@ #include -namespace GenericEditor { +namespace TextEditor { namespace Internal { class IncludeRulesInstruction @@ -51,6 +51,6 @@ private: }; } // namespace Internal -} // namespace GenericEditor +} // namespace TextEditor #endif // INCLUDERULESINSTRUCTION_H diff --git a/src/plugins/genericeditor/itemdata.cpp b/src/plugins/texteditor/generichighlighter/itemdata.cpp similarity index 99% rename from src/plugins/genericeditor/itemdata.cpp rename to src/plugins/texteditor/generichighlighter/itemdata.cpp index 2511734eb79..498d968e32c 100644 --- a/src/plugins/genericeditor/itemdata.cpp +++ b/src/plugins/texteditor/generichighlighter/itemdata.cpp @@ -30,7 +30,7 @@ #include "itemdata.h" #include "reuse.h" -using namespace GenericEditor; +using namespace TextEditor; using namespace Internal; const QLatin1String ItemData::kDsNormal("dsNormal"); diff --git a/src/plugins/genericeditor/itemdata.h b/src/plugins/texteditor/generichighlighter/itemdata.h similarity index 98% rename from src/plugins/genericeditor/itemdata.h rename to src/plugins/texteditor/generichighlighter/itemdata.h index ee4c2c3246f..c1302397498 100644 --- a/src/plugins/genericeditor/itemdata.h +++ b/src/plugins/texteditor/generichighlighter/itemdata.h @@ -33,7 +33,7 @@ #include #include -namespace GenericEditor { +namespace TextEditor { namespace Internal { class ItemData @@ -99,6 +99,6 @@ private: }; } // namespace Internal -} // namespace GenericEditor +} // namespace TextEditor #endif // ITEMDATA_H diff --git a/src/plugins/genericeditor/keywordlist.cpp b/src/plugins/texteditor/generichighlighter/keywordlist.cpp similarity index 98% rename from src/plugins/genericeditor/keywordlist.cpp rename to src/plugins/texteditor/generichighlighter/keywordlist.cpp index 70ef6ac614b..48c9672915a 100644 --- a/src/plugins/genericeditor/keywordlist.cpp +++ b/src/plugins/texteditor/generichighlighter/keywordlist.cpp @@ -29,7 +29,7 @@ #include "keywordlist.h" -using namespace GenericEditor; +using namespace TextEditor; using namespace Internal; void KeywordList::addKeyword(const QString &keyword) diff --git a/src/plugins/genericeditor/keywordlist.h b/src/plugins/texteditor/generichighlighter/keywordlist.h similarity index 96% rename from src/plugins/genericeditor/keywordlist.h rename to src/plugins/texteditor/generichighlighter/keywordlist.h index c76a7311beb..82495ca220a 100644 --- a/src/plugins/genericeditor/keywordlist.h +++ b/src/plugins/texteditor/generichighlighter/keywordlist.h @@ -33,7 +33,7 @@ #include #include -namespace GenericEditor { +namespace TextEditor { namespace Internal { class KeywordList @@ -48,6 +48,6 @@ private: }; } // namespace Internal -} // namespace GenericEditor +} // namespace TextEditor #endif // KEYWORDLIST_H diff --git a/src/plugins/genericeditor/genericeditorplugin.cpp b/src/plugins/texteditor/generichighlighter/manager.cpp similarity index 77% rename from src/plugins/genericeditor/genericeditorplugin.cpp rename to src/plugins/texteditor/generichighlighter/manager.cpp index 73578134cfe..6080c4f764e 100644 --- a/src/plugins/genericeditor/genericeditorplugin.cpp +++ b/src/plugins/texteditor/generichighlighter/manager.cpp @@ -27,16 +27,15 @@ ** **************************************************************************/ -#include "genericeditorplugin.h" +#include "manager.h" #include "highlightdefinition.h" #include "highlightdefinitionhandler.h" #include "highlighterexception.h" -#include "genericeditorconstants.h" -#include "editor.h" -#include "editorfactory.h" +#include "texteditorplugin.h" +#include "texteditorsettings.h" +#include "plaintexteditorfactory.h" #include -#include #include #include @@ -58,64 +57,26 @@ #include #include -using namespace GenericEditor; +using namespace TextEditor; using namespace Internal; -GenericEditorPlugin *GenericEditorPlugin::m_instance = 0; - -GenericEditorPlugin::GenericEditorPlugin() : - m_actionHandler(0) -{ - QTC_ASSERT(!m_instance, return); - m_instance = this; - - connect(Core::ICore::instance(), SIGNAL(coreOpened()), this, SLOT(registerMimeTypes())); -} - -GenericEditorPlugin::~GenericEditorPlugin() -{ - delete m_actionHandler; - m_instance = 0; -} - -GenericEditorPlugin *GenericEditorPlugin::instance() -{ return m_instance; } - -bool GenericEditorPlugin::initialize(const QStringList &arguments, QString *errorString) -{ - Q_UNUSED(arguments) - Q_UNUSED(errorString) - - m_factory = new EditorFactory(this); - addAutoReleasedObject(m_factory); - - m_actionHandler = new TextEditor::TextEditorActionHandler( - GenericEditor::Constants::GENERIC_EDITOR, - TextEditor::TextEditorActionHandler::Format | - TextEditor::TextEditorActionHandler::UnCommentSelection); - m_actionHandler->initializeActions(); - - return true; -} - -void GenericEditorPlugin::extensionsInitialized() +Manager::Manager() {} -void GenericEditorPlugin::initializeEditor(Editor *editor) +Manager *Manager::instance() { - m_actionHandler->setupActions(editor); - - TextEditor::TextEditorSettings::instance()->initializeEditor(editor); + static Manager manager; + return &manager; } -QString GenericEditorPlugin::definitionIdByName(const QString &name) const +QString Manager::definitionIdByName(const QString &name) const { return m_idByName.value(name); } -QString GenericEditorPlugin::definitionIdByMimeType(const QString &mimeType) const +QString Manager::definitionIdByMimeType(const QString &mimeType) const { - Q_ASSERT(!mimeType.isEmpty() && m_idByMimeType.count(mimeType) > 0); + Q_ASSERT(!mimeType.isEmpty()); - if (m_idByMimeType.count(mimeType) == 1) { + if (m_idByMimeType.count(mimeType) <= 1) { return m_idByMimeType.value(mimeType); } else { QStringList candidateIds; @@ -129,7 +90,7 @@ QString GenericEditorPlugin::definitionIdByMimeType(const QString &mimeType) con } } -const QSharedPointer &GenericEditorPlugin::definition(const QString &id) +const QSharedPointer &Manager::definition(const QString &id) { if (!m_definitions.contains(id)) { m_isBuilding.insert(id); @@ -154,19 +115,19 @@ const QSharedPointer &GenericEditorPlugin::definition(const return *m_definitions.constFind(id); } -bool GenericEditorPlugin::isBuildingDefinition(const QString &id) const +bool Manager::isBuildingDefinition(const QString &id) const { return m_isBuilding.contains(id); } -void GenericEditorPlugin::registerMimeTypes() +void Manager::registerMimeTypes() { QFuture future = - QtConcurrent::run(&GenericEditorPlugin::gatherDefinitionsMimeTypes, this); + QtConcurrent::run(&Manager::gatherDefinitionsMimeTypes, this); m_watcher.setFuture(future); connect(&m_watcher, SIGNAL(resultReadyAt(int)), this, SLOT(registerMimeType(int))); } -void GenericEditorPlugin::gatherDefinitionsMimeTypes(QFutureInterface &future) +void Manager::gatherDefinitionsMimeTypes(QFutureInterface &future) { QDir definitionsDir(Core::ICore::instance()->resourcePath() + QLatin1String("/generic-highlighter")); @@ -208,14 +169,14 @@ void GenericEditorPlugin::gatherDefinitionsMimeTypes(QFutureInterfacemimeDatabase()->addMimeType(mimeType); - m_factory->m_mimeTypes.append(mimeType.type()); + TextEditorPlugin::instance()->editorFactory()->addMimeType(mimeType.type()); } -void GenericEditorPlugin::parseDefinitionMetadata(const QFileInfo &fileInfo, +void Manager::parseDefinitionMetadata(const QFileInfo &fileInfo, QString *comment, QStringList *mimeTypes, QStringList *patterns) @@ -273,5 +234,3 @@ void GenericEditorPlugin::parseDefinitionMetadata(const QFileInfo &fileInfo, reader.clear(); definitionFile.close(); } - -Q_EXPORT_PLUGIN(GenericEditorPlugin) diff --git a/src/plugins/genericeditor/genericeditorplugin.h b/src/plugins/texteditor/generichighlighter/manager.h similarity index 77% rename from src/plugins/genericeditor/genericeditorplugin.h rename to src/plugins/texteditor/generichighlighter/manager.h index 43a6742ef96..f5663dc4111 100644 --- a/src/plugins/genericeditor/genericeditorplugin.h +++ b/src/plugins/texteditor/generichighlighter/manager.h @@ -27,15 +27,12 @@ ** **************************************************************************/ -#ifndef GENERICEDITORPLUGIN_H -#define GENERICEDITORPLUGIN_H +#ifndef MANAGER_H +#define MANAGER_H #include -#include -#include #include -#include #include #include #include @@ -48,27 +45,16 @@ class QStringList; template class QFutureInterface; QT_END_NAMESPACE -namespace GenericEditor { +namespace TextEditor { namespace Internal { class HighlightDefinition; -class Editor; -class EditorFactory; -class GenericEditorPlugin : public ExtensionSystem::IPlugin +class Manager : public QObject { Q_OBJECT - -public: - GenericEditorPlugin(); - virtual ~GenericEditorPlugin(); - - static GenericEditorPlugin *instance(); - - virtual bool initialize(const QStringList &arguments, QString *errorString); - virtual void extensionsInitialized(); - - void initializeEditor(Editor *editor); +public: + static Manager *instance(); QString definitionIdByName(const QString &name) const; QString definitionIdByMimeType(const QString &mimeType) const; @@ -80,9 +66,8 @@ private slots: void registerMimeType(int index) const; private: - Q_DISABLE_COPY(GenericEditorPlugin) - - static GenericEditorPlugin *m_instance; + Manager(); + Q_DISABLE_COPY(Manager) void gatherDefinitionsMimeTypes(QFutureInterface &future); void parseDefinitionMetadata(const QFileInfo &fileInfo, @@ -99,10 +84,6 @@ private: }; PriorityCompare m_priorityComp; - TextEditor::TextEditorActionHandler *m_actionHandler; - - EditorFactory *m_factory; - QFutureWatcher m_watcher; QHash m_idByName; @@ -112,6 +93,6 @@ private: }; } // namespace Internal -} // namespace GenericEditor +} // namespace TextEditor -#endif // GENERICEDITORPLUGIN_H +#endif // MANAGER_H diff --git a/src/plugins/genericeditor/progressdata.cpp b/src/plugins/texteditor/generichighlighter/progressdata.cpp similarity index 98% rename from src/plugins/genericeditor/progressdata.cpp rename to src/plugins/texteditor/generichighlighter/progressdata.cpp index f751454bfbc..12c76079d84 100644 --- a/src/plugins/genericeditor/progressdata.cpp +++ b/src/plugins/texteditor/generichighlighter/progressdata.cpp @@ -31,7 +31,7 @@ #include -using namespace GenericEditor; +using namespace TextEditor; using namespace Internal; ProgressData::ProgressData() : diff --git a/src/plugins/genericeditor/progressdata.h b/src/plugins/texteditor/generichighlighter/progressdata.h similarity index 97% rename from src/plugins/genericeditor/progressdata.h rename to src/plugins/texteditor/generichighlighter/progressdata.h index 6d3d35e95b5..a621c15dc75 100644 --- a/src/plugins/genericeditor/progressdata.h +++ b/src/plugins/texteditor/generichighlighter/progressdata.h @@ -32,7 +32,7 @@ #include -namespace GenericEditor { +namespace TextEditor { namespace Internal { class ProgressData @@ -67,6 +67,6 @@ private: }; } // namespace Internal -} // namespace GenericEditor +} // namespace TextEditor #endif // PROGRESSDATA_H diff --git a/src/plugins/genericeditor/reuse.h b/src/plugins/texteditor/generichighlighter/reuse.h similarity index 97% rename from src/plugins/genericeditor/reuse.h rename to src/plugins/texteditor/generichighlighter/reuse.h index 019f0e0e443..197e3042d98 100644 --- a/src/plugins/genericeditor/reuse.h +++ b/src/plugins/texteditor/generichighlighter/reuse.h @@ -36,7 +36,7 @@ #include #include -namespace GenericEditor { +namespace TextEditor { namespace Internal { inline bool toBool(const QString &s) @@ -95,6 +95,6 @@ inline void setStartCharacter(QChar &c, const QString &character) } } // namespace Internal -} // namespace GenericEditor +} // namespace TextEditor #endif // REUSE_H diff --git a/src/plugins/genericeditor/rule.cpp b/src/plugins/texteditor/generichighlighter/rule.cpp similarity index 99% rename from src/plugins/genericeditor/rule.cpp rename to src/plugins/texteditor/generichighlighter/rule.cpp index 7c09818571e..1ca7349c6aa 100644 --- a/src/plugins/genericeditor/rule.cpp +++ b/src/plugins/texteditor/generichighlighter/rule.cpp @@ -37,7 +37,7 @@ #include -using namespace GenericEditor; +using namespace TextEditor; using namespace Internal; const QLatin1Char Rule::kBackSlash('\\'); diff --git a/src/plugins/genericeditor/rule.h b/src/plugins/texteditor/generichighlighter/rule.h similarity index 98% rename from src/plugins/genericeditor/rule.h rename to src/plugins/texteditor/generichighlighter/rule.h index c27d5b09026..a53b2f8e5c4 100644 --- a/src/plugins/genericeditor/rule.h +++ b/src/plugins/texteditor/generichighlighter/rule.h @@ -34,7 +34,7 @@ #include #include -namespace GenericEditor { +namespace TextEditor { namespace Internal { class ProgressData; @@ -155,6 +155,6 @@ private: }; } // namespace Internal -} // namespace GenericEditor +} // namespace TextEditor #endif // RULE_H diff --git a/src/plugins/genericeditor/specificrules.cpp b/src/plugins/texteditor/generichighlighter/specificrules.cpp similarity index 99% rename from src/plugins/genericeditor/specificrules.cpp rename to src/plugins/texteditor/generichighlighter/specificrules.cpp index 41def9aa25a..6fe4269367e 100644 --- a/src/plugins/genericeditor/specificrules.cpp +++ b/src/plugins/texteditor/generichighlighter/specificrules.cpp @@ -35,7 +35,7 @@ #include -using namespace GenericEditor; +using namespace TextEditor; using namespace Internal; namespace { diff --git a/src/plugins/genericeditor/specificrules.h b/src/plugins/texteditor/generichighlighter/specificrules.h similarity index 99% rename from src/plugins/genericeditor/specificrules.h rename to src/plugins/texteditor/generichighlighter/specificrules.h index 108f88a4073..7ec2552dad3 100644 --- a/src/plugins/genericeditor/specificrules.h +++ b/src/plugins/texteditor/generichighlighter/specificrules.h @@ -38,7 +38,7 @@ #include #include -namespace GenericEditor { +namespace TextEditor { namespace Internal { class KeywordList; @@ -283,6 +283,6 @@ private: }; } // namespace Internal -} // namespace GenericEditor +} // namespace TextEditor #endif // SPECIFICRULES_H diff --git a/src/plugins/texteditor/plaintexteditor.cpp b/src/plugins/texteditor/plaintexteditor.cpp index 257280b0b3c..2c748b07384 100644 --- a/src/plugins/texteditor/plaintexteditor.cpp +++ b/src/plugins/texteditor/plaintexteditor.cpp @@ -31,9 +31,20 @@ #include "tabsettings.h" #include "texteditorconstants.h" #include "texteditorplugin.h" +#include "texteditorsettings.h" +#include "basetextdocument.h" +#include "highlightdefinition.h" +#include "highlighter.h" +#include "highlighterexception.h" +#include "manager.h" #include #include +#include +#include + +#include +#include using namespace TextEditor; using namespace TextEditor::Internal; @@ -54,8 +65,11 @@ PlainTextEditor::PlainTextEditor(QWidget *parent) setRequestMarkEnabled(false); setLineSeparatorsAllowed(true); - setMimeType(QLatin1String(TextEditor::Constants::C_TEXTEDITOR_MIMETYPE_TEXT)); setDisplayName(tr(Core::Constants::K_DEFAULT_TEXT_EDITOR_DISPLAY_NAME)); + + m_commentDefinition.clearCommentStyles(); + + connect(file(), SIGNAL(changed()), this, SLOT(configure())); } QList PlainTextEditorEditable::context() const @@ -76,7 +90,56 @@ QString PlainTextEditorEditable::id() const return QLatin1String(Core::Constants::K_DEFAULT_TEXT_EDITOR_ID); } +void PlainTextEditor::unCommentSelection() +{ + Utils::unCommentSelection(this, m_commentDefinition); +} + +void PlainTextEditor::setFontSettings(const TextEditor::FontSettings & fs) +{ + TextEditor::BaseTextEditor::setFontSettings(fs); + + Highlighter *highlighter = static_cast(baseTextDocument()->syntaxHighlighter()); + if (!highlighter) + return; + + highlighter->configureFormats(fs); + highlighter->rehighlight(); +} + +void PlainTextEditor::configure() +{ + const QString &mimeType = Core::ICore::instance()->mimeDatabase()->findByFile( + QFileInfo(file()->fileName())).type(); + baseTextDocument()->setMimeType(mimeType); + + const QString &definitionId = Manager::instance()->definitionIdByMimeType(mimeType); + if (!definitionId.isEmpty()) { + try { + const QSharedPointer &definition = + Manager::instance()->definition(definitionId); + + 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()); + m_commentDefinition.setMultiLineStart(definition->multiLineCommentStart()); + m_commentDefinition.setMultiLineEnd(definition->multiLineCommentEnd()); + } catch (const HighlighterException &) { + } + } + + // @todo: Indentation specification through the definition files is not really being + // used because Kate recommends to configure indentation through another feature. + // Maybe we should provide something similar in Creator? For now, only normal + // indentation is supported. + m_indenter.reset(new TextEditor::NormalIndenter); +} + void PlainTextEditor::indentBlock(QTextDocument *doc, QTextBlock block, QChar typedChar) { - m_indenter.indentBlock(doc, block, typedChar, tabSettings()); + m_indenter->indentBlock(doc, block, typedChar, tabSettings()); } diff --git a/src/plugins/texteditor/plaintexteditor.h b/src/plugins/texteditor/plaintexteditor.h index f2c5673fb04..fdc85423d2c 100644 --- a/src/plugins/texteditor/plaintexteditor.h +++ b/src/plugins/texteditor/plaintexteditor.h @@ -33,7 +33,10 @@ #include "basetexteditor.h" #include "normalindenter.h" +#include + #include +#include namespace TextEditor { @@ -61,13 +64,20 @@ class TEXTEDITOR_EXPORT PlainTextEditor : public BaseTextEditor public: PlainTextEditor(QWidget *parent); +public slots: + virtual void unCommentSelection(); + virtual void setFontSettings(const TextEditor::FontSettings &); + +private slots: + void configure(); + protected: virtual BaseTextEditorEditable *createEditableInterface() { return new PlainTextEditorEditable(this); } virtual void indentBlock(QTextDocument *doc, QTextBlock block, QChar typedChar); private: - // Indent a text block based on previous line. - NormalIndenter m_indenter; + Utils::CommentDefinition m_commentDefinition; + QScopedPointer m_indenter; }; } // namespace TextEditor diff --git a/src/plugins/texteditor/plaintexteditorfactory.cpp b/src/plugins/texteditor/plaintexteditorfactory.cpp index 3a960bc180e..7a219973955 100644 --- a/src/plugins/texteditor/plaintexteditorfactory.cpp +++ b/src/plugins/texteditor/plaintexteditorfactory.cpp @@ -44,7 +44,8 @@ PlainTextEditorFactory::PlainTextEditorFactory(QObject *parent) { m_actionHandler = new TextEditorActionHandler( QLatin1String(TextEditor::Constants::C_TEXTEDITOR), - TextEditorActionHandler::Format); + TextEditorActionHandler::Format | + TextEditorActionHandler::UnCommentSelection); m_mimeTypes << QLatin1String(TextEditor::Constants::C_TEXTEDITOR_MIMETYPE_TEXT); } @@ -76,6 +77,11 @@ Core::IEditor *PlainTextEditorFactory::createEditor(QWidget *parent) return rc->editableInterface(); } +void PlainTextEditorFactory::addMimeType(const QString &type) +{ + m_mimeTypes.append(type); +} + QStringList PlainTextEditorFactory::mimeTypes() const { return m_mimeTypes; diff --git a/src/plugins/texteditor/plaintexteditorfactory.h b/src/plugins/texteditor/plaintexteditorfactory.h index d55f4808afb..a01a80f7f11 100644 --- a/src/plugins/texteditor/plaintexteditorfactory.h +++ b/src/plugins/texteditor/plaintexteditorfactory.h @@ -50,6 +50,7 @@ public: PlainTextEditorFactory(QObject *parent = 0); virtual ~PlainTextEditorFactory(); + void addMimeType(const QString &type); virtual QStringList mimeTypes() const; //Core::IEditorFactory QString id() const; diff --git a/src/plugins/texteditor/texteditor.pro b/src/plugins/texteditor/texteditor.pro index bf64eb51c18..4892ff29925 100644 --- a/src/plugins/texteditor/texteditor.pro +++ b/src/plugins/texteditor/texteditor.pro @@ -1,8 +1,11 @@ TEMPLATE = lib TARGET = TextEditor DEFINES += TEXTEDITOR_LIBRARY +QT += xml include(../../qtcreatorplugin.pri) include(texteditor_dependencies.pri) +INCLUDEPATH += generichighlighter +DEPENDPATH += generichighlighter SOURCES += texteditorplugin.cpp \ textfilewizard.cpp \ plaintexteditor.cpp \ @@ -37,7 +40,19 @@ SOURCES += texteditorplugin.cpp \ basetextdocumentlayout.cpp \ completionsettings.cpp \ normalindenter.cpp \ - indenter.cpp + indenter.cpp \ + generichighlighter/itemdata.cpp \ + generichighlighter/specificrules.cpp \ + generichighlighter/rule.cpp \ + generichighlighter/dynamicrule.cpp \ + generichighlighter/context.cpp \ + generichighlighter/includerulesinstruction.cpp \ + generichighlighter/progressdata.cpp \ + generichighlighter/keywordlist.cpp \ + generichighlighter/highlightdefinition.cpp \ + generichighlighter/highlighter.cpp \ + generichighlighter/manager.cpp \ + generichighlighter/highlightdefinitionhandler.cpp HEADERS += texteditorplugin.h \ textfilewizard.h \ @@ -77,7 +92,22 @@ HEADERS += texteditorplugin.h \ basetextdocumentlayout.h \ completionsettings.h \ normalindenter.h \ - indenter.h + indenter.h \ + generichighlighter/reuse.h \ + generichighlighter/itemdata.h \ + generichighlighter/specificrules.h \ + generichighlighter/rule.h \ + generichighlighter/reuse.h \ + generichighlighter/dynamicrule.h \ + generichighlighter/context.h \ + generichighlighter/includerulesinstruction.h \ + generichighlighter/progressdata.h \ + generichighlighter/keywordlist.h \ + generichighlighter/highlighterexception.h \ + generichighlighter/highlightdefinition.h \ + generichighlighter/highlighter.h \ + generichighlighter/manager.h \ + generichighlighter/highlightdefinitionhandler.h FORMS += behaviorsettingspage.ui \ diff --git a/src/plugins/texteditor/texteditorplugin.cpp b/src/plugins/texteditor/texteditorplugin.cpp index dca81bed5a8..058fcd63509 100644 --- a/src/plugins/texteditor/texteditorplugin.cpp +++ b/src/plugins/texteditor/texteditorplugin.cpp @@ -39,6 +39,7 @@ #include "plaintexteditorfactory.h" #include "plaintexteditor.h" #include "storagesettings.h" +#include "manager.h" #include #include @@ -70,6 +71,9 @@ TextEditorPlugin::TextEditorPlugin() { QTC_ASSERT(!m_instance, return); m_instance = this; + + connect(Core::ICore::instance(), SIGNAL(coreOpened()), + Manager::instance(), SLOT(registerMimeTypes())); } TextEditorPlugin::~TextEditorPlugin() diff --git a/src/plugins/texteditor/texteditorplugin.h b/src/plugins/texteditor/texteditorplugin.h index 1fc4c10be77..93f8870e1fd 100644 --- a/src/plugins/texteditor/texteditorplugin.h +++ b/src/plugins/texteditor/texteditorplugin.h @@ -64,6 +64,7 @@ public: void initializeEditor(PlainTextEditor *editor); + PlainTextEditorFactory *editorFactory() { return m_editorFactory; } LineNumberFilter *lineNumberFilter() { return m_lineNumberFilter; } private slots: diff --git a/tests/auto/generichighlighter/specificrules/specificrules.pro b/tests/auto/generichighlighter/specificrules/specificrules.pro index 4c36644ab00..889ff8a7376 100644 --- a/tests/auto/generichighlighter/specificrules/specificrules.pro +++ b/tests/auto/generichighlighter/specificrules/specificrules.pro @@ -3,15 +3,15 @@ QT += testlib PLUGINSDIR = ../../../../src/plugins SOURCES += tst_specificrules.cpp \ - $$PLUGINSDIR/genericeditor/context.cpp \ - $$PLUGINSDIR/genericeditor/dynamicrule.cpp \ - $$PLUGINSDIR/genericeditor/rule.cpp \ - $$PLUGINSDIR/genericeditor/specificrules.cpp \ - $$PLUGINSDIR/genericeditor/progressdata.cpp \ - $$PLUGINSDIR/genericeditor/highlightdefinition.cpp \ - $$PLUGINSDIR/genericeditor/keywordlist.cpp \ - $$PLUGINSDIR/genericeditor/itemdata.cpp + $$PLUGINSDIR/texteditor/generichighlighter/context.cpp \ + $$PLUGINSDIR/texteditor/generichighlighter/dynamicrule.cpp \ + $$PLUGINSDIR/texteditor/generichighlighter/rule.cpp \ + $$PLUGINSDIR/texteditor/generichighlighter/specificrules.cpp \ + $$PLUGINSDIR/texteditor/generichighlighter/progressdata.cpp \ + $$PLUGINSDIR/texteditor/generichighlighter/highlightdefinition.cpp \ + $$PLUGINSDIR/texteditor/generichighlighter/keywordlist.cpp \ + $$PLUGINSDIR/texteditor/generichighlighter/itemdata.cpp -INCLUDEPATH += $$PLUGINSDIR $$UTILSDIR +INCLUDEPATH += $$PLUGINSDIR TARGET=tst_$$TARGET diff --git a/tests/auto/generichighlighter/specificrules/tst_specificrules.cpp b/tests/auto/generichighlighter/specificrules/tst_specificrules.cpp index ee94024adf0..7fa6c5048ba 100644 --- a/tests/auto/generichighlighter/specificrules/tst_specificrules.cpp +++ b/tests/auto/generichighlighter/specificrules/tst_specificrules.cpp @@ -27,14 +27,14 @@ ** **************************************************************************/ -#include -#include -#include -#include +#include +#include +#include +#include #include -using namespace GenericEditor; +using namespace TextEditor; using namespace Internal; class tst_SpecificRules : public QObject