diff options
Diffstat (limited to 'src/plugins/pythoneditor')
7 files changed, 114 insertions, 0 deletions
diff --git a/src/plugins/pythoneditor/pythoneditor.pro b/src/plugins/pythoneditor/pythoneditor.pro index 0e7e02672f..9d87e03a12 100644 --- a/src/plugins/pythoneditor/pythoneditor.pro +++ b/src/plugins/pythoneditor/pythoneditor.pro @@ -18,6 +18,7 @@ HEADERS += \ wizard/pythonclasswizarddialog.h \ wizard/pythonsourcegenerator.h \ tools/pythonhighlighter.h \ + tools/pythonhighlighterfactory.h \ tools/pythonindenter.h \ tools/lexical/pythonformattoken.h \ tools/lexical/pythonscanner.h \ @@ -34,5 +35,6 @@ SOURCES += \ wizard/pythonclassnamepage.cpp \ wizard/pythonsourcegenerator.cpp \ tools/pythonhighlighter.cpp \ + tools/pythonhighlighterfactory.cpp \ tools/pythonindenter.cpp \ tools/lexical/pythonscanner.cpp diff --git a/src/plugins/pythoneditor/pythoneditor.qbs b/src/plugins/pythoneditor/pythoneditor.qbs index 5637b891b1..3b0a4899a6 100644 --- a/src/plugins/pythoneditor/pythoneditor.qbs +++ b/src/plugins/pythoneditor/pythoneditor.qbs @@ -32,6 +32,7 @@ QtcPlugin { "lexical/pythonscanner.h", "lexical/pythonscanner.cpp", "lexical/sourcecodestream.h", "pythonhighlighter.h", "pythonhighlighter.cpp", + "pythonhighlighterfactory.h", "pythonhighlighterfactory.cpp", "pythonindenter.cpp", "pythonindenter.h" ] } diff --git a/src/plugins/pythoneditor/pythoneditorplugin.cpp b/src/plugins/pythoneditor/pythoneditorplugin.cpp index b49ae92f48..1f8ec02163 100644 --- a/src/plugins/pythoneditor/pythoneditorplugin.cpp +++ b/src/plugins/pythoneditor/pythoneditorplugin.cpp @@ -33,6 +33,7 @@ #include "wizard/pythonclasswizard.h" #include "pythoneditorwidget.h" #include "pythoneditorfactory.h" +#include "tools/pythonhighlighterfactory.h" #include <coreplugin/icore.h> #include <coreplugin/coreconstants.h> @@ -252,6 +253,7 @@ bool PythonEditorPlugin::initialize( //////////////////////////////////////////////////////////////////////////// addAutoReleasedObject(new FileWizard(Core::ICore::instance())); addAutoReleasedObject(new ClassWizard(Core::ICore::instance())); + addAutoReleasedObject(new Internal::PythonHighlighterFactory); return true; } diff --git a/src/plugins/pythoneditor/tools/pythonhighlighter.cpp b/src/plugins/pythoneditor/tools/pythonhighlighter.cpp index ea809c4e6f..32c59ef6b0 100644 --- a/src/plugins/pythoneditor/tools/pythonhighlighter.cpp +++ b/src/plugins/pythoneditor/tools/pythonhighlighter.cpp @@ -65,10 +65,21 @@ using namespace PythonEditor::Internal; * @endcode */ +PythonHighlighter::PythonHighlighter(QTextDocument *parent) : + TextEditor::SyntaxHighlighter(parent) +{ + init(); +} + /// New instance created when opening any document in editor PythonHighlighter::PythonHighlighter(TextEditor::BaseTextDocument *parent) : TextEditor::SyntaxHighlighter(parent) { + init(); +} + +void PythonHighlighter::init() +{ static QVector<TextEditor::TextStyle> categories; if (categories.isEmpty()) { categories << TextEditor::C_NUMBER diff --git a/src/plugins/pythoneditor/tools/pythonhighlighter.h b/src/plugins/pythoneditor/tools/pythonhighlighter.h index 41b7eb6c71..d5287fc0b5 100644 --- a/src/plugins/pythoneditor/tools/pythonhighlighter.h +++ b/src/plugins/pythoneditor/tools/pythonhighlighter.h @@ -40,6 +40,7 @@ class PythonHighlighter : public TextEditor::SyntaxHighlighter { Q_OBJECT public: + explicit PythonHighlighter(QTextDocument *parent = 0); explicit PythonHighlighter(TextEditor::BaseTextDocument *parent); virtual ~PythonHighlighter(); @@ -49,6 +50,7 @@ protected: private: int highlightLine(const QString &text, int initialState); void highlightImport(Internal::Scanner &scanner); + void init(); }; } // namespace PythonEditor diff --git a/src/plugins/pythoneditor/tools/pythonhighlighterfactory.cpp b/src/plugins/pythoneditor/tools/pythonhighlighterfactory.cpp new file mode 100644 index 0000000000..3ea998d48e --- /dev/null +++ b/src/plugins/pythoneditor/tools/pythonhighlighterfactory.cpp @@ -0,0 +1,45 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** 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. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "pythonhighlighterfactory.h" +#include "pythoneditorconstants.h" +#include "tools/pythonhighlighter.h" + +using namespace PythonEditor::Internal; + +PythonHighlighterFactory::PythonHighlighterFactory() +{ + setId(Constants::C_PYTHONEDITOR_ID); + addMimeType(QLatin1String(Constants::C_PY_MIMETYPE)); +} + +TextEditor::SyntaxHighlighter *PythonHighlighterFactory::createHighlighter() const +{ + return new PythonHighlighter; +} diff --git a/src/plugins/pythoneditor/tools/pythonhighlighterfactory.h b/src/plugins/pythoneditor/tools/pythonhighlighterfactory.h new file mode 100644 index 0000000000..fa7dc02825 --- /dev/null +++ b/src/plugins/pythoneditor/tools/pythonhighlighterfactory.h @@ -0,0 +1,51 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** 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. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef PYTHONHIGHLIGHTERFACTORY_H +#define PYTHONHIGHLIGHTERFACTORY_H + +#include <texteditor/ihighlighterfactory.h> + +namespace PythonEditor { +namespace Internal { + +class PythonHighlighterFactory : public TextEditor::IHighlighterFactory +{ + Q_OBJECT + +public: + PythonHighlighterFactory(); + + virtual TextEditor::SyntaxHighlighter *createHighlighter() const; +}; + +} // namespace Internal +} // namespace PythonEditor + +#endif // PYTHONHIGHLIGHTERFACTORY_H |