diff --git a/src/plugins/glsleditor/glsleditor.cpp b/src/plugins/glsleditor/glsleditor.cpp index c9fcbe1ebd4..7b7f17191b2 100644 --- a/src/plugins/glsleditor/glsleditor.cpp +++ b/src/plugins/glsleditor/glsleditor.cpp @@ -28,7 +28,6 @@ ****************************************************************************/ #include "glsleditor.h" -#include "glsleditoreditable.h" #include "glsleditorconstants.h" #include "glsleditorplugin.h" #include "glslhighlighter.h" @@ -44,20 +43,29 @@ #include #include -#include #include #include #include +#include #include + #include -#include -#include -#include +#include + #include +#include +#include +#include +#include + #include + #include +#include #include +#include +#include #include #include #include @@ -65,16 +73,17 @@ #include #include +using namespace TextEditor; using namespace GLSL; -using namespace GLSLEditor; -using namespace GLSLEditor::Internal; +using namespace GLSLEditor::Constants; + +namespace GLSLEditor { +namespace Internal { enum { UPDATE_DOCUMENT_DEFAULT_INTERVAL = 150 }; -namespace { - class CreateRanges: protected GLSL::Visitor { QTextDocument *textDocument; @@ -100,14 +109,11 @@ protected: } }; -} // end of anonymous namespace - Document::Document() : _engine(0) , _ast(0) , _globalScope(0) { - } Document::~Document() @@ -133,24 +139,21 @@ void Document::addRange(const QTextCursor &cursor, GLSL::Scope *scope) _cursors.append(c); } -GlslEditorWidget::GlslEditorWidget(const TextEditor::BaseTextDocumentPtr &doc) +GlslEditorWidget::GlslEditorWidget() { - setTextDocument(doc); setAutoCompleter(new GLSLCompleter); - m_outlineCombo = 0; setParenthesesMatchingEnabled(true); setMarksVisible(true); setCodeFoldingSupported(true); - m_updateDocumentTimer = new QTimer(this); - m_updateDocumentTimer->setInterval(UPDATE_DOCUMENT_DEFAULT_INTERVAL); - m_updateDocumentTimer->setSingleShot(true); - connect(m_updateDocumentTimer, SIGNAL(timeout()), this, SLOT(updateDocumentNow())); + m_updateDocumentTimer.setInterval(UPDATE_DOCUMENT_DEFAULT_INTERVAL); + m_updateDocumentTimer.setSingleShot(true); + connect(&m_updateDocumentTimer, &QTimer::timeout, + this, &GlslEditorWidget::updateDocumentNow); - connect(this, SIGNAL(textChanged()), this, SLOT(updateDocument())); - - new Highlighter(textDocument()); + connect(this, &QPlainTextEdit::textChanged, + [this]() { m_updateDocumentTimer.start(); }); m_outlineCombo = new QComboBox; m_outlineCombo->setMinimumContentsLength(22); @@ -171,7 +174,7 @@ GlslEditorWidget::GlslEditorWidget(const TextEditor::BaseTextDocumentPtr &doc) policy.setHorizontalPolicy(QSizePolicy::Expanding); m_outlineCombo->setSizePolicy(policy); - insertExtraToolBarWidget(TextEditor::BaseTextEditorWidget::Left, m_outlineCombo); + insertExtraToolBarWidget(BaseTextEditorWidget::Left, m_outlineCombo); // if (m_modelManager) { // m_semanticHighlighter->setModelManager(m_modelManager); @@ -197,16 +200,10 @@ bool GlslEditorWidget::isOutdated() const return false; } -Core::IEditor *GlslEditor::duplicate() -{ - GlslEditorWidget *newEditor = new GlslEditorWidget(editorWidget()->textDocumentPtr()); - return newEditor->editor(); -} - bool GlslEditor::open(QString *errorString, const QString &fileName, const QString &realFileName) { textDocument()->setMimeType(Core::MimeDatabase::findByFile(QFileInfo(fileName)).type()); - bool b = TextEditor::BaseTextEditor::open(errorString, fileName, realFileName); + bool b = BaseTextEditor::open(errorString, fileName, realFileName); return b; } @@ -223,26 +220,21 @@ QString GlslEditorWidget::wordUnderCursor() const return word; } -TextEditor::BaseTextEditor *GlslEditorWidget::createEditor() +BaseTextEditor *GlslEditorWidget::createEditor() { - return new GlslEditor; -} - -void GlslEditorWidget::updateDocument() -{ - m_updateDocumentTimer->start(); + QTC_ASSERT("should not happen anymore" && false, return 0); } void GlslEditorWidget::updateDocumentNow() { - m_updateDocumentTimer->stop(); + m_updateDocumentTimer.stop(); int variant = languageVariant(textDocument()->mimeType()); const QString contents = toPlainText(); // get the code from the editor const QByteArray preprocessedCode = contents.toLatin1(); // ### use the QtCreator C++ preprocessor. Document::Ptr doc(new Document()); - GLSL::Engine *engine = new GLSL::Engine(); + Engine *engine = new GLSL::Engine(); doc->_engine = new GLSL::Engine(); Parser parser(doc->_engine, preprocessedCode.constData(), preprocessedCode.size(), variant); TranslationUnitAST *ast = parser.parse(); @@ -336,11 +328,10 @@ int GlslEditorWidget::languageVariant(const QString &type) return variant; } -TextEditor::IAssistInterface *GlslEditorWidget::createAssistInterface( - TextEditor::AssistKind kind, - TextEditor::AssistReason reason) const +IAssistInterface *GlslEditorWidget::createAssistInterface( + AssistKind kind, AssistReason reason) const { - if (kind == TextEditor::Completion) + if (kind == Completion) return new GLSLCompletionAssistInterface(document(), position(), editor()->document()->filePath(), @@ -349,3 +340,59 @@ TextEditor::IAssistInterface *GlslEditorWidget::createAssistInterface( m_glslDocument); return BaseTextEditorWidget::createAssistInterface(kind, reason); } + + +////////////////////////////////////////////////////////////////// +// +// GlslEditor +// +////////////////////////////////////////////////////////////////// + +GlslEditor::GlslEditor() +{ + addContext(C_GLSLEDITOR_ID); + setDuplicateSupported(true); + setCommentStyle(Utils::CommentDefinition::CppStyle); + setCompletionAssistProvider(ExtensionSystem::PluginManager::getObject()); + + setEditorCreator([]() { return new GlslEditor; }); + setWidgetCreator([]() { return new GlslEditorWidget; }); + + setDocumentCreator([]() -> BaseTextDocument * { + auto doc = new BaseTextDocument(C_GLSLEDITOR_ID); + doc->setIndenter(new GLSLIndenter); + new Highlighter(doc); + return doc; + }); +} + + +////////////////////////////////////////////////////////////////// +// +// GlslEditorFactory +// +////////////////////////////////////////////////////////////////// + +GlslEditorFactory::GlslEditorFactory() +{ + setId(C_GLSLEDITOR_ID); + setDisplayName(qApp->translate("OpenWith::Editors", C_GLSLEDITOR_DISPLAY_NAME)); + addMimeType(GLSL_MIMETYPE); + addMimeType(GLSL_MIMETYPE_VERT); + addMimeType(GLSL_MIMETYPE_FRAG); + addMimeType(GLSL_MIMETYPE_VERT_ES); + addMimeType(GLSL_MIMETYPE_FRAG_ES); + new TextEditorActionHandler(this, C_GLSLEDITOR_ID, + TextEditorActionHandler::Format + | TextEditorActionHandler::UnCommentSelection + | TextEditorActionHandler::UnCollapseAll); + +} + +Core::IEditor *GlslEditorFactory::createEditor() +{ + return new GlslEditor; +} + +} // namespace Internal +} // namespace GLSLEditor diff --git a/src/plugins/glsleditor/glsleditor.h b/src/plugins/glsleditor/glsleditor.h index 4e54005350d..35140e5bd64 100644 --- a/src/plugins/glsleditor/glsleditor.h +++ b/src/plugins/glsleditor/glsleditor.h @@ -31,13 +31,14 @@ #define GLSLEDITOR_H #include +#include #include #include +#include QT_BEGIN_NAMESPACE class QComboBox; -class QTimer; QT_END_NAMESPACE namespace GLSL { @@ -86,7 +87,7 @@ class GlslEditorWidget : public TextEditor::BaseTextEditorWidget Q_OBJECT public: - GlslEditorWidget(const TextEditor::BaseTextDocumentPtr &doc); + GlslEditorWidget(); int editorRevision() const; bool isOutdated() const; @@ -98,22 +99,38 @@ public: TextEditor::IAssistInterface *createAssistInterface(TextEditor::AssistKind assistKind, TextEditor::AssistReason reason) const; -private slots: - void updateDocument(); - void updateDocumentNow(); - -protected: +private: TextEditor::BaseTextEditor *createEditor(); -private: + void updateDocumentNow(); void setSelectedElements(); QString wordUnderCursor() const; - QTimer *m_updateDocumentTimer; + QTimer m_updateDocumentTimer; QComboBox *m_outlineCombo; Document::Ptr m_glslDocument; }; +class GlslEditor : public TextEditor::BaseTextEditor +{ + Q_OBJECT + +public: + GlslEditor(); + + bool open(QString *errorString, const QString &fileName, const QString &realFileName); +}; + +class GlslEditorFactory : public Core::IEditorFactory +{ + Q_OBJECT + +public: + GlslEditorFactory(); + + Core::IEditor *createEditor(); +}; + } // namespace Internal } // namespace GLSLEditor diff --git a/src/plugins/glsleditor/glsleditor.pro b/src/plugins/glsleditor/glsleditor.pro index ad353b0b462..579e483a099 100644 --- a/src/plugins/glsleditor/glsleditor.pro +++ b/src/plugins/glsleditor/glsleditor.pro @@ -6,8 +6,6 @@ DEFINES += \ HEADERS += \ glsleditor.h \ glsleditorconstants.h \ -glsleditoreditable.h \ -glsleditorfactory.h \ glsleditorplugin.h \ glslfilewizard.h \ glslhighlighter.h \ @@ -19,8 +17,6 @@ glslhoverhandler.h \ SOURCES += \ glsleditor.cpp \ -glsleditoreditable.cpp \ -glsleditorfactory.cpp \ glsleditorplugin.cpp \ glslfilewizard.cpp \ glslhighlighter.cpp \ diff --git a/src/plugins/glsleditor/glsleditor.qbs b/src/plugins/glsleditor/glsleditor.qbs index 79f0dd0a6af..c1b1b4da192 100644 --- a/src/plugins/glsleditor/glsleditor.qbs +++ b/src/plugins/glsleditor/glsleditor.qbs @@ -24,10 +24,6 @@ QtcPlugin { "glsleditor.h", "glsleditor.qrc", "glsleditorconstants.h", - "glsleditoreditable.cpp", - "glsleditoreditable.h", - "glsleditorfactory.cpp", - "glsleditorfactory.h", "glsleditorplugin.cpp", "glsleditorplugin.h", "glslfilewizard.cpp", diff --git a/src/plugins/glsleditor/glsleditorconstants.h b/src/plugins/glsleditor/glsleditorconstants.h index d0ffb394075..cd7a94ea4c5 100644 --- a/src/plugins/glsleditor/glsleditorconstants.h +++ b/src/plugins/glsleditor/glsleditorconstants.h @@ -35,7 +35,6 @@ namespace GLSLEditor { namespace Constants { -// menus const char M_CONTEXT[] = "GLSL Editor.ContextMenu"; const char M_TOOLS_GLSL[] = "GLSLEditor.Tools.Menu"; diff --git a/src/plugins/glsleditor/glsleditoreditable.cpp b/src/plugins/glsleditor/glsleditoreditable.cpp deleted file mode 100644 index e1ec3172e49..00000000000 --- a/src/plugins/glsleditor/glsleditoreditable.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 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 "glsleditoreditable.h" -#include "glsleditorconstants.h" -#include "glslcompletionassist.h" -#include "glslautocompleter.h" - -#include - -#include - -#include - -namespace GLSLEditor { -namespace Internal { - -GlslEditor::GlslEditor() -{ - setContext(Core::Context(GLSLEditor::Constants::C_GLSLEDITOR_ID, - TextEditor::Constants::C_TEXTEDITOR)); - setDuplicateSupported(true); - setCommentStyle(Utils::CommentDefinition::CppStyle); - setCompletionAssistProvider(ExtensionSystem::PluginManager::getObject()); -} - -} // namespace Internal -} // namespace GLSLEditor diff --git a/src/plugins/glsleditor/glsleditoreditable.h b/src/plugins/glsleditor/glsleditoreditable.h deleted file mode 100644 index 9c40192bbab..00000000000 --- a/src/plugins/glsleditor/glsleditoreditable.h +++ /dev/null @@ -1,52 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 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 GLSLEDITOREDITABLE_H -#define GLSLEDITOREDITABLE_H - -#include - -namespace GLSLEditor { -namespace Internal { - -class GlslEditor : public TextEditor::BaseTextEditor -{ - Q_OBJECT - -public: - GlslEditor(); - - Core::IEditor *duplicate(); - bool open(QString *errorString, const QString &fileName, const QString &realFileName); -}; - -} // namespace Internal -} // namespace GLSLEditor - -#endif // GLSLEDITOREDITABLE_H diff --git a/src/plugins/glsleditor/glsleditorfactory.cpp b/src/plugins/glsleditor/glsleditorfactory.cpp deleted file mode 100644 index edadb40181d..00000000000 --- a/src/plugins/glsleditor/glsleditorfactory.cpp +++ /dev/null @@ -1,73 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 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 "glsleditorfactory.h" -#include "glsleditoreditable.h" -#include "glsleditor.h" -#include "glsleditorconstants.h" -#include "glsleditorplugin.h" -#include "glslindenter.h" - -#include -#include - -#include -#include -#include - -#include -#include - -using namespace GLSLEditor::Internal; -using namespace GLSLEditor::Constants; - -GLSLEditorFactory::GLSLEditorFactory(QObject *parent) - : Core::IEditorFactory(parent) -{ - setId(C_GLSLEDITOR_ID); - setDisplayName(qApp->translate("OpenWith::Editors", C_GLSLEDITOR_DISPLAY_NAME)); - addMimeType(GLSLEditor::Constants::GLSL_MIMETYPE); - addMimeType(GLSLEditor::Constants::GLSL_MIMETYPE_VERT); - addMimeType(GLSLEditor::Constants::GLSL_MIMETYPE_FRAG); - addMimeType(GLSLEditor::Constants::GLSL_MIMETYPE_VERT_ES); - addMimeType(GLSLEditor::Constants::GLSL_MIMETYPE_FRAG_ES); - new TextEditor::TextEditorActionHandler(this, Constants::C_GLSLEDITOR_ID, - TextEditor::TextEditorActionHandler::Format - | TextEditor::TextEditorActionHandler::UnCommentSelection - | TextEditor::TextEditorActionHandler::UnCollapseAll); - -} - -Core::IEditor *GLSLEditorFactory::createEditor() -{ - TextEditor::BaseTextDocumentPtr doc(new TextEditor::BaseTextDocument(C_GLSLEDITOR_ID)); - doc->setIndenter(new GLSLIndenter); - GlslEditorWidget *rc = new GlslEditorWidget(doc); - return rc->editor(); -} diff --git a/src/plugins/glsleditor/glsleditorfactory.h b/src/plugins/glsleditor/glsleditorfactory.h deleted file mode 100644 index 698fa77bd1e..00000000000 --- a/src/plugins/glsleditor/glsleditorfactory.h +++ /dev/null @@ -1,51 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 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 GLSLEDITORFACTORY_H -#define GLSLEDITORFACTORY_H - -#include - -namespace GLSLEditor { -namespace Internal { - -class GLSLEditorFactory : public Core::IEditorFactory -{ - Q_OBJECT - -public: - GLSLEditorFactory(QObject *parent); - - Core::IEditor *createEditor(); -}; - -} // namespace Internal -} // namespace GLSLEditor - -#endif // GLSLEDITORFACTORY_H diff --git a/src/plugins/glsleditor/glsleditorplugin.cpp b/src/plugins/glsleditor/glsleditorplugin.cpp index 8dbcf99044d..aba368deceb 100644 --- a/src/plugins/glsleditor/glsleditorplugin.cpp +++ b/src/plugins/glsleditor/glsleditorplugin.cpp @@ -28,42 +28,42 @@ ****************************************************************************/ #include "glsleditorplugin.h" +#include "glslcompletionassist.h" #include "glsleditor.h" #include "glsleditorconstants.h" -#include "glsleditorfactory.h" #include "glslfilewizard.h" -#include "glslhoverhandler.h" -#include "glslcompletionassist.h" #include "glslhighlighter.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "glslhoverhandler.h" #include #include #include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include + +#include + #include +#include +#include +#include +#include +#include +#include using namespace Core; using namespace TextEditor; @@ -75,7 +75,6 @@ class GLSLEditorPluginPrivate { public: GLSLEditorPluginPrivate() : - m_editor(0), m_glsl_120_frag(0), m_glsl_120_vert(0), m_glsl_120_common(0), @@ -94,7 +93,6 @@ public: delete m_glsl_es_100_common; } - GLSLEditorFactory *m_editor; QPointer m_currentTextEditable; GLSLEditorPlugin::InitFile *m_glsl_120_frag; @@ -121,7 +119,6 @@ GLSLEditorPlugin::GLSLEditorPlugin() GLSLEditorPlugin::~GLSLEditorPlugin() { - removeObject(dd->m_editor); delete dd; m_instance = 0; } @@ -131,14 +128,8 @@ bool GLSLEditorPlugin::initialize(const QStringList & /*arguments*/, QString *er if (!MimeDatabase::addMimeTypes(QLatin1String(":/glsleditor/GLSLEditor.mimetypes.xml"), errorMessage)) return false; -// m_modelManager = new ModelManager(this); -// addAutoReleasedObject(m_modelManager); - addAutoReleasedObject(new GLSLHoverHandler(this)); - - dd->m_editor = new GLSLEditorFactory(this); - addObject(dd->m_editor); - + addAutoReleasedObject(new GlslEditorFactory); addAutoReleasedObject(new GLSLCompletionAssistProvider); ActionContainer *contextMenu = ActionManager::createMenu(GLSLEditor::Constants::M_CONTEXT); diff --git a/src/plugins/glsleditor/glslhoverhandler.cpp b/src/plugins/glsleditor/glslhoverhandler.cpp index fc672467e94..cc9ee0ea339 100644 --- a/src/plugins/glsleditor/glslhoverhandler.cpp +++ b/src/plugins/glsleditor/glslhoverhandler.cpp @@ -29,7 +29,6 @@ #include "glslhoverhandler.h" #include "glsleditor.h" -#include "glsleditoreditable.h" #include #include @@ -38,7 +37,6 @@ #include #include -#include using namespace GLSLEditor; using namespace GLSLEditor::Internal;