2010-11-10 14:01:09 +01:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2012-01-26 18:33:46 +01:00
|
|
|
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
|
2010-11-10 14:01:09 +01:00
|
|
|
**
|
2011-11-02 15:59:12 +01:00
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
2010-11-10 14:01:09 +01:00
|
|
|
**
|
|
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** 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.
|
2010-11-10 14:01:09 +01:00
|
|
|
**
|
2010-12-17 17:14:20 +01:00
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
2011-04-13 08:42:33 +02:00
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
2010-12-17 17:14:20 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Other Usage
|
|
|
|
|
**
|
|
|
|
|
** Alternatively, this file may be used in accordance with the terms and
|
|
|
|
|
** conditions contained in a signed written agreement between you and Nokia.
|
|
|
|
|
**
|
2010-12-17 17:14:20 +01:00
|
|
|
** If you have questions regarding the use of this file, please contact
|
2011-11-02 15:59:12 +01:00
|
|
|
** Nokia at qt-info@nokia.com.
|
2010-11-10 14:01:09 +01:00
|
|
|
**
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "glsleditorplugin.h"
|
|
|
|
|
#include "glsleditor.h"
|
|
|
|
|
#include "glsleditorconstants.h"
|
|
|
|
|
#include "glsleditorfactory.h"
|
2010-11-24 13:27:53 +10:00
|
|
|
#include "glslfilewizard.h"
|
2010-11-26 11:17:30 +01:00
|
|
|
#include "glslhoverhandler.h"
|
2011-04-15 16:19:23 +02:00
|
|
|
#include "glslcompletionassist.h"
|
2010-11-10 14:01:09 +01:00
|
|
|
|
|
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
|
#include <coreplugin/coreconstants.h>
|
|
|
|
|
#include <coreplugin/mimedatabase.h>
|
2011-09-05 16:10:37 +02:00
|
|
|
#include <coreplugin/id.h>
|
2010-11-10 14:01:09 +01:00
|
|
|
#include <coreplugin/fileiconprovider.h>
|
|
|
|
|
#include <coreplugin/actionmanager/actionmanager.h>
|
|
|
|
|
#include <coreplugin/actionmanager/actioncontainer.h>
|
|
|
|
|
#include <coreplugin/actionmanager/command.h>
|
|
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
|
|
|
|
#include <projectexplorer/taskhub.h>
|
|
|
|
|
#include <extensionsystem/pluginmanager.h>
|
|
|
|
|
#include <texteditor/texteditorconstants.h>
|
|
|
|
|
#include <texteditor/texteditorsettings.h>
|
|
|
|
|
#include <texteditor/textfilewizard.h>
|
|
|
|
|
#include <texteditor/texteditoractionhandler.h>
|
|
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
|
2010-11-26 15:00:46 +01:00
|
|
|
#include <glsl/glslengine.h>
|
|
|
|
|
#include <glsl/glslparser.h>
|
|
|
|
|
#include <glsl/glsllexer.h>
|
|
|
|
|
|
2010-11-10 14:01:09 +01:00
|
|
|
#include <QtCore/QtPlugin>
|
|
|
|
|
#include <QtCore/QDebug>
|
|
|
|
|
#include <QtCore/QSettings>
|
|
|
|
|
#include <QtCore/QDir>
|
|
|
|
|
#include <QtCore/QCoreApplication>
|
|
|
|
|
#include <QtCore/QTimer>
|
|
|
|
|
#include <QtGui/QMenu>
|
|
|
|
|
#include <QtGui/QAction>
|
|
|
|
|
|
|
|
|
|
using namespace GLSLEditor;
|
|
|
|
|
using namespace GLSLEditor::Internal;
|
|
|
|
|
using namespace GLSLEditor::Constants;
|
|
|
|
|
|
|
|
|
|
GLSLEditorPlugin *GLSLEditorPlugin::m_instance = 0;
|
|
|
|
|
|
2010-11-26 15:00:46 +01:00
|
|
|
GLSLEditorPlugin::InitFile::~InitFile()
|
|
|
|
|
{
|
|
|
|
|
delete engine;
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-10 14:01:09 +01:00
|
|
|
GLSLEditorPlugin::GLSLEditorPlugin() :
|
|
|
|
|
m_editor(0),
|
|
|
|
|
m_actionHandler(0)
|
|
|
|
|
{
|
|
|
|
|
m_instance = this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GLSLEditorPlugin::~GLSLEditorPlugin()
|
|
|
|
|
{
|
|
|
|
|
removeObject(m_editor);
|
|
|
|
|
delete m_actionHandler;
|
|
|
|
|
m_instance = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*! Copied from cppplugin.cpp */
|
|
|
|
|
static inline
|
|
|
|
|
Core::Command *createSeparator(Core::ActionManager *am,
|
|
|
|
|
QObject *parent,
|
|
|
|
|
Core::Context &context,
|
|
|
|
|
const char *id)
|
|
|
|
|
{
|
|
|
|
|
QAction *separator = new QAction(parent);
|
|
|
|
|
separator->setSeparator(true);
|
|
|
|
|
return am->registerAction(separator, Core::Id(id), context);
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-21 13:05:15 +02:00
|
|
|
bool GLSLEditorPlugin::initialize(const QStringList & /*arguments*/, QString *errorMessage)
|
2010-11-10 14:01:09 +01:00
|
|
|
{
|
2012-01-24 15:36:40 +01:00
|
|
|
if (!Core::ICore::mimeDatabase()->addMimeTypes(QLatin1String(":/glsleditor/GLSLEditor.mimetypes.xml"), errorMessage))
|
2010-11-10 14:01:09 +01:00
|
|
|
return false;
|
|
|
|
|
|
2010-11-26 15:00:46 +01:00
|
|
|
parseGlslFile(QLatin1String("glsl_120.frag"), &m_glsl_120_frag);
|
|
|
|
|
parseGlslFile(QLatin1String("glsl_120.vert"), &m_glsl_120_vert);
|
|
|
|
|
parseGlslFile(QLatin1String("glsl_120_common.glsl"), &m_glsl_120_common);
|
2010-11-29 10:09:22 +10:00
|
|
|
parseGlslFile(QLatin1String("glsl_es_100.frag"), &m_glsl_es_100_frag);
|
|
|
|
|
parseGlslFile(QLatin1String("glsl_es_100.vert"), &m_glsl_es_100_vert);
|
|
|
|
|
parseGlslFile(QLatin1String("glsl_es_100_common.glsl"), &m_glsl_es_100_common);
|
2010-11-26 15:00:46 +01:00
|
|
|
|
2010-11-26 14:18:50 +01:00
|
|
|
|
2010-11-10 14:01:09 +01:00
|
|
|
// m_modelManager = new ModelManager(this);
|
|
|
|
|
// addAutoReleasedObject(m_modelManager);
|
|
|
|
|
|
2010-11-26 11:17:30 +01:00
|
|
|
addAutoReleasedObject(new GLSLHoverHandler(this));
|
|
|
|
|
|
2010-11-10 14:01:09 +01:00
|
|
|
Core::Context context(GLSLEditor::Constants::C_GLSLEDITOR_ID);
|
|
|
|
|
|
|
|
|
|
m_editor = new GLSLEditorFactory(this);
|
|
|
|
|
addObject(m_editor);
|
|
|
|
|
|
2011-04-15 16:19:23 +02:00
|
|
|
addAutoReleasedObject(new GLSLCompletionAssistProvider);
|
2010-11-12 17:11:20 +01:00
|
|
|
|
2010-11-10 14:01:09 +01:00
|
|
|
m_actionHandler = new TextEditor::TextEditorActionHandler(GLSLEditor::Constants::C_GLSLEDITOR_ID,
|
|
|
|
|
TextEditor::TextEditorActionHandler::Format
|
|
|
|
|
| TextEditor::TextEditorActionHandler::UnCommentSelection
|
|
|
|
|
| TextEditor::TextEditorActionHandler::UnCollapseAll);
|
|
|
|
|
m_actionHandler->initializeActions();
|
|
|
|
|
|
2012-01-24 15:36:40 +01:00
|
|
|
Core::ActionManager *am = Core::ICore::actionManager();
|
2010-11-10 14:01:09 +01:00
|
|
|
Core::ActionContainer *contextMenu = am->createMenu(GLSLEditor::Constants::M_CONTEXT);
|
|
|
|
|
Core::ActionContainer *glslToolsMenu = am->createMenu(Core::Id(Constants::M_TOOLS_GLSL));
|
2010-12-16 11:49:47 +01:00
|
|
|
glslToolsMenu->setOnAllDisabledBehavior(Core::ActionContainer::Hide);
|
2010-11-10 14:01:09 +01:00
|
|
|
QMenu *menu = glslToolsMenu->menu();
|
|
|
|
|
//: GLSL sub-menu in the Tools menu
|
|
|
|
|
menu->setTitle(tr("GLSL"));
|
|
|
|
|
am->actionContainer(Core::Constants::M_TOOLS)->addMenu(glslToolsMenu);
|
|
|
|
|
|
2010-11-12 17:11:20 +01:00
|
|
|
Core::Command *cmd = 0;
|
2010-11-10 14:01:09 +01:00
|
|
|
|
|
|
|
|
// Insert marker for "Refactoring" menu:
|
|
|
|
|
Core::Context globalContext(Core::Constants::C_GLOBAL);
|
|
|
|
|
Core::Command *sep = createSeparator(am, this, globalContext,
|
|
|
|
|
Constants::SEPARATOR1);
|
|
|
|
|
sep->action()->setObjectName(Constants::M_REFACTORING_MENU_INSERTION_POINT);
|
|
|
|
|
contextMenu->addAction(sep);
|
|
|
|
|
contextMenu->addAction(createSeparator(am, this, globalContext,
|
|
|
|
|
Constants::SEPARATOR2));
|
|
|
|
|
|
|
|
|
|
cmd = am->command(TextEditor::Constants::UN_COMMENT_SELECTION);
|
|
|
|
|
contextMenu->addAction(cmd);
|
|
|
|
|
|
2011-09-21 13:05:15 +02:00
|
|
|
errorMessage->clear();
|
2010-11-10 14:01:09 +01:00
|
|
|
|
|
|
|
|
Core::FileIconProvider *iconProvider = Core::FileIconProvider::instance();
|
2012-01-24 15:36:40 +01:00
|
|
|
Core::MimeDatabase *mimeDatabase = Core::ICore::mimeDatabase();
|
2010-11-25 12:46:26 +10:00
|
|
|
iconProvider->registerIconOverlayForMimeType(QIcon(QLatin1String(":/glsleditor/images/glslfile.png")),
|
|
|
|
|
mimeDatabase->findByType(QLatin1String(GLSLEditor::Constants::GLSL_MIMETYPE)));
|
2010-12-01 10:04:56 +10:00
|
|
|
iconProvider->registerIconOverlayForMimeType(QIcon(QLatin1String(":/glsleditor/images/glslfile.png")),
|
|
|
|
|
mimeDatabase->findByType(QLatin1String(GLSLEditor::Constants::GLSL_MIMETYPE_VERT)));
|
|
|
|
|
iconProvider->registerIconOverlayForMimeType(QIcon(QLatin1String(":/glsleditor/images/glslfile.png")),
|
|
|
|
|
mimeDatabase->findByType(QLatin1String(GLSLEditor::Constants::GLSL_MIMETYPE_FRAG)));
|
|
|
|
|
iconProvider->registerIconOverlayForMimeType(QIcon(QLatin1String(":/glsleditor/images/glslfile.png")),
|
|
|
|
|
mimeDatabase->findByType(QLatin1String(GLSLEditor::Constants::GLSL_MIMETYPE_VERT_ES)));
|
|
|
|
|
iconProvider->registerIconOverlayForMimeType(QIcon(QLatin1String(":/glsleditor/images/glslfile.png")),
|
|
|
|
|
mimeDatabase->findByType(QLatin1String(GLSLEditor::Constants::GLSL_MIMETYPE_FRAG_ES)));
|
2010-11-10 14:01:09 +01:00
|
|
|
|
2012-01-24 15:36:40 +01:00
|
|
|
QObject *core = Core::ICore::instance();
|
2010-11-24 13:27:53 +10:00
|
|
|
Core::BaseFileWizardParameters fragWizardParameters(Core::IWizard::FileWizard);
|
|
|
|
|
fragWizardParameters.setCategory(QLatin1String(Constants::WIZARD_CATEGORY_GLSL));
|
|
|
|
|
fragWizardParameters.setDisplayCategory(QCoreApplication::translate("GLSLEditor", Constants::WIZARD_TR_CATEGORY_GLSL));
|
|
|
|
|
fragWizardParameters.setDescription
|
|
|
|
|
(tr("Creates a fragment shader in the OpenGL/ES 2.0 Shading "
|
2011-02-15 16:05:52 +01:00
|
|
|
"Language (GLSL/ES). Fragment shaders generate the final "
|
|
|
|
|
"pixel colors for triangles, points and lines rendered "
|
2010-11-24 13:27:53 +10:00
|
|
|
"with OpenGL."));
|
2011-02-15 16:05:52 +01:00
|
|
|
fragWizardParameters.setDisplayName(tr("Fragment Shader (OpenGL/ES 2.0)"));
|
2010-11-24 13:27:53 +10:00
|
|
|
fragWizardParameters.setId(QLatin1String("F.GLSL"));
|
2010-12-01 10:04:56 +10:00
|
|
|
addAutoReleasedObject(new GLSLFileWizard(fragWizardParameters, GLSLFileWizard::FragmentShaderES, core));
|
2010-11-24 13:27:53 +10:00
|
|
|
|
|
|
|
|
Core::BaseFileWizardParameters vertWizardParameters(Core::IWizard::FileWizard);
|
|
|
|
|
vertWizardParameters.setCategory(QLatin1String(Constants::WIZARD_CATEGORY_GLSL));
|
|
|
|
|
vertWizardParameters.setDisplayCategory(QCoreApplication::translate("GLSLEditor", Constants::WIZARD_TR_CATEGORY_GLSL));
|
|
|
|
|
vertWizardParameters.setDescription
|
|
|
|
|
(tr("Creates a vertex shader in the OpenGL/ES 2.0 Shading "
|
2011-02-15 16:05:52 +01:00
|
|
|
"Language (GLSL/ES). Vertex shaders transform the "
|
|
|
|
|
"positions, normals and texture co-ordinates of "
|
|
|
|
|
"triangles, points and lines rendered with OpenGL."));
|
|
|
|
|
vertWizardParameters.setDisplayName(tr("Vertex Shader (OpenGL/ES 2.0)"));
|
2010-12-01 10:04:56 +10:00
|
|
|
vertWizardParameters.setId(QLatin1String("G.GLSL"));
|
|
|
|
|
addAutoReleasedObject(new GLSLFileWizard(vertWizardParameters, GLSLFileWizard::VertexShaderES, core));
|
|
|
|
|
|
|
|
|
|
fragWizardParameters.setDescription
|
|
|
|
|
(tr("Creates a fragment shader in the Desktop OpenGL Shading "
|
2011-02-15 16:05:52 +01:00
|
|
|
"Language (GLSL). Fragment shaders generate the final "
|
|
|
|
|
"pixel colors for triangles, points and lines rendered "
|
2010-12-01 10:04:56 +10:00
|
|
|
"with OpenGL."));
|
2011-02-15 16:05:52 +01:00
|
|
|
fragWizardParameters.setDisplayName(tr("Fragment Shader (Desktop OpenGL)"));
|
2010-12-01 10:04:56 +10:00
|
|
|
fragWizardParameters.setId(QLatin1String("J.GLSL"));
|
|
|
|
|
addAutoReleasedObject(new GLSLFileWizard(fragWizardParameters, GLSLFileWizard::FragmentShaderDesktop, core));
|
|
|
|
|
|
|
|
|
|
vertWizardParameters.setDescription
|
|
|
|
|
(tr("Creates a vertex shader in the Desktop OpenGL Shading "
|
2011-02-15 16:05:52 +01:00
|
|
|
"Language (GLSL). Vertex shaders transform the "
|
|
|
|
|
"positions, normals and texture co-ordinates of "
|
|
|
|
|
"triangles, points and lines rendered with OpenGL."));
|
|
|
|
|
vertWizardParameters.setDisplayName(tr("Vertex Shader (Desktop OpenGL)"));
|
2010-12-01 10:04:56 +10:00
|
|
|
vertWizardParameters.setId(QLatin1String("K.GLSL"));
|
|
|
|
|
addAutoReleasedObject(new GLSLFileWizard(vertWizardParameters, GLSLFileWizard::VertexShaderDesktop, core));
|
2010-11-24 13:27:53 +10:00
|
|
|
|
2010-11-10 14:01:09 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GLSLEditorPlugin::extensionsInitialized()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ExtensionSystem::IPlugin::ShutdownFlag GLSLEditorPlugin::aboutToShutdown()
|
|
|
|
|
{
|
|
|
|
|
// delete GLSL::Icons::instance(); // delete object held by singleton
|
|
|
|
|
|
|
|
|
|
return IPlugin::aboutToShutdown();
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-21 16:02:26 +01:00
|
|
|
void GLSLEditorPlugin::initializeEditor(GLSLEditor::GLSLTextEditorWidget *editor)
|
2010-11-10 14:01:09 +01:00
|
|
|
{
|
2011-07-29 12:00:11 +02:00
|
|
|
QTC_CHECK(m_instance);
|
2010-11-10 14:01:09 +01:00
|
|
|
|
|
|
|
|
m_actionHandler->setupActions(editor);
|
|
|
|
|
|
|
|
|
|
TextEditor::TextEditorSettings::instance()->initializeEditor(editor);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Core::Command *GLSLEditorPlugin::addToolAction(QAction *a, Core::ActionManager *am,
|
2011-11-10 11:36:51 +01:00
|
|
|
Core::Context &context, const Core::Id &id,
|
2010-11-10 14:01:09 +01:00
|
|
|
Core::ActionContainer *c1, const QString &keySequence)
|
|
|
|
|
{
|
2011-11-10 11:36:51 +01:00
|
|
|
Core::Command *command = am->registerAction(a, id, context);
|
2010-11-10 14:01:09 +01:00
|
|
|
if (!keySequence.isEmpty())
|
|
|
|
|
command->setDefaultKeySequence(QKeySequence(keySequence));
|
|
|
|
|
c1->addAction(command);
|
|
|
|
|
return command;
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-26 14:18:50 +01:00
|
|
|
QByteArray GLSLEditorPlugin::glslFile(const QString &fileName)
|
|
|
|
|
{
|
2012-01-24 15:36:40 +01:00
|
|
|
QString path = Core::ICore::resourcePath();
|
2010-11-26 14:18:50 +01:00
|
|
|
path += QLatin1String("/glsl/");
|
|
|
|
|
path += fileName;
|
|
|
|
|
QFile file(path);
|
|
|
|
|
if (file.open(QFile::ReadOnly))
|
|
|
|
|
return file.readAll();
|
|
|
|
|
return QByteArray();
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-26 15:00:46 +01:00
|
|
|
void GLSLEditorPlugin::parseGlslFile(const QString &fileName, InitFile *initFile)
|
|
|
|
|
{
|
2010-11-29 10:09:22 +10:00
|
|
|
// Parse the builtins for any langugage variant so we can use all keywords.
|
2010-12-16 12:05:48 +01:00
|
|
|
const unsigned variant = GLSL::Lexer::Variant_All;
|
2010-11-26 15:00:46 +01:00
|
|
|
|
|
|
|
|
const QByteArray code = glslFile(fileName);
|
|
|
|
|
initFile->engine = new GLSL::Engine();
|
|
|
|
|
GLSL::Parser parser(initFile->engine, code.constData(), code.size(), variant);
|
|
|
|
|
initFile->ast = parser.parse();
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-01 10:04:56 +10:00
|
|
|
const GLSLEditorPlugin::InitFile *GLSLEditorPlugin::fragmentShaderInit(int variant) const
|
2010-11-26 14:18:50 +01:00
|
|
|
{
|
2010-12-01 10:04:56 +10:00
|
|
|
if (variant & GLSL::Lexer::Variant_GLSL_120)
|
|
|
|
|
return &m_glsl_120_frag;
|
|
|
|
|
else
|
|
|
|
|
return &m_glsl_es_100_frag;
|
2010-11-26 14:18:50 +01:00
|
|
|
}
|
|
|
|
|
|
2010-12-01 10:04:56 +10:00
|
|
|
const GLSLEditorPlugin::InitFile *GLSLEditorPlugin::vertexShaderInit(int variant) const
|
2010-11-26 14:18:50 +01:00
|
|
|
{
|
2010-12-01 10:04:56 +10:00
|
|
|
if (variant & GLSL::Lexer::Variant_GLSL_120)
|
|
|
|
|
return &m_glsl_120_vert;
|
|
|
|
|
else
|
|
|
|
|
return &m_glsl_es_100_vert;
|
2010-11-26 14:18:50 +01:00
|
|
|
}
|
|
|
|
|
|
2010-12-01 10:04:56 +10:00
|
|
|
const GLSLEditorPlugin::InitFile *GLSLEditorPlugin::shaderInit(int variant) const
|
2010-11-26 14:18:50 +01:00
|
|
|
{
|
2010-12-01 10:04:56 +10:00
|
|
|
if (variant & GLSL::Lexer::Variant_GLSL_120)
|
|
|
|
|
return &m_glsl_120_common;
|
|
|
|
|
else
|
|
|
|
|
return &m_glsl_es_100_common;
|
2010-11-26 14:18:50 +01:00
|
|
|
}
|
|
|
|
|
|
2010-11-10 14:01:09 +01:00
|
|
|
Q_EXPORT_PLUGIN(GLSLEditorPlugin)
|