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 "glsleditor.h"
|
|
|
|
|
#include "glsleditoreditable.h"
|
|
|
|
|
#include "glsleditorconstants.h"
|
|
|
|
|
#include "glsleditorplugin.h"
|
2010-11-10 15:44:59 +01:00
|
|
|
#include "glslhighlighter.h"
|
2010-11-26 10:59:33 +01:00
|
|
|
#include "glslautocompleter.h"
|
|
|
|
|
#include "glslindenter.h"
|
2011-04-15 16:19:23 +02:00
|
|
|
#include "glslcompletionassist.h"
|
2010-11-10 14:01:09 +01:00
|
|
|
|
2010-11-12 12:44:55 +01:00
|
|
|
#include <glsl/glsllexer.h>
|
|
|
|
|
#include <glsl/glslparser.h>
|
|
|
|
|
#include <glsl/glslengine.h>
|
2010-11-26 12:55:24 +01:00
|
|
|
#include <glsl/glslsemantic.h>
|
2010-11-26 15:00:46 +01:00
|
|
|
#include <glsl/glslsymbols.h>
|
2010-11-12 12:44:55 +01:00
|
|
|
|
2010-11-10 14:01:09 +01:00
|
|
|
#include <coreplugin/actionmanager/actionmanager.h>
|
|
|
|
|
#include <coreplugin/actionmanager/actioncontainer.h>
|
2011-09-05 16:10:37 +02:00
|
|
|
#include <coreplugin/id.h>
|
2010-11-10 14:01:09 +01:00
|
|
|
#include <coreplugin/actionmanager/command.h>
|
|
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
|
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
|
#include <coreplugin/mimedatabase.h>
|
|
|
|
|
#include <extensionsystem/pluginmanager.h>
|
|
|
|
|
#include <texteditor/basetextdocument.h>
|
|
|
|
|
#include <texteditor/fontsettings.h>
|
|
|
|
|
#include <texteditor/tabsettings.h>
|
|
|
|
|
#include <texteditor/texteditorconstants.h>
|
|
|
|
|
#include <texteditor/texteditorsettings.h>
|
|
|
|
|
#include <texteditor/syntaxhighlighter.h>
|
|
|
|
|
#include <texteditor/refactoroverlay.h>
|
|
|
|
|
#include <texteditor/tooltip/tooltip.h>
|
|
|
|
|
#include <qmldesigner/qmldesignerconstants.h>
|
|
|
|
|
#include <utils/changeset.h>
|
|
|
|
|
#include <utils/uncommentselection.h>
|
|
|
|
|
|
|
|
|
|
#include <QtCore/QFileInfo>
|
|
|
|
|
#include <QtCore/QSignalMapper>
|
|
|
|
|
#include <QtCore/QTimer>
|
2010-11-12 12:44:55 +01:00
|
|
|
#include <QtCore/QDebug>
|
2010-11-10 14:01:09 +01:00
|
|
|
|
|
|
|
|
#include <QtGui/QMenu>
|
|
|
|
|
#include <QtGui/QComboBox>
|
|
|
|
|
#include <QtGui/QHeaderView>
|
|
|
|
|
#include <QtGui/QInputDialog>
|
|
|
|
|
#include <QtGui/QMainWindow>
|
|
|
|
|
#include <QtGui/QToolBar>
|
|
|
|
|
#include <QtGui/QTreeView>
|
|
|
|
|
|
|
|
|
|
using namespace GLSL;
|
|
|
|
|
using namespace GLSLEditor;
|
|
|
|
|
using namespace GLSLEditor::Internal;
|
|
|
|
|
|
|
|
|
|
enum {
|
|
|
|
|
UPDATE_DOCUMENT_DEFAULT_INTERVAL = 150
|
|
|
|
|
};
|
|
|
|
|
|
2010-11-29 17:21:47 +01:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
class CreateRanges: protected GLSL::Visitor
|
|
|
|
|
{
|
|
|
|
|
QTextDocument *textDocument;
|
|
|
|
|
Document::Ptr glslDocument;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
CreateRanges(QTextDocument *textDocument, Document::Ptr glslDocument)
|
|
|
|
|
: textDocument(textDocument), glslDocument(glslDocument) {}
|
|
|
|
|
|
|
|
|
|
void operator()(GLSL::AST *ast) { accept(ast); }
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
using GLSL::Visitor::visit;
|
|
|
|
|
|
|
|
|
|
virtual void endVisit(GLSL::CompoundStatementAST *ast)
|
|
|
|
|
{
|
|
|
|
|
if (ast->symbol) {
|
|
|
|
|
QTextCursor tc(textDocument);
|
|
|
|
|
tc.setPosition(ast->start);
|
|
|
|
|
tc.setPosition(ast->end, QTextCursor::KeepAnchor);
|
|
|
|
|
glslDocument->addRange(tc, ast->symbol);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // end of anonymous namespace
|
|
|
|
|
|
|
|
|
|
Document::Document()
|
|
|
|
|
: _engine(0)
|
|
|
|
|
, _ast(0)
|
|
|
|
|
, _globalScope(0)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Document::~Document()
|
|
|
|
|
{
|
|
|
|
|
delete _globalScope;
|
|
|
|
|
delete _engine;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GLSL::Scope *Document::scopeAt(int position) const
|
|
|
|
|
{
|
|
|
|
|
foreach (const Range &c, _cursors) {
|
|
|
|
|
if (position >= c.cursor.selectionStart() && position <= c.cursor.selectionEnd())
|
|
|
|
|
return c.scope;
|
|
|
|
|
}
|
|
|
|
|
return _globalScope;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Document::addRange(const QTextCursor &cursor, GLSL::Scope *scope)
|
|
|
|
|
{
|
|
|
|
|
Range c;
|
|
|
|
|
c.cursor = cursor;
|
|
|
|
|
c.scope = scope;
|
|
|
|
|
_cursors.append(c);
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-21 16:02:26 +01:00
|
|
|
GLSLTextEditorWidget::GLSLTextEditorWidget(QWidget *parent) :
|
|
|
|
|
TextEditor::BaseTextEditorWidget(parent),
|
2010-11-10 14:01:09 +01:00
|
|
|
m_outlineCombo(0)
|
|
|
|
|
{
|
|
|
|
|
setParenthesesMatchingEnabled(true);
|
|
|
|
|
setMarksVisible(true);
|
|
|
|
|
setCodeFoldingSupported(true);
|
2010-11-26 10:59:33 +01:00
|
|
|
setIndenter(new GLSLIndenter());
|
|
|
|
|
setAutoCompleter(new GLSLCompleter());
|
2010-11-10 14:01:09 +01:00
|
|
|
|
|
|
|
|
m_updateDocumentTimer = new QTimer(this);
|
|
|
|
|
m_updateDocumentTimer->setInterval(UPDATE_DOCUMENT_DEFAULT_INTERVAL);
|
|
|
|
|
m_updateDocumentTimer->setSingleShot(true);
|
|
|
|
|
connect(m_updateDocumentTimer, SIGNAL(timeout()), this, SLOT(updateDocumentNow()));
|
|
|
|
|
|
|
|
|
|
connect(this, SIGNAL(textChanged()), this, SLOT(updateDocument()));
|
|
|
|
|
|
2011-08-02 12:26:00 +02:00
|
|
|
new Highlighter(baseTextDocument());
|
2010-11-10 14:01:09 +01:00
|
|
|
|
|
|
|
|
// if (m_modelManager) {
|
|
|
|
|
// m_semanticHighlighter->setModelManager(m_modelManager);
|
|
|
|
|
// connect(m_modelManager, SIGNAL(documentUpdated(GLSL::Document::Ptr)),
|
|
|
|
|
// this, SLOT(onDocumentUpdated(GLSL::Document::Ptr)));
|
|
|
|
|
// connect(m_modelManager, SIGNAL(libraryInfoUpdated(QString,GLSL::LibraryInfo)),
|
|
|
|
|
// this, SLOT(forceSemanticRehighlight()));
|
|
|
|
|
// connect(this->document(), SIGNAL(modificationChanged(bool)), this, SLOT(modificationChanged(bool)));
|
|
|
|
|
// }
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-21 16:02:26 +01:00
|
|
|
GLSLTextEditorWidget::~GLSLTextEditorWidget()
|
2010-11-10 14:01:09 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-21 16:02:26 +01:00
|
|
|
int GLSLTextEditorWidget::editorRevision() const
|
2010-11-10 14:01:09 +01:00
|
|
|
{
|
|
|
|
|
//return document()->revision();
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-21 16:02:26 +01:00
|
|
|
bool GLSLTextEditorWidget::isOutdated() const
|
2010-11-10 14:01:09 +01:00
|
|
|
{
|
|
|
|
|
// if (m_semanticInfo.revision() != editorRevision())
|
|
|
|
|
// return true;
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Core::IEditor *GLSLEditorEditable::duplicate(QWidget *parent)
|
|
|
|
|
{
|
2011-02-21 16:02:26 +01:00
|
|
|
GLSLTextEditorWidget *newEditor = new GLSLTextEditorWidget(parent);
|
|
|
|
|
newEditor->duplicateFrom(editorWidget());
|
2010-11-10 14:01:09 +01:00
|
|
|
GLSLEditorPlugin::instance()->initializeEditor(newEditor);
|
2011-02-21 16:02:26 +01:00
|
|
|
return newEditor->editor();
|
2010-11-10 14:01:09 +01:00
|
|
|
}
|
|
|
|
|
|
2011-11-10 11:36:51 +01:00
|
|
|
Core::Id GLSLEditorEditable::id() const
|
2010-11-10 14:01:09 +01:00
|
|
|
{
|
2011-11-10 11:36:51 +01:00
|
|
|
return GLSLEditor::Constants::C_GLSLEDITOR_ID;
|
2010-11-10 14:01:09 +01:00
|
|
|
}
|
|
|
|
|
|
2011-05-10 20:43:03 +02:00
|
|
|
bool GLSLEditorEditable::open(QString *errorString, const QString &fileName, const QString &realFileName)
|
2010-11-10 14:01:09 +01:00
|
|
|
{
|
2012-01-24 15:36:40 +01:00
|
|
|
editorWidget()->setMimeType(Core::ICore::mimeDatabase()->findByFile(QFileInfo(fileName)).type());
|
2011-05-10 20:43:03 +02:00
|
|
|
bool b = TextEditor::BaseTextEditor::open(errorString, fileName, realFileName);
|
2010-11-10 14:01:09 +01:00
|
|
|
return b;
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-21 16:02:26 +01:00
|
|
|
void GLSLTextEditorWidget::setFontSettings(const TextEditor::FontSettings &fs)
|
2010-11-10 14:01:09 +01:00
|
|
|
{
|
2011-02-21 16:02:26 +01:00
|
|
|
TextEditor::BaseTextEditorWidget::setFontSettings(fs);
|
2010-11-10 14:01:09 +01:00
|
|
|
Highlighter *highlighter = qobject_cast<Highlighter*>(baseTextDocument()->syntaxHighlighter());
|
|
|
|
|
if (!highlighter)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
NumberFormat,
|
|
|
|
|
StringFormat,
|
|
|
|
|
TypeFormat,
|
|
|
|
|
KeywordFormat,
|
|
|
|
|
LabelFormat,
|
|
|
|
|
CommentFormat,
|
|
|
|
|
VisualWhitespace,
|
|
|
|
|
*/
|
|
|
|
|
static QVector<QString> categories;
|
|
|
|
|
if (categories.isEmpty()) {
|
|
|
|
|
categories << QLatin1String(TextEditor::Constants::C_NUMBER)
|
|
|
|
|
<< QLatin1String(TextEditor::Constants::C_STRING)
|
|
|
|
|
<< QLatin1String(TextEditor::Constants::C_TYPE)
|
|
|
|
|
<< QLatin1String(TextEditor::Constants::C_KEYWORD)
|
2010-11-23 17:05:55 +10:00
|
|
|
<< QLatin1String(TextEditor::Constants::C_OPERATOR)
|
|
|
|
|
<< QLatin1String(TextEditor::Constants::C_PREPROCESSOR)
|
|
|
|
|
<< QLatin1String(TextEditor::Constants::C_LABEL)
|
2010-11-10 14:01:09 +01:00
|
|
|
<< QLatin1String(TextEditor::Constants::C_COMMENT)
|
2010-11-23 17:05:55 +10:00
|
|
|
<< QLatin1String(TextEditor::Constants::C_DOXYGEN_COMMENT)
|
|
|
|
|
<< QLatin1String(TextEditor::Constants::C_DOXYGEN_TAG)
|
|
|
|
|
<< QLatin1String(TextEditor::Constants::C_VISUAL_WHITESPACE)
|
|
|
|
|
<< QLatin1String(TextEditor::Constants::C_REMOVED_LINE);
|
2010-11-10 14:01:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
highlighter->setFormats(fs.toTextCharFormats(categories));
|
|
|
|
|
highlighter->rehighlight();
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-21 16:02:26 +01:00
|
|
|
QString GLSLTextEditorWidget::wordUnderCursor() const
|
2010-11-10 14:01:09 +01:00
|
|
|
{
|
|
|
|
|
QTextCursor tc = textCursor();
|
|
|
|
|
const QChar ch = characterAt(tc.position() - 1);
|
|
|
|
|
// make sure that we're not at the start of the next word.
|
|
|
|
|
if (ch.isLetterOrNumber() || ch == QLatin1Char('_'))
|
|
|
|
|
tc.movePosition(QTextCursor::Left);
|
|
|
|
|
tc.movePosition(QTextCursor::StartOfWord);
|
|
|
|
|
tc.movePosition(QTextCursor::EndOfWord, QTextCursor::KeepAnchor);
|
|
|
|
|
const QString word = tc.selectedText();
|
|
|
|
|
return word;
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-21 16:02:26 +01:00
|
|
|
TextEditor::BaseTextEditor *GLSLTextEditorWidget::createEditor()
|
2010-11-10 14:01:09 +01:00
|
|
|
{
|
|
|
|
|
GLSLEditorEditable *editable = new GLSLEditorEditable(this);
|
|
|
|
|
createToolBar(editable);
|
|
|
|
|
return editable;
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-25 15:58:02 +01:00
|
|
|
void GLSLTextEditorWidget::createToolBar(GLSLEditorEditable *editor)
|
2010-11-10 14:01:09 +01:00
|
|
|
{
|
|
|
|
|
m_outlineCombo = new QComboBox;
|
|
|
|
|
m_outlineCombo->setMinimumContentsLength(22);
|
2010-11-12 12:44:55 +01:00
|
|
|
|
|
|
|
|
// ### m_outlineCombo->setModel(m_outlineModel);
|
2010-11-10 14:01:09 +01:00
|
|
|
|
|
|
|
|
QTreeView *treeView = new QTreeView;
|
|
|
|
|
treeView->header()->hide();
|
|
|
|
|
treeView->setItemsExpandable(false);
|
|
|
|
|
treeView->setRootIsDecorated(false);
|
|
|
|
|
m_outlineCombo->setView(treeView);
|
|
|
|
|
treeView->expandAll();
|
|
|
|
|
|
|
|
|
|
//m_outlineCombo->setSizeAdjustPolicy(QComboBox::AdjustToContents);
|
|
|
|
|
|
|
|
|
|
// Make the combo box prefer to expand
|
|
|
|
|
QSizePolicy policy = m_outlineCombo->sizePolicy();
|
|
|
|
|
policy.setHorizontalPolicy(QSizePolicy::Expanding);
|
|
|
|
|
m_outlineCombo->setSizePolicy(policy);
|
|
|
|
|
|
2011-02-25 15:58:02 +01:00
|
|
|
editor->insertExtraToolBarWidget(TextEditor::BaseTextEditor::Left, m_outlineCombo);
|
2010-11-10 14:01:09 +01:00
|
|
|
}
|
|
|
|
|
|
2011-02-21 16:02:26 +01:00
|
|
|
bool GLSLTextEditorWidget::event(QEvent *e)
|
2010-11-10 14:01:09 +01:00
|
|
|
{
|
2011-02-21 16:02:26 +01:00
|
|
|
return BaseTextEditorWidget::event(e);
|
2010-11-10 14:01:09 +01:00
|
|
|
}
|
|
|
|
|
|
2011-02-21 16:02:26 +01:00
|
|
|
void GLSLTextEditorWidget::unCommentSelection()
|
2010-11-10 14:01:09 +01:00
|
|
|
{
|
|
|
|
|
Utils::unCommentSelection(this);
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-21 16:02:26 +01:00
|
|
|
void GLSLTextEditorWidget::updateDocument()
|
2010-11-10 14:01:09 +01:00
|
|
|
{
|
2010-11-12 12:44:55 +01:00
|
|
|
m_updateDocumentTimer->start();
|
2010-11-10 14:01:09 +01:00
|
|
|
}
|
|
|
|
|
|
2011-02-21 16:02:26 +01:00
|
|
|
void GLSLTextEditorWidget::updateDocumentNow()
|
2010-11-10 14:01:09 +01:00
|
|
|
{
|
2010-11-12 12:44:55 +01:00
|
|
|
m_updateDocumentTimer->stop();
|
|
|
|
|
|
2011-08-02 12:26:00 +02:00
|
|
|
int variant = languageVariant(mimeType());
|
2010-11-12 12:44:55 +01:00
|
|
|
const QString contents = toPlainText(); // get the code from the editor
|
|
|
|
|
const QByteArray preprocessedCode = contents.toLatin1(); // ### use the QtCreator C++ preprocessor.
|
|
|
|
|
|
2010-11-29 17:21:47 +01:00
|
|
|
Document::Ptr doc(new Document());
|
|
|
|
|
GLSL::Engine *engine = new GLSL::Engine();
|
|
|
|
|
doc->_engine = new GLSL::Engine();
|
|
|
|
|
Parser parser(doc->_engine, preprocessedCode.constData(), preprocessedCode.size(), variant);
|
2010-11-25 12:19:57 +01:00
|
|
|
TranslationUnitAST *ast = parser.parse();
|
2010-11-29 09:54:27 +01:00
|
|
|
if (ast != 0 || extraSelections(CodeWarningsSelection).isEmpty()) {
|
|
|
|
|
GLSLEditorPlugin *plugin = GLSLEditorPlugin::instance();
|
|
|
|
|
|
|
|
|
|
Semantic sem;
|
2010-11-29 17:21:47 +01:00
|
|
|
Scope *globalScope = engine->newNamespace();
|
|
|
|
|
doc->_globalScope = globalScope;
|
2010-12-01 10:04:56 +10:00
|
|
|
sem.translationUnit(plugin->shaderInit(variant)->ast, globalScope, plugin->shaderInit(variant)->engine);
|
2010-11-29 09:54:27 +01:00
|
|
|
if (variant & Lexer::Variant_VertexShader)
|
2010-12-01 10:04:56 +10:00
|
|
|
sem.translationUnit(plugin->vertexShaderInit(variant)->ast, globalScope, plugin->vertexShaderInit(variant)->engine);
|
2010-11-29 09:54:27 +01:00
|
|
|
if (variant & Lexer::Variant_FragmentShader)
|
2010-12-01 10:04:56 +10:00
|
|
|
sem.translationUnit(plugin->fragmentShaderInit(variant)->ast, globalScope, plugin->fragmentShaderInit(variant)->engine);
|
2010-11-29 17:21:47 +01:00
|
|
|
sem.translationUnit(ast, globalScope, engine);
|
|
|
|
|
|
|
|
|
|
CreateRanges createRanges(document(), doc);
|
|
|
|
|
createRanges(ast);
|
2010-11-29 09:54:27 +01:00
|
|
|
|
|
|
|
|
QTextCharFormat errorFormat;
|
|
|
|
|
errorFormat.setUnderlineStyle(QTextCharFormat::WaveUnderline);
|
|
|
|
|
errorFormat.setUnderlineColor(Qt::red);
|
|
|
|
|
|
|
|
|
|
QTextCharFormat warningFormat;
|
|
|
|
|
warningFormat.setUnderlineStyle(QTextCharFormat::WaveUnderline);
|
|
|
|
|
warningFormat.setUnderlineColor(Qt::darkYellow);
|
|
|
|
|
|
|
|
|
|
QList<QTextEdit::ExtraSelection> sels;
|
|
|
|
|
QSet<int> errors;
|
|
|
|
|
|
2010-11-29 17:21:47 +01:00
|
|
|
foreach (const DiagnosticMessage &m, engine->diagnosticMessages()) {
|
2010-11-29 09:54:27 +01:00
|
|
|
if (! m.line())
|
|
|
|
|
continue;
|
|
|
|
|
else if (errors.contains(m.line()))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
errors.insert(m.line());
|
|
|
|
|
|
|
|
|
|
QTextCursor cursor(document()->findBlockByNumber(m.line() - 1));
|
|
|
|
|
cursor.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor);
|
|
|
|
|
|
|
|
|
|
QTextEdit::ExtraSelection sel;
|
|
|
|
|
sel.cursor = cursor;
|
|
|
|
|
sel.format = m.isError() ? errorFormat : warningFormat;
|
|
|
|
|
sel.format.setToolTip(m.message());
|
|
|
|
|
sels.append(sel);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setExtraSelections(CodeWarningsSelection, sels);
|
2010-11-29 17:21:47 +01:00
|
|
|
m_glslDocument = doc;
|
2010-11-19 14:59:33 +01:00
|
|
|
}
|
2010-11-10 14:01:09 +01:00
|
|
|
}
|
2010-11-26 15:14:33 +01:00
|
|
|
|
2011-08-02 12:26:00 +02:00
|
|
|
int GLSLTextEditorWidget::languageVariant(const QString &type)
|
2010-11-26 15:14:33 +01:00
|
|
|
{
|
2010-12-01 11:49:36 +10:00
|
|
|
int variant = 0;
|
|
|
|
|
bool isVertex = false;
|
|
|
|
|
bool isFragment = false;
|
|
|
|
|
bool isDesktop = false;
|
|
|
|
|
if (type.isEmpty()) {
|
|
|
|
|
// ### Before file has been opened, so don't know the mime type.
|
|
|
|
|
isVertex = true;
|
|
|
|
|
isFragment = true;
|
|
|
|
|
} else if (type == QLatin1String("text/x-glsl") ||
|
|
|
|
|
type == QLatin1String("application/x-glsl")) {
|
|
|
|
|
isVertex = true;
|
|
|
|
|
isFragment = true;
|
|
|
|
|
isDesktop = true;
|
|
|
|
|
} else if (type == QLatin1String("text/x-glsl-vert")) {
|
|
|
|
|
isVertex = true;
|
|
|
|
|
isDesktop = true;
|
|
|
|
|
} else if (type == QLatin1String("text/x-glsl-frag")) {
|
|
|
|
|
isFragment = true;
|
|
|
|
|
isDesktop = true;
|
|
|
|
|
} else if (type == QLatin1String("text/x-glsl-es-vert")) {
|
|
|
|
|
isVertex = true;
|
|
|
|
|
} else if (type == QLatin1String("text/x-glsl-es-frag")) {
|
|
|
|
|
isFragment = true;
|
|
|
|
|
}
|
|
|
|
|
if (isDesktop)
|
|
|
|
|
variant |= Lexer::Variant_GLSL_120;
|
|
|
|
|
else
|
2010-12-01 12:30:07 +10:00
|
|
|
variant |= Lexer::Variant_GLSL_ES_100;
|
2010-12-01 11:49:36 +10:00
|
|
|
if (isVertex)
|
|
|
|
|
variant |= Lexer::Variant_VertexShader;
|
|
|
|
|
if (isFragment)
|
|
|
|
|
variant |= Lexer::Variant_FragmentShader;
|
|
|
|
|
return variant;
|
2010-11-26 15:14:33 +01:00
|
|
|
}
|
2010-11-29 17:21:47 +01:00
|
|
|
|
2011-02-21 16:02:26 +01:00
|
|
|
Document::Ptr GLSLTextEditorWidget::glslDocument() const
|
2010-11-29 17:21:47 +01:00
|
|
|
{
|
|
|
|
|
return m_glslDocument;
|
|
|
|
|
}
|
2011-04-15 16:19:23 +02:00
|
|
|
|
|
|
|
|
TextEditor::IAssistInterface *GLSLTextEditorWidget::createAssistInterface(
|
|
|
|
|
TextEditor::AssistKind kind,
|
|
|
|
|
TextEditor::AssistReason reason) const
|
|
|
|
|
{
|
|
|
|
|
if (kind == TextEditor::Completion)
|
|
|
|
|
return new GLSLCompletionAssistInterface(document(),
|
|
|
|
|
position(),
|
|
|
|
|
editor()->file(),
|
|
|
|
|
reason,
|
|
|
|
|
mimeType(),
|
|
|
|
|
glslDocument());
|
|
|
|
|
return BaseTextEditorWidget::createAssistInterface(kind, reason);
|
|
|
|
|
}
|