diff options
author | hjk <hjk@qt.io> | 2024-01-11 18:10:56 +0100 |
---|---|---|
committer | hjk <hjk@qt.io> | 2024-01-11 17:28:55 +0000 |
commit | 1f1e31b4fc25124ca2205749deb925f8cada1c9b (patch) | |
tree | 0da8db43ed638f3cd1c6387aec28668bf0ff013a /src/plugins/glsleditor | |
parent | 7f419fdf6423ce1e166f6c2e5484598812b2a205 (diff) |
GlslEditor: Inline plugin class to .cpp
Not quite the standard setup yet, but getting closer.
Change-Id: Ifadc0b07b9d3f43381d5f49848c49bcc1d069861
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
Diffstat (limited to 'src/plugins/glsleditor')
-rw-r--r-- | src/plugins/glsleditor/glsleditor.cpp | 6 | ||||
-rw-r--r-- | src/plugins/glsleditor/glsleditorplugin.cpp | 136 | ||||
-rw-r--r-- | src/plugins/glsleditor/glsleditorplugin.h | 51 |
3 files changed, 93 insertions, 100 deletions
diff --git a/src/plugins/glsleditor/glsleditor.cpp b/src/plugins/glsleditor/glsleditor.cpp index 4e738f29f8..580f5b750e 100644 --- a/src/plugins/glsleditor/glsleditor.cpp +++ b/src/plugins/glsleditor/glsleditor.cpp @@ -240,14 +240,14 @@ void GlslEditorWidget::updateDocumentNow() Semantic sem; Scope *globalScope = new Namespace(); doc->_globalScope = globalScope; - const GlslEditorPlugin::InitFile *file = GlslEditorPlugin::shaderInit(variant); + const InitFile *file = shaderInit(variant); sem.translationUnit(file->ast(), globalScope, file->engine()); if (variant & Lexer::Variant_VertexShader) { - file = GlslEditorPlugin::vertexShaderInit(variant); + file = vertexShaderInit(variant); sem.translationUnit(file->ast(), globalScope, file->engine()); } if (variant & Lexer::Variant_FragmentShader) { - file = GlslEditorPlugin::fragmentShaderInit(variant); + file = fragmentShaderInit(variant); sem.translationUnit(file->ast(), globalScope, file->engine()); } sem.translationUnit(ast, globalScope, doc->_engine); diff --git a/src/plugins/glsleditor/glsleditorplugin.cpp b/src/plugins/glsleditor/glsleditorplugin.cpp index e84605f19c..f4bcdc8d97 100644 --- a/src/plugins/glsleditor/glsleditorplugin.cpp +++ b/src/plugins/glsleditor/glsleditorplugin.cpp @@ -20,6 +20,8 @@ #include <coreplugin/editormanager/editormanager.h> #include <coreplugin/icore.h> +#include <extensionsystem/iplugin.h> + #include <utils/fsengine/fileiconprovider.h> #include <utils/mimeconstants.h> @@ -28,21 +30,20 @@ using namespace Core; using namespace Utils; -namespace GlslEditor { -namespace Internal { +namespace GlslEditor::Internal { class GlslEditorPluginPrivate { public: - GlslEditorPlugin::InitFile m_glsl_330_frag{"glsl_330.frag"}; - GlslEditorPlugin::InitFile m_glsl_330_vert{"glsl_330.vert"}; - GlslEditorPlugin::InitFile m_glsl_330_common{"glsl_330_common.glsl"}; - GlslEditorPlugin::InitFile m_glsl_120_frag{"glsl_120.frag"}; - GlslEditorPlugin::InitFile m_glsl_120_vert{"glsl_120.vert"}; - GlslEditorPlugin::InitFile m_glsl_120_common{"glsl_120_common.glsl"}; - GlslEditorPlugin::InitFile m_glsl_es_100_frag{"glsl_es_100.frag"}; - GlslEditorPlugin::InitFile m_glsl_es_100_vert{"glsl_es_100.vert"}; - GlslEditorPlugin::InitFile m_glsl_es_100_common{"glsl_es_100_common.glsl"}; + InitFile m_glsl_330_frag{"glsl_330.frag"}; + InitFile m_glsl_330_vert{"glsl_330.vert"}; + InitFile m_glsl_330_common{"glsl_330_common.glsl"}; + InitFile m_glsl_120_frag{"glsl_120.frag"}; + InitFile m_glsl_120_vert{"glsl_120.vert"}; + InitFile m_glsl_120_common{"glsl_120_common.glsl"}; + InitFile m_glsl_es_100_frag{"glsl_es_100.frag"}; + InitFile m_glsl_es_100_vert{"glsl_es_100.vert"}; + InitFile m_glsl_es_100_common{"glsl_es_100_common.glsl"}; GlslEditorFactory editorFactory; GlslCompletionAssistProvider completionAssistProvider; @@ -50,17 +51,16 @@ public: static GlslEditorPluginPrivate *dd = nullptr; -GlslEditorPlugin::InitFile::InitFile(const QString &fileName) +InitFile::InitFile(const QString &fileName) : m_fileName(fileName) {} - -GlslEditorPlugin::InitFile::~InitFile() +InitFile::~InitFile() { delete m_engine; } -void GlslEditorPlugin::InitFile::initialize() const +void InitFile::initialize() const { // Parse the builtins for any language variant so we can use all keywords. const int variant = GLSL::Lexer::Variant_All; @@ -75,63 +75,21 @@ void GlslEditorPlugin::InitFile::initialize() const m_ast = parser.parse(); } -GLSL::TranslationUnitAST *GlslEditorPlugin::InitFile::ast() const +GLSL::TranslationUnitAST *InitFile::ast() const { if (!m_ast) initialize(); return m_ast; } -GLSL::Engine *GlslEditorPlugin::InitFile::engine() const +GLSL::Engine *InitFile::engine() const { if (!m_engine) initialize(); return m_engine; } -GlslEditorPlugin::~GlslEditorPlugin() -{ - delete dd; - dd = nullptr; -} - -void GlslEditorPlugin::initialize() -{ - dd = new GlslEditorPluginPrivate; - - ActionContainer *contextMenu = ActionManager::createMenu(Constants::M_CONTEXT); - ActionContainer *glslToolsMenu = ActionManager::createMenu(Id(Constants::M_TOOLS_GLSL)); - glslToolsMenu->setOnAllDisabledBehavior(ActionContainer::Hide); - QMenu *menu = glslToolsMenu->menu(); - //: GLSL sub-menu in the Tools menu - menu->setTitle(Tr::tr("GLSL")); - ActionManager::actionContainer(Core::Constants::M_TOOLS)->addMenu(glslToolsMenu); - - // Insert marker for "Refactoring" menu: - Command *sep = contextMenu->addSeparator(); - sep->action()->setObjectName(Constants::M_REFACTORING_MENU_INSERTION_POINT); - contextMenu->addSeparator(); - - Command *cmd = ActionManager::command(TextEditor::Constants::UN_COMMENT_SELECTION); - contextMenu->addAction(cmd); -} - -void GlslEditorPlugin::extensionsInitialized() -{ - using namespace Utils::Constants; - FileIconProvider::registerIconOverlayForMimeType(":/glsleditor/images/glslfile.png", - GLSL_MIMETYPE); - FileIconProvider::registerIconOverlayForMimeType(":/glsleditor/images/glslfile.png", - GLSL_VERT_MIMETYPE); - FileIconProvider::registerIconOverlayForMimeType(":/glsleditor/images/glslfile.png", - GLSL_FRAG_MIMETYPE); - FileIconProvider::registerIconOverlayForMimeType(":/glsleditor/images/glslfile.png", - GLSL_ES_VERT_MIMETYPE); - FileIconProvider::registerIconOverlayForMimeType(":/glsleditor/images/glslfile.png", - GLSL_ES_FRAG_MIMETYPE); -} - -const GlslEditorPlugin::InitFile *GlslEditorPlugin::fragmentShaderInit(int variant) +const InitFile *fragmentShaderInit(int variant) { if (variant & GLSL::Lexer::Variant_GLSL_400) return &dd->m_glsl_330_frag; @@ -140,7 +98,7 @@ const GlslEditorPlugin::InitFile *GlslEditorPlugin::fragmentShaderInit(int varia : &dd->m_glsl_es_100_frag; } -const GlslEditorPlugin::InitFile *GlslEditorPlugin::vertexShaderInit(int variant) +const InitFile *vertexShaderInit(int variant) { if (variant & GLSL::Lexer::Variant_GLSL_400) return &dd->m_glsl_330_vert; @@ -149,7 +107,7 @@ const GlslEditorPlugin::InitFile *GlslEditorPlugin::vertexShaderInit(int variant : &dd->m_glsl_es_100_vert; } -const GlslEditorPlugin::InitFile *GlslEditorPlugin::shaderInit(int variant) +const InitFile *shaderInit(int variant) { if (variant & GLSL::Lexer::Variant_GLSL_400) return &dd->m_glsl_330_common; @@ -158,5 +116,55 @@ const GlslEditorPlugin::InitFile *GlslEditorPlugin::shaderInit(int variant) : &dd->m_glsl_es_100_common; } -} // namespace Internal -} // namespace GlslEditor +class GlslEditorPlugin final : public ExtensionSystem::IPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "GLSLEditor.json") + +public: + ~GlslEditorPlugin() final + { + delete dd; + dd = nullptr; + } + + void initialize() final + { + dd = new GlslEditorPluginPrivate; + + ActionContainer *contextMenu = ActionManager::createMenu(Constants::M_CONTEXT); + ActionContainer *glslToolsMenu = ActionManager::createMenu(Id(Constants::M_TOOLS_GLSL)); + glslToolsMenu->setOnAllDisabledBehavior(ActionContainer::Hide); + QMenu *menu = glslToolsMenu->menu(); + //: GLSL sub-menu in the Tools menu + menu->setTitle(Tr::tr("GLSL")); + ActionManager::actionContainer(Core::Constants::M_TOOLS)->addMenu(glslToolsMenu); + + // Insert marker for "Refactoring" menu: + Command *sep = contextMenu->addSeparator(); + sep->action()->setObjectName(Constants::M_REFACTORING_MENU_INSERTION_POINT); + contextMenu->addSeparator(); + + Command *cmd = ActionManager::command(TextEditor::Constants::UN_COMMENT_SELECTION); + contextMenu->addAction(cmd); + } + + void extensionsInitialized() final + { + using namespace Utils::Constants; + FileIconProvider::registerIconOverlayForMimeType(":/glsleditor/images/glslfile.png", + GLSL_MIMETYPE); + FileIconProvider::registerIconOverlayForMimeType(":/glsleditor/images/glslfile.png", + GLSL_VERT_MIMETYPE); + FileIconProvider::registerIconOverlayForMimeType(":/glsleditor/images/glslfile.png", + GLSL_FRAG_MIMETYPE); + FileIconProvider::registerIconOverlayForMimeType(":/glsleditor/images/glslfile.png", + GLSL_ES_VERT_MIMETYPE); + FileIconProvider::registerIconOverlayForMimeType(":/glsleditor/images/glslfile.png", + GLSL_ES_FRAG_MIMETYPE); + } +}; + +} // GlslEditor::Internal + +#include "glsleditorplugin.moc" diff --git a/src/plugins/glsleditor/glsleditorplugin.h b/src/plugins/glsleditor/glsleditorplugin.h index 3d6b9f2338..a442db1128 100644 --- a/src/plugins/glsleditor/glsleditorplugin.h +++ b/src/plugins/glsleditor/glsleditorplugin.h @@ -3,46 +3,31 @@ #pragma once -#include <extensionsystem/iplugin.h> +#include <QString> + #include <glsl/glsl.h> -namespace GlslEditor { -namespace Internal { +namespace GlslEditor::Internal { -class GlslEditorPlugin final : public ExtensionSystem::IPlugin +class InitFile { - Q_OBJECT - Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "GLSLEditor.json") - public: - GlslEditorPlugin() = default; - ~GlslEditorPlugin() final; - - class InitFile - { - public: - explicit InitFile(const QString &m_fileName); - ~InitFile(); - - GLSL::Engine *engine() const; - GLSL::TranslationUnitAST *ast() const; + explicit InitFile(const QString &m_fileName); + ~InitFile(); - private: - void initialize() const; - - QString m_fileName; - mutable GLSL::Engine *m_engine = nullptr; - mutable GLSL::TranslationUnitAST *m_ast = nullptr; - }; - - static const InitFile *fragmentShaderInit(int variant); - static const InitFile *vertexShaderInit(int variant); - static const InitFile *shaderInit(int variant); + GLSL::Engine *engine() const; + GLSL::TranslationUnitAST *ast() const; private: - void initialize() final; - void extensionsInitialized() final; + void initialize() const; + + QString m_fileName; + mutable GLSL::Engine *m_engine = nullptr; + mutable GLSL::TranslationUnitAST *m_ast = nullptr; }; -} // namespace Internal -} // namespace GlslEditor +const InitFile *fragmentShaderInit(int variant); +const InitFile *vertexShaderInit(int variant); +const InitFile *shaderInit(int variant); + +} // GlslEditor |