forked from qt-creator/qt-creator
De-noise GLSLEditorPlugin
Change-Id: Iaf846c387caed2b6636e5b057dce0b685d07012d Reviewed-by: hjk <qthjk@ovi.com>
This commit is contained in:
@@ -65,9 +65,11 @@
|
|||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
|
|
||||||
using namespace GLSLEditor;
|
using namespace Core;
|
||||||
using namespace GLSLEditor::Internal;
|
using namespace TextEditor;
|
||||||
using namespace GLSLEditor::Constants;
|
|
||||||
|
namespace GLSLEditor {
|
||||||
|
namespace Internal {
|
||||||
|
|
||||||
GLSLEditorPlugin *GLSLEditorPlugin::m_instance = 0;
|
GLSLEditorPlugin *GLSLEditorPlugin::m_instance = 0;
|
||||||
|
|
||||||
@@ -104,7 +106,7 @@ GLSLEditorPlugin::~GLSLEditorPlugin()
|
|||||||
|
|
||||||
bool GLSLEditorPlugin::initialize(const QStringList & /*arguments*/, QString *errorMessage)
|
bool GLSLEditorPlugin::initialize(const QStringList & /*arguments*/, QString *errorMessage)
|
||||||
{
|
{
|
||||||
if (!Core::ICore::mimeDatabase()->addMimeTypes(QLatin1String(":/glsleditor/GLSLEditor.mimetypes.xml"), errorMessage))
|
if (!ICore::mimeDatabase()->addMimeTypes(QLatin1String(":/glsleditor/GLSLEditor.mimetypes.xml"), errorMessage))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// m_modelManager = new ModelManager(this);
|
// m_modelManager = new ModelManager(this);
|
||||||
@@ -112,42 +114,40 @@ bool GLSLEditorPlugin::initialize(const QStringList & /*arguments*/, QString *er
|
|||||||
|
|
||||||
addAutoReleasedObject(new GLSLHoverHandler(this));
|
addAutoReleasedObject(new GLSLHoverHandler(this));
|
||||||
|
|
||||||
Core::Context context(GLSLEditor::Constants::C_GLSLEDITOR_ID);
|
|
||||||
|
|
||||||
m_editor = new GLSLEditorFactory(this);
|
m_editor = new GLSLEditorFactory(this);
|
||||||
addObject(m_editor);
|
addObject(m_editor);
|
||||||
|
|
||||||
addAutoReleasedObject(new GLSLCompletionAssistProvider);
|
addAutoReleasedObject(new GLSLCompletionAssistProvider);
|
||||||
|
|
||||||
m_actionHandler = new TextEditor::TextEditorActionHandler(GLSLEditor::Constants::C_GLSLEDITOR_ID,
|
m_actionHandler = new TextEditorActionHandler(Constants::C_GLSLEDITOR_ID,
|
||||||
TextEditor::TextEditorActionHandler::Format
|
TextEditorActionHandler::Format
|
||||||
| TextEditor::TextEditorActionHandler::UnCommentSelection
|
| TextEditorActionHandler::UnCommentSelection
|
||||||
| TextEditor::TextEditorActionHandler::UnCollapseAll);
|
| TextEditorActionHandler::UnCollapseAll);
|
||||||
m_actionHandler->initializeActions();
|
m_actionHandler->initializeActions();
|
||||||
|
|
||||||
Core::ActionContainer *contextMenu = Core::ActionManager::createMenu(GLSLEditor::Constants::M_CONTEXT);
|
ActionContainer *contextMenu = ActionManager::createMenu(GLSLEditor::Constants::M_CONTEXT);
|
||||||
Core::ActionContainer *glslToolsMenu = Core::ActionManager::createMenu(Core::Id(Constants::M_TOOLS_GLSL));
|
ActionContainer *glslToolsMenu = ActionManager::createMenu(Id(Constants::M_TOOLS_GLSL));
|
||||||
glslToolsMenu->setOnAllDisabledBehavior(Core::ActionContainer::Hide);
|
glslToolsMenu->setOnAllDisabledBehavior(ActionContainer::Hide);
|
||||||
QMenu *menu = glslToolsMenu->menu();
|
QMenu *menu = glslToolsMenu->menu();
|
||||||
//: GLSL sub-menu in the Tools menu
|
//: GLSL sub-menu in the Tools menu
|
||||||
menu->setTitle(tr("GLSL"));
|
menu->setTitle(tr("GLSL"));
|
||||||
Core::ActionManager::actionContainer(Core::Constants::M_TOOLS)->addMenu(glslToolsMenu);
|
ActionManager::actionContainer(Core::Constants::M_TOOLS)->addMenu(glslToolsMenu);
|
||||||
|
|
||||||
Core::Command *cmd = 0;
|
Command *cmd = 0;
|
||||||
|
|
||||||
// Insert marker for "Refactoring" menu:
|
// Insert marker for "Refactoring" menu:
|
||||||
Core::Context globalContext(Core::Constants::C_GLOBAL);
|
Context globalContext(Core::Constants::C_GLOBAL);
|
||||||
Core::Command *sep = contextMenu->addSeparator(globalContext);
|
Command *sep = contextMenu->addSeparator(globalContext);
|
||||||
sep->action()->setObjectName(QLatin1String(Constants::M_REFACTORING_MENU_INSERTION_POINT));
|
sep->action()->setObjectName(QLatin1String(Constants::M_REFACTORING_MENU_INSERTION_POINT));
|
||||||
contextMenu->addSeparator(globalContext);
|
contextMenu->addSeparator(globalContext);
|
||||||
|
|
||||||
cmd = Core::ActionManager::command(TextEditor::Constants::UN_COMMENT_SELECTION);
|
cmd = ActionManager::command(TextEditor::Constants::UN_COMMENT_SELECTION);
|
||||||
contextMenu->addAction(cmd);
|
contextMenu->addAction(cmd);
|
||||||
|
|
||||||
errorMessage->clear();
|
errorMessage->clear();
|
||||||
|
|
||||||
Core::FileIconProvider *iconProvider = Core::FileIconProvider::instance();
|
FileIconProvider *iconProvider = FileIconProvider::instance();
|
||||||
Core::MimeDatabase *mimeDatabase = Core::ICore::mimeDatabase();
|
MimeDatabase *mimeDatabase = ICore::mimeDatabase();
|
||||||
iconProvider->registerIconOverlayForMimeType(QIcon(QLatin1String(":/glsleditor/images/glslfile.png")),
|
iconProvider->registerIconOverlayForMimeType(QIcon(QLatin1String(":/glsleditor/images/glslfile.png")),
|
||||||
mimeDatabase->findByType(QLatin1String(GLSLEditor::Constants::GLSL_MIMETYPE)));
|
mimeDatabase->findByType(QLatin1String(GLSLEditor::Constants::GLSL_MIMETYPE)));
|
||||||
iconProvider->registerIconOverlayForMimeType(QIcon(QLatin1String(":/glsleditor/images/glslfile.png")),
|
iconProvider->registerIconOverlayForMimeType(QIcon(QLatin1String(":/glsleditor/images/glslfile.png")),
|
||||||
@@ -159,8 +159,8 @@ bool GLSLEditorPlugin::initialize(const QStringList & /*arguments*/, QString *er
|
|||||||
iconProvider->registerIconOverlayForMimeType(QIcon(QLatin1String(":/glsleditor/images/glslfile.png")),
|
iconProvider->registerIconOverlayForMimeType(QIcon(QLatin1String(":/glsleditor/images/glslfile.png")),
|
||||||
mimeDatabase->findByType(QLatin1String(GLSLEditor::Constants::GLSL_MIMETYPE_FRAG_ES)));
|
mimeDatabase->findByType(QLatin1String(GLSLEditor::Constants::GLSL_MIMETYPE_FRAG_ES)));
|
||||||
|
|
||||||
QObject *core = Core::ICore::instance();
|
QObject *core = ICore::instance();
|
||||||
Core::BaseFileWizardParameters fragWizardParameters(Core::IWizard::FileWizard);
|
BaseFileWizardParameters fragWizardParameters(IWizard::FileWizard);
|
||||||
fragWizardParameters.setCategory(QLatin1String(Constants::WIZARD_CATEGORY_GLSL));
|
fragWizardParameters.setCategory(QLatin1String(Constants::WIZARD_CATEGORY_GLSL));
|
||||||
fragWizardParameters.setDisplayCategory(QCoreApplication::translate("GLSLEditor", Constants::WIZARD_TR_CATEGORY_GLSL));
|
fragWizardParameters.setDisplayCategory(QCoreApplication::translate("GLSLEditor", Constants::WIZARD_TR_CATEGORY_GLSL));
|
||||||
fragWizardParameters.setDescription
|
fragWizardParameters.setDescription
|
||||||
@@ -172,7 +172,7 @@ bool GLSLEditorPlugin::initialize(const QStringList & /*arguments*/, QString *er
|
|||||||
fragWizardParameters.setId(QLatin1String("F.GLSL"));
|
fragWizardParameters.setId(QLatin1String("F.GLSL"));
|
||||||
addAutoReleasedObject(new GLSLFileWizard(fragWizardParameters, GLSLFileWizard::FragmentShaderES, core));
|
addAutoReleasedObject(new GLSLFileWizard(fragWizardParameters, GLSLFileWizard::FragmentShaderES, core));
|
||||||
|
|
||||||
Core::BaseFileWizardParameters vertWizardParameters(Core::IWizard::FileWizard);
|
BaseFileWizardParameters vertWizardParameters(IWizard::FileWizard);
|
||||||
vertWizardParameters.setCategory(QLatin1String(Constants::WIZARD_CATEGORY_GLSL));
|
vertWizardParameters.setCategory(QLatin1String(Constants::WIZARD_CATEGORY_GLSL));
|
||||||
vertWizardParameters.setDisplayCategory(QCoreApplication::translate("GLSLEditor", Constants::WIZARD_TR_CATEGORY_GLSL));
|
vertWizardParameters.setDisplayCategory(QCoreApplication::translate("GLSLEditor", Constants::WIZARD_TR_CATEGORY_GLSL));
|
||||||
vertWizardParameters.setDescription
|
vertWizardParameters.setDescription
|
||||||
@@ -212,28 +212,14 @@ void GLSLEditorPlugin::extensionsInitialized()
|
|||||||
ExtensionSystem::IPlugin::ShutdownFlag GLSLEditorPlugin::aboutToShutdown()
|
ExtensionSystem::IPlugin::ShutdownFlag GLSLEditorPlugin::aboutToShutdown()
|
||||||
{
|
{
|
||||||
// delete GLSL::Icons::instance(); // delete object held by singleton
|
// delete GLSL::Icons::instance(); // delete object held by singleton
|
||||||
|
|
||||||
return IPlugin::aboutToShutdown();
|
return IPlugin::aboutToShutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLSLEditorPlugin::initializeEditor(GLSLEditor::GLSLTextEditorWidget *editor)
|
void GLSLEditorPlugin::initializeEditor(GLSLEditor::GLSLTextEditorWidget *editor)
|
||||||
{
|
{
|
||||||
QTC_CHECK(m_instance);
|
QTC_CHECK(m_instance);
|
||||||
|
|
||||||
m_actionHandler->setupActions(editor);
|
m_actionHandler->setupActions(editor);
|
||||||
|
TextEditorSettings::instance()->initializeEditor(editor);
|
||||||
TextEditor::TextEditorSettings::instance()->initializeEditor(editor);
|
|
||||||
}
|
|
||||||
|
|
||||||
Core::Command *GLSLEditorPlugin::addToolAction(QAction *a,
|
|
||||||
Core::Context &context, const Core::Id &id,
|
|
||||||
Core::ActionContainer *c1, const QString &keySequence)
|
|
||||||
{
|
|
||||||
Core::Command *command = Core::ActionManager::registerAction(a, id, context);
|
|
||||||
if (!keySequence.isEmpty())
|
|
||||||
command->setDefaultKeySequence(QKeySequence(keySequence));
|
|
||||||
c1->addAction(command);
|
|
||||||
return command;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GLSLEditorPlugin::InitFile *GLSLEditorPlugin::getInitFile(const QString &fileName, InitFile **initFile) const
|
GLSLEditorPlugin::InitFile *GLSLEditorPlugin::getInitFile(const QString &fileName, InitFile **initFile) const
|
||||||
@@ -247,10 +233,7 @@ GLSLEditorPlugin::InitFile *GLSLEditorPlugin::getInitFile(const QString &fileNam
|
|||||||
|
|
||||||
QByteArray GLSLEditorPlugin::glslFile(const QString &fileName) const
|
QByteArray GLSLEditorPlugin::glslFile(const QString &fileName) const
|
||||||
{
|
{
|
||||||
QString path = Core::ICore::resourcePath();
|
QFile file(ICore::resourcePath() + QLatin1String("/glsl/") + fileName);
|
||||||
path += QLatin1String("/glsl/");
|
|
||||||
path += fileName;
|
|
||||||
QFile file(path);
|
|
||||||
if (file.open(QFile::ReadOnly))
|
if (file.open(QFile::ReadOnly))
|
||||||
return file.readAll();
|
return file.readAll();
|
||||||
return QByteArray();
|
return QByteArray();
|
||||||
@@ -291,4 +274,7 @@ const GLSLEditorPlugin::InitFile *GLSLEditorPlugin::shaderInit(int variant) cons
|
|||||||
return getInitFile(QLatin1String("glsl_es_100_common.glsl"), &m_glsl_es_100_common);
|
return getInitFile(QLatin1String("glsl_es_100_common.glsl"), &m_glsl_es_100_common);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace Internal
|
||||||
|
} // namespace GLSLEditor
|
||||||
|
|
||||||
Q_EXPORT_PLUGIN(GLSLEditorPlugin)
|
Q_EXPORT_PLUGIN(GLSLEditorPlugin)
|
||||||
|
|||||||
@@ -33,14 +33,15 @@
|
|||||||
#include <extensionsystem/iplugin.h>
|
#include <extensionsystem/iplugin.h>
|
||||||
#include <coreplugin/icontext.h>
|
#include <coreplugin/icontext.h>
|
||||||
#include <coreplugin/id.h>
|
#include <coreplugin/id.h>
|
||||||
#include <QPointer>
|
|
||||||
#include <glsl/glsl.h>
|
#include <glsl/glsl.h>
|
||||||
|
|
||||||
|
#include <QPointer>
|
||||||
|
|
||||||
QT_FORWARD_DECLARE_CLASS(QAction)
|
QT_FORWARD_DECLARE_CLASS(QAction)
|
||||||
QT_FORWARD_DECLARE_CLASS(QTimer)
|
|
||||||
|
|
||||||
namespace TextEditor {
|
namespace TextEditor {
|
||||||
class TextEditorActionHandler;
|
class TextEditorActionHandler;
|
||||||
|
class ITextEditor;
|
||||||
} // namespace TextEditor
|
} // namespace TextEditor
|
||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
@@ -49,14 +50,6 @@ class ActionContainer;
|
|||||||
class ActionManager;
|
class ActionManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace TextEditor {
|
|
||||||
class ITextEditor;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace GLSL {
|
|
||||||
class ModelManagerInterface;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace GLSLEditor {
|
namespace GLSLEditor {
|
||||||
|
|
||||||
class GLSLTextEditorWidget;
|
class GLSLTextEditorWidget;
|
||||||
@@ -64,8 +57,6 @@ class GLSLTextEditorWidget;
|
|||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
class GLSLEditorFactory;
|
class GLSLEditorFactory;
|
||||||
class GLSLPreviewRunner;
|
|
||||||
class GLSLQuickFixCollector;
|
|
||||||
|
|
||||||
class GLSLEditorPlugin : public ExtensionSystem::IPlugin
|
class GLSLEditorPlugin : public ExtensionSystem::IPlugin
|
||||||
{
|
{
|
||||||
@@ -74,26 +65,27 @@ class GLSLEditorPlugin : public ExtensionSystem::IPlugin
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
GLSLEditorPlugin();
|
GLSLEditorPlugin();
|
||||||
virtual ~GLSLEditorPlugin();
|
~GLSLEditorPlugin();
|
||||||
|
|
||||||
// IPlugin
|
// IPlugin
|
||||||
bool initialize(const QStringList &arguments, QString *errorMessage = 0);
|
bool initialize(const QStringList &arguments, QString *errorMessage = 0);
|
||||||
void extensionsInitialized();
|
void extensionsInitialized();
|
||||||
ShutdownFlag aboutToShutdown();
|
ShutdownFlag aboutToShutdown();
|
||||||
|
|
||||||
static GLSLEditorPlugin *instance()
|
static GLSLEditorPlugin *instance() { return m_instance; }
|
||||||
{ return m_instance; }
|
|
||||||
|
|
||||||
void initializeEditor(GLSLEditor::GLSLTextEditorWidget *editor);
|
void initializeEditor(GLSLEditor::GLSLTextEditorWidget *editor);
|
||||||
|
|
||||||
struct InitFile {
|
struct InitFile
|
||||||
GLSL::Engine *engine;
|
{
|
||||||
GLSL::TranslationUnitAST *ast;
|
|
||||||
|
|
||||||
InitFile(GLSL::Engine *engine = 0, GLSL::TranslationUnitAST *ast = 0)
|
InitFile(GLSL::Engine *engine = 0, GLSL::TranslationUnitAST *ast = 0)
|
||||||
: engine(engine), ast(ast) {}
|
: engine(engine), ast(ast)
|
||||||
|
{}
|
||||||
|
|
||||||
~InitFile();
|
~InitFile();
|
||||||
|
|
||||||
|
GLSL::Engine *engine;
|
||||||
|
GLSL::TranslationUnitAST *ast;
|
||||||
};
|
};
|
||||||
|
|
||||||
const InitFile *fragmentShaderInit(int variant) const;
|
const InitFile *fragmentShaderInit(int variant) const;
|
||||||
@@ -105,10 +97,6 @@ private:
|
|||||||
InitFile *getInitFile(const QString &fileName, InitFile **initFile) const;
|
InitFile *getInitFile(const QString &fileName, InitFile **initFile) const;
|
||||||
void parseGlslFile(const QString &fileName, InitFile *initFile) const;
|
void parseGlslFile(const QString &fileName, InitFile *initFile) const;
|
||||||
|
|
||||||
// FIXME: Unused?
|
|
||||||
Core::Command *addToolAction(QAction *a, Core::Context &context, const Core::Id &name,
|
|
||||||
Core::ActionContainer *c1, const QString &keySequence);
|
|
||||||
|
|
||||||
static GLSLEditorPlugin *m_instance;
|
static GLSLEditorPlugin *m_instance;
|
||||||
|
|
||||||
GLSLEditorFactory *m_editor;
|
GLSLEditorFactory *m_editor;
|
||||||
|
|||||||
Reference in New Issue
Block a user