Commit 2d89f188 authored by hjk's avatar hjk

GLSL: Cleanup plugin interface

Change-Id: I67734f0770cff14136e3795055fd5481d803f754
Reviewed-by: default avatarDavid Schulz <david.schulz@digia.com>
parent 0ff2ed64
......@@ -191,7 +191,7 @@ Core::IEditor *GLSLEditorEditable::duplicate(QWidget *parent)
{
GLSLTextEditorWidget *newEditor = new GLSLTextEditorWidget(parent);
newEditor->duplicateFrom(editorWidget());
GLSLEditorPlugin::instance()->initializeEditor(newEditor);
GLSLEditorPlugin::initializeEditor(newEditor);
return newEditor->editor();
}
......@@ -256,11 +256,6 @@ void GLSLTextEditorWidget::createToolBar(GLSLEditorEditable *editor)
editor->insertExtraToolBarWidget(TextEditor::BaseTextEditor::Left, m_outlineCombo);
}
bool GLSLTextEditorWidget::event(QEvent *e)
{
return BaseTextEditorWidget::event(e);
}
void GLSLTextEditorWidget::unCommentSelection()
{
Utils::unCommentSelection(this);
......@@ -285,16 +280,19 @@ void GLSLTextEditorWidget::updateDocumentNow()
Parser parser(doc->_engine, preprocessedCode.constData(), preprocessedCode.size(), variant);
TranslationUnitAST *ast = parser.parse();
if (ast != 0 || extraSelections(CodeWarningsSelection).isEmpty()) {
GLSLEditorPlugin *plugin = GLSLEditorPlugin::instance();
Semantic sem;
Scope *globalScope = engine->newNamespace();
doc->_globalScope = globalScope;
sem.translationUnit(plugin->shaderInit(variant)->ast, globalScope, plugin->shaderInit(variant)->engine);
if (variant & Lexer::Variant_VertexShader)
sem.translationUnit(plugin->vertexShaderInit(variant)->ast, globalScope, plugin->vertexShaderInit(variant)->engine);
if (variant & Lexer::Variant_FragmentShader)
sem.translationUnit(plugin->fragmentShaderInit(variant)->ast, globalScope, plugin->fragmentShaderInit(variant)->engine);
const GLSLEditorPlugin::InitFile *file = GLSLEditorPlugin::shaderInit(variant);
sem.translationUnit(file->ast, globalScope, file->engine);
if (variant & Lexer::Variant_VertexShader) {
file = GLSLEditorPlugin::vertexShaderInit(variant);
sem.translationUnit(file->ast, globalScope, file->engine);
}
if (variant & Lexer::Variant_FragmentShader) {
file = GLSLEditorPlugin::fragmentShaderInit(variant);
sem.translationUnit(file->ast, globalScope, file->engine);
}
sem.translationUnit(ast, globalScope, engine);
CreateRanges createRanges(document(), doc);
......@@ -371,11 +369,6 @@ int GLSLTextEditorWidget::languageVariant(const QString &type)
return variant;
}
Document::Ptr GLSLTextEditorWidget::glslDocument() const
{
return m_glslDocument;
}
TextEditor::IAssistInterface *GLSLTextEditorWidget::createAssistInterface(
TextEditor::AssistKind kind,
TextEditor::AssistReason reason) const
......@@ -386,6 +379,6 @@ TextEditor::IAssistInterface *GLSLTextEditorWidget::createAssistInterface(
editor()->document()->filePath(),
reason,
mimeType(),
glslDocument());
m_glslDocument);
return BaseTextEditorWidget::createAssistInterface(kind, reason);
}
......@@ -46,8 +46,6 @@ class TranslationUnitAST;
class Scope;
} // namespace GLSL
namespace Core { class ICore; }
namespace GLSLEditor {
namespace Internal {
......@@ -100,8 +98,6 @@ public:
static int languageVariant(const QString &mimeType);
Document::Ptr glslDocument() const;
TextEditor::IAssistInterface *createAssistInterface(TextEditor::AssistKind assistKind,
TextEditor::AssistReason reason) const;
......@@ -110,7 +106,6 @@ private slots:
void updateDocumentNow();
protected:
bool event(QEvent *e);
TextEditor::BaseTextEditor *createEditor();
void createToolBar(Internal::GLSLEditorEditable *editable);
......
......@@ -59,7 +59,7 @@ GLSLEditorFactory::GLSLEditorFactory(QObject *parent)
Core::IEditor *GLSLEditorFactory::createEditor(QWidget *parent)
{
GLSLTextEditorWidget *rc = new GLSLTextEditorWidget(parent);
GLSLEditorPlugin::instance()->initializeEditor(rc);
GLSLEditorPlugin::initializeEditor(rc);
return rc->editor();
}
......
......@@ -72,36 +72,61 @@ using namespace TextEditor;
namespace GLSLEditor {
namespace Internal {
GLSLEditorPlugin *GLSLEditorPlugin::m_instance = 0;
class GLSLEditorPluginPrivate
{
public:
GLSLEditorPluginPrivate() :
m_editor(0),
m_actionHandler(0),
m_glsl_120_frag(0),
m_glsl_120_vert(0),
m_glsl_120_common(0),
m_glsl_es_100_frag(0),
m_glsl_es_100_vert(0),
m_glsl_es_100_common(0)
{}
~GLSLEditorPluginPrivate()
{
delete m_actionHandler;
delete m_glsl_120_frag;
delete m_glsl_120_vert;
delete m_glsl_120_common;
delete m_glsl_es_100_frag;
delete m_glsl_es_100_vert;
delete m_glsl_es_100_common;
}
GLSLEditorFactory *m_editor;
TextEditor::TextEditorActionHandler *m_actionHandler;
QPointer<TextEditor::ITextEditor> m_currentTextEditable;
GLSLEditorPlugin::InitFile *m_glsl_120_frag;
GLSLEditorPlugin::InitFile *m_glsl_120_vert;
GLSLEditorPlugin::InitFile *m_glsl_120_common;
GLSLEditorPlugin::InitFile *m_glsl_es_100_frag;
GLSLEditorPlugin::InitFile *m_glsl_es_100_vert;
GLSLEditorPlugin::InitFile *m_glsl_es_100_common;
};
static GLSLEditorPluginPrivate *dd = 0;
static GLSLEditorPlugin *m_instance = 0;
GLSLEditorPlugin::InitFile::~InitFile()
{
delete engine;
}
GLSLEditorPlugin::GLSLEditorPlugin() :
m_editor(0),
m_actionHandler(0),
m_glsl_120_frag(0),
m_glsl_120_vert(0),
m_glsl_120_common(0),
m_glsl_es_100_frag(0),
m_glsl_es_100_vert(0),
m_glsl_es_100_common(0)
GLSLEditorPlugin::GLSLEditorPlugin()
{
m_instance = this;
dd = new GLSLEditorPluginPrivate;
}
GLSLEditorPlugin::~GLSLEditorPlugin()
{
removeObject(m_editor);
delete m_actionHandler;
delete m_glsl_120_frag;
delete m_glsl_120_vert;
delete m_glsl_120_common;
delete m_glsl_es_100_frag;
delete m_glsl_es_100_vert;
delete m_glsl_es_100_common;
removeObject(dd->m_editor);
delete dd;
m_instance = 0;
}
......@@ -115,16 +140,16 @@ bool GLSLEditorPlugin::initialize(const QStringList & /*arguments*/, QString *er
addAutoReleasedObject(new GLSLHoverHandler(this));
m_editor = new GLSLEditorFactory(this);
addObject(m_editor);
dd->m_editor = new GLSLEditorFactory(this);
addObject(dd->m_editor);
addAutoReleasedObject(new GLSLCompletionAssistProvider);
m_actionHandler = new TextEditorActionHandler(Constants::C_GLSLEDITOR_ID,
dd->m_actionHandler = new TextEditorActionHandler(Constants::C_GLSLEDITOR_ID,
TextEditorActionHandler::Format
| TextEditorActionHandler::UnCommentSelection
| TextEditorActionHandler::UnCollapseAll);
m_actionHandler->initializeActions();
dd->m_actionHandler->initializeActions();
ActionContainer *contextMenu = ActionManager::createMenu(GLSLEditor::Constants::M_CONTEXT);
ActionContainer *glslToolsMenu = ActionManager::createMenu(Id(Constants::M_TOOLS_GLSL));
......@@ -219,20 +244,11 @@ ExtensionSystem::IPlugin::ShutdownFlag GLSLEditorPlugin::aboutToShutdown()
void GLSLEditorPlugin::initializeEditor(GLSLTextEditorWidget *editor)
{
QTC_CHECK(m_instance);
m_actionHandler->setupActions(editor);
dd->m_actionHandler->setupActions(editor);
TextEditorSettings::instance()->initializeEditor(editor);
}
GLSLEditorPlugin::InitFile *GLSLEditorPlugin::getInitFile(const QString &fileName, InitFile **initFile) const
{
if (*initFile)
return *initFile;
*initFile = new GLSLEditorPlugin::InitFile;
parseGlslFile(fileName, *initFile);
return *initFile;
}
QByteArray GLSLEditorPlugin::glslFile(const QString &fileName) const
static QByteArray glslFile(const QString &fileName)
{
QFile file(ICore::resourcePath() + QLatin1String("/glsl/") + fileName);
if (file.open(QFile::ReadOnly))
......@@ -240,7 +256,7 @@ QByteArray GLSLEditorPlugin::glslFile(const QString &fileName) const
return QByteArray();
}
void GLSLEditorPlugin::parseGlslFile(const QString &fileName, InitFile *initFile) const
static void parseGlslFile(const QString &fileName, GLSLEditorPlugin::InitFile *initFile)
{
// Parse the builtins for any langugage variant so we can use all keywords.
const int variant = GLSL::Lexer::Variant_All;
......@@ -251,28 +267,37 @@ void GLSLEditorPlugin::parseGlslFile(const QString &fileName, InitFile *initFile
initFile->ast = parser.parse();
}
const GLSLEditorPlugin::InitFile *GLSLEditorPlugin::fragmentShaderInit(int variant) const
static GLSLEditorPlugin::InitFile *getInitFile(const char *fileName, GLSLEditorPlugin::InitFile **initFile)
{
if (*initFile)
return *initFile;
*initFile = new GLSLEditorPlugin::InitFile;
parseGlslFile(QLatin1String(fileName), *initFile);
return *initFile;
}
const GLSLEditorPlugin::InitFile *GLSLEditorPlugin::fragmentShaderInit(int variant)
{
if (variant & GLSL::Lexer::Variant_GLSL_120)
return getInitFile(QLatin1String("glsl_120.frag"), &m_glsl_120_frag);
return getInitFile("glsl_120.frag", &dd->m_glsl_120_frag);
else
return getInitFile(QLatin1String("glsl_es_100.frag"), &m_glsl_es_100_frag);
return getInitFile("glsl_es_100.frag", &dd->m_glsl_es_100_frag);
}
const GLSLEditorPlugin::InitFile *GLSLEditorPlugin::vertexShaderInit(int variant) const
const GLSLEditorPlugin::InitFile *GLSLEditorPlugin::vertexShaderInit(int variant)
{
if (variant & GLSL::Lexer::Variant_GLSL_120)
return getInitFile(QLatin1String("glsl_120.vert"), &m_glsl_120_vert);
return getInitFile("glsl_120.vert", &dd->m_glsl_120_vert);
else
return getInitFile(QLatin1String("glsl_es_100.vert"), &m_glsl_es_100_vert);
return getInitFile("glsl_es_100.vert", &dd->m_glsl_es_100_vert);
}
const GLSLEditorPlugin::InitFile *GLSLEditorPlugin::shaderInit(int variant) const
const GLSLEditorPlugin::InitFile *GLSLEditorPlugin::shaderInit(int variant)
{
if (variant & GLSL::Lexer::Variant_GLSL_120)
return getInitFile(QLatin1String("glsl_120_common.glsl"), &m_glsl_120_common);
return getInitFile("glsl_120_common.glsl", &dd->m_glsl_120_common);
else
return getInitFile(QLatin1String("glsl_es_100_common.glsl"), &m_glsl_es_100_common);
return getInitFile("glsl_es_100_common.glsl", &dd->m_glsl_es_100_common);
}
} // namespace Internal
......
......@@ -31,29 +31,11 @@
#define GLSLEDITORPLUGIN_H
#include <extensionsystem/iplugin.h>
#include <coreplugin/icontext.h>
#include <coreplugin/id.h>
#include <glsl/glsl.h>
#include <QPointer>
QT_FORWARD_DECLARE_CLASS(QAction)
namespace TextEditor {
class TextEditorActionHandler;
class ITextEditor;
} // namespace TextEditor
namespace Core {
class Command;
class ActionContainer;
class ActionManager;
} // namespace Core
namespace GLSLEditor {
namespace Internal {
class GLSLEditorFactory;
class GLSLTextEditorWidget;
class GLSLEditorPlugin : public ExtensionSystem::IPlugin
......@@ -70,9 +52,7 @@ public:
void extensionsInitialized();
ShutdownFlag aboutToShutdown();
static GLSLEditorPlugin *instance() { return m_instance; }
void initializeEditor(GLSLTextEditorWidget *editor);
static void initializeEditor(GLSLTextEditorWidget *editor);
struct InitFile
{
......@@ -86,28 +66,9 @@ public:
GLSL::TranslationUnitAST *ast;
};
const InitFile *fragmentShaderInit(int variant) const;
const InitFile *vertexShaderInit(int variant) const;
const InitFile *shaderInit(int variant) const;
private:
QByteArray glslFile(const QString &fileName) const;
InitFile *getInitFile(const QString &fileName, InitFile **initFile) const;
void parseGlslFile(const QString &fileName, InitFile *initFile) const;
static GLSLEditorPlugin *m_instance;
GLSLEditorFactory *m_editor;
TextEditor::TextEditorActionHandler *m_actionHandler;
QPointer<TextEditor::ITextEditor> m_currentTextEditable;
mutable InitFile *m_glsl_120_frag;
mutable InitFile *m_glsl_120_vert;
mutable InitFile *m_glsl_120_common;
mutable InitFile *m_glsl_es_100_frag;
mutable InitFile *m_glsl_es_100_vert;
mutable InitFile *m_glsl_es_100_common;
static const InitFile *fragmentShaderInit(int variant);
static const InitFile *vertexShaderInit(int variant);
static const InitFile *shaderInit(int variant);
};
} // namespace Internal
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment