blob: 5d238a4f2b49edd30abb926d0686cb761919190e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "glsleditorplugin.h"
#include "glslcompletionassist.h"
#include "glsleditor.h"
#include "glsleditorconstants.h"
#include "glsleditortr.h"
#include "glslhighlighter.h"
#include <glsl/glslengine.h>
#include <glsl/glslparser.h>
#include <glsl/glsllexer.h>
#include <coreplugin/actionmanager/actioncontainer.h>
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/actionmanager/command.h>
#include <coreplugin/coreconstants.h>
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/icore.h>
#include <utils/fsengine/fileiconprovider.h>
#include <QMenu>
using namespace Core;
using namespace Utils;
namespace GlslEditor {
namespace 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"};
GlslEditorFactory editorFactory;
GlslCompletionAssistProvider completionAssistProvider;
};
static GlslEditorPluginPrivate *dd = nullptr;
GlslEditorPlugin::InitFile::InitFile(const QString &fileName)
: m_fileName(fileName)
{}
GlslEditorPlugin::InitFile::~InitFile()
{
delete m_engine;
}
void GlslEditorPlugin::InitFile::initialize() const
{
// Parse the builtins for any language variant so we can use all keywords.
const int variant = GLSL::Lexer::Variant_All;
QByteArray code;
QFile file(ICore::resourcePath("glsl").pathAppended(m_fileName).toString());
if (file.open(QFile::ReadOnly))
code = file.readAll();
m_engine = new GLSL::Engine();
GLSL::Parser parser(m_engine, code.constData(), code.size(), variant);
m_ast = parser.parse();
}
GLSL::TranslationUnitAST *GlslEditorPlugin::InitFile::ast() const
{
if (!m_ast)
initialize();
return m_ast;
}
GLSL::Engine *GlslEditorPlugin::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()
{
FileIconProvider::registerIconOverlayForMimeType(":/glsleditor/images/glslfile.png", Constants::GLSL_MIMETYPE);
FileIconProvider::registerIconOverlayForMimeType(":/glsleditor/images/glslfile.png", Constants::GLSL_MIMETYPE_VERT);
FileIconProvider::registerIconOverlayForMimeType(":/glsleditor/images/glslfile.png", Constants::GLSL_MIMETYPE_FRAG);
FileIconProvider::registerIconOverlayForMimeType(":/glsleditor/images/glslfile.png", Constants::GLSL_MIMETYPE_VERT_ES);
FileIconProvider::registerIconOverlayForMimeType(":/glsleditor/images/glslfile.png", Constants::GLSL_MIMETYPE_FRAG_ES);
}
const GlslEditorPlugin::InitFile *GlslEditorPlugin::fragmentShaderInit(int variant)
{
if (variant & GLSL::Lexer::Variant_GLSL_400)
return &dd->m_glsl_330_frag;
return (variant & GLSL::Lexer::Variant_GLSL_120)
? &dd->m_glsl_120_frag
: &dd->m_glsl_es_100_frag;
}
const GlslEditorPlugin::InitFile *GlslEditorPlugin::vertexShaderInit(int variant)
{
if (variant & GLSL::Lexer::Variant_GLSL_400)
return &dd->m_glsl_330_vert;
return (variant & GLSL::Lexer::Variant_GLSL_120)
? &dd->m_glsl_120_vert
: &dd->m_glsl_es_100_vert;
}
const GlslEditorPlugin::InitFile *GlslEditorPlugin::shaderInit(int variant)
{
if (variant & GLSL::Lexer::Variant_GLSL_400)
return &dd->m_glsl_330_common;
return (variant & GLSL::Lexer::Variant_GLSL_120)
? &dd->m_glsl_120_common
: &dd->m_glsl_es_100_common;
}
} // namespace Internal
} // namespace GlslEditor
|