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