Commit f6eeed03 authored by Roberto Raggi's avatar Roberto Raggi

Initial import of the GLSL editor plug-in.

parent bc70a688
INCLUDEPATH += $$PWD/../../shared
INCLUDEPATH += $$PWD/../../shared/glsl $$PWD/../../shared/glsl/parser
DEPENDPATH += $$PWD/../../shared/glsl $$PWD/../../shared/glsl/parser
LIBS *= -l$$qtLibraryName(GLSL)
DEFINES += QT_CREATOR
<?xml version="1.0"?>
<mime-info xmlns='http://www.freedesktop.org/standards/shared-mime-info'>
<mime-type type="application/x-glsl">
<alias type="text/x-glsl"/>
<sub-class-of type="text/plain"/>
<comment>GLSL file</comment>
<glob pattern="*.glsl"/>
</mime-type>
</mime-info>
<plugin name=\"GLSLditor\" version=\"$$QTCREATOR_VERSION\" compatVersion=\"$$QTCREATOR_VERSION\">
<vendor>Nokia Corporation</vendor>
<copyright>(C) 2010 Nokia Corporation</copyright>
<license>
Commercial Usage
Licensees holding valid Qt Commercial licenses may use this plugin in accordance with the Qt Commercial License Agreement provided with the Software or, alternatively, in accordance with the terms contained in a written agreement between you and Nokia.
GNU Lesser General Public License Usage
Alternatively, this plugin may be used under the terms of the GNU Lesser General Public License version 2.1 as published by the Free Software Foundation. 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.
</license>
<category>GLSL</category>
<description>Editor for GLSL.</description>
<url>http://qt.nokia.com</url>
<dependencyList>
<dependency name=\"Core\" version=\"$$QTCREATOR_VERSION\"/>
<dependency name=\"TextEditor\" version=\"$$QTCREATOR_VERSION\"/>
<dependency name=\"ProjectExplorer\" version=\"$$QTCREATOR_VERSION\"/>
</dependencyList>
</plugin>
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, 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.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#include "glsleditor.h"
#include "glsleditoreditable.h"
#include "glsleditorconstants.h"
#include "glsleditorplugin.h"
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/actionmanager/actioncontainer.h>
#include <coreplugin/uniqueidmanager.h>
#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>
#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
};
GLSLTextEditor::GLSLTextEditor(QWidget *parent) :
TextEditor::BaseTextEditor(parent),
m_outlineCombo(0)
{
setParenthesesMatchingEnabled(true);
setMarksVisible(true);
setCodeFoldingSupported(true);
setCodeFoldingVisible(true);
//setIndenter(new Indenter);
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()));
// baseTextDocument()->setSyntaxHighlighter(new Highlighter(document()));
// 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)));
// }
}
GLSLTextEditor::~GLSLTextEditor()
{
}
int GLSLTextEditor::editorRevision() const
{
//return document()->revision();
return 0;
}
bool GLSLTextEditor::isOutdated() const
{
// if (m_semanticInfo.revision() != editorRevision())
// return true;
return false;
}
Core::IEditor *GLSLEditorEditable::duplicate(QWidget *parent)
{
GLSLTextEditor *newEditor = new GLSLTextEditor(parent);
newEditor->duplicateFrom(editor());
GLSLEditorPlugin::instance()->initializeEditor(newEditor);
return newEditor->editableInterface();
}
QString GLSLEditorEditable::id() const
{
return QLatin1String(GLSLEditor::Constants::C_GLSLEDITOR_ID);
}
bool GLSLEditorEditable::open(const QString &fileName)
{
bool b = TextEditor::BaseTextEditorEditable::open(fileName);
editor()->setMimeType(Core::ICore::instance()->mimeDatabase()->findByFile(QFileInfo(fileName)).type());
return b;
}
Core::Context GLSLEditorEditable::context() const
{
return m_context;
}
void GLSLTextEditor::setFontSettings(const TextEditor::FontSettings &fs)
{
TextEditor::BaseTextEditor::setFontSettings(fs);
#warning set up the GLSL highlighter
#if 0
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)
<< QLatin1String(TextEditor::Constants::C_FIELD)
<< QLatin1String(TextEditor::Constants::C_COMMENT)
<< QLatin1String(TextEditor::Constants::C_VISUAL_WHITESPACE);
}
highlighter->setFormats(fs.toTextCharFormats(categories));
highlighter->rehighlight();
#endif
}
QString GLSLTextEditor::wordUnderCursor() const
{
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;
}
TextEditor::BaseTextEditorEditable *GLSLTextEditor::createEditableInterface()
{
GLSLEditorEditable *editable = new GLSLEditorEditable(this);
createToolBar(editable);
return editable;
}
void GLSLTextEditor::createToolBar(GLSLEditorEditable *editable)
{
m_outlineCombo = new QComboBox;
m_outlineCombo->setMinimumContentsLength(22);
#warning set up the outline model
// m_outlineCombo->setModel(m_outlineModel);
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);
connect(m_outlineCombo, SIGNAL(activated(int)), this, SLOT(jumpToOutlineElement(int)));
connect(file(), SIGNAL(changed()), this, SLOT(updateFileName()));
QToolBar *toolBar = static_cast<QToolBar*>(editable->toolBar());
QList<QAction*> actions = toolBar->actions();
toolBar->insertWidget(actions.first(), m_outlineCombo);
}
bool GLSLTextEditor::event(QEvent *e)
{
return BaseTextEditor::event(e);
}
void GLSLTextEditor::unCommentSelection()
{
Utils::unCommentSelection(this);
}
void GLSLTextEditor::updateDocument()
{
}
void GLSLTextEditor::updateDocumentNow()
{
}
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, 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.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#ifndef GLSLEDITOR_H
#define GLSLEDITOR_H
#include "glsleditor_global.h"
#include "glsleditoreditable.h"
#include <texteditor/basetexteditor.h>
#include <texteditor/quickfix.h>
#include <QtCore/QSharedPointer>
QT_BEGIN_NAMESPACE
class QComboBox;
class QTimer;
QT_END_NAMESPACE
namespace Core {
class ICore;
}
namespace GLSLEditor {
class GLSLEDITOR_EXPORT GLSLTextEditor : public TextEditor::BaseTextEditor
{
Q_OBJECT
public:
GLSLTextEditor(QWidget *parent = 0);
~GLSLTextEditor();
virtual void unCommentSelection();
int editorRevision() const;
bool isOutdated() const;
public slots:
virtual void setFontSettings(const TextEditor::FontSettings &);
private slots:
void updateDocument();
void updateDocumentNow();
protected:
bool event(QEvent *e);
TextEditor::BaseTextEditorEditable *createEditableInterface();
void createToolBar(Internal::GLSLEditorEditable *editable);
private:
void setSelectedElements();
QString wordUnderCursor() const;
const Core::Context m_context;
QTimer *m_updateDocumentTimer;
QComboBox *m_outlineCombo;
};
} // namespace GLSLEditor
#endif // GLSLEDITOR_H
include(qmljseditor_dependencies.pri)
LIBS *= -l$$qtLibraryName(QmlJSEditor)
TEMPLATE = lib
TARGET = GLSLEditor
include(../../qtcreatorplugin.pri)
include(glsleditor_dependencies.pri)
DEFINES += \
GLSLEDITOR_LIBRARY \
QT_CREATOR
HEADERS += \
glsleditor.h \
glsleditor_global.h \
glsleditoractionhandler.h \
glsleditorconstants.h \
glsleditoreditable.h \
glsleditorfactory.h \
glsleditorplugin.h
SOURCES += \
glsleditor.cpp \
glsleditoractionhandler.cpp \
glsleditoreditable.cpp \
glsleditorfactory.cpp \
glsleditorplugin.cpp
OTHER_FILES += GLSLEditor.mimetypes.xml
<RCC>
<qresource prefix="/glsleditor">
<file>GLSLEditor.mimetypes.xml</file>
<file>images/glslfile.png</file>
</qresource>
</RCC>
include(../../plugins/coreplugin/coreplugin.pri)
include(../../plugins/texteditor/texteditor.pri)
include(../../plugins/projectexplorer/projectexplorer.pri)
include(../../libs/glsl/glsl.pri)
include(../../libs/utils/utils.pri)
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, 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.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#ifndef GLSLEDITOR_GLOBAL_H
#define GLSLEDITOR_GLOBAL_H
#include <QtGlobal>
#if defined(GLSLEDITOR_LIBRARY)
# define GLSLEDITOR_EXPORT Q_DECL_EXPORT
#else
# define GLSLEDITOR_EXPORT Q_DECL_IMPORT
#endif
#endif // GLSLEDITOR_GLOBAL_H
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, 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.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#include "glsleditoractionhandler.h"
#include "glsleditorconstants.h"
#include "glsleditor.h"
#include <coreplugin/icore.h>
#include <coreplugin/actionmanager/actionmanager.h>
#include <QtCore/QDebug>
#include <QtGui/QAction>
#include <QtGui/QMainWindow>
#include <QtGui/QMessageBox>
namespace GLSLEditor {
namespace Internal {
GLSLEditorActionHandler::GLSLEditorActionHandler()
: TextEditor::TextEditorActionHandler(GLSLEditor::Constants::C_GLSLEDITOR_ID, Format)
{
}
void GLSLEditorActionHandler::createActions()
{
TextEditor::TextEditorActionHandler::createActions();
}
} // namespace Internal
} // namespace GLSLEditor
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, 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.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#ifndef GLSLDITORACTIONHANDLER_H
#define GLSLDITORACTIONHANDLER_H
#include <texteditor/texteditoractionhandler.h>
namespace GLSLEditor {
namespace Internal {
class GLSLEditorActionHandler : public TextEditor::TextEditorActionHandler
{
Q_OBJECT
public:
GLSLEditorActionHandler();
void createActions();
};
} // namespace Internal
} // namespace GLSLEditor
#endif // GLSLDITORACTIONHANDLER_H
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, 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.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#ifndef GLSLEDITOR_CONSTANTS_H
#define GLSLEDITOR_CONSTANTS_H
#include <QtCore/QtGlobal>
namespace GLSLEditor {
namespace Constants {
// menus
const char * const M_CONTEXT = "GLSL Editor.ContextMenu";
const char * const M_TOOLS_GLSL = "GLSLEditor.Tools.Menu";
const char * const SEPARATOR1 = "GLSLEditor.Separator1";
const char * const SEPARATOR2 = "GLSLEditor.Separator2";
const char * const M_REFACTORING_MENU_INSERTION_POINT = "GLSLEditor.RefactorGroup";
const char * const RUN_SEP = "GLSLEditor.Run.Separator";
const char * const C_GLSLEDITOR_ID = "GLSLEditor.GLSLEditor";
const char * const C_GLSLEDITOR_DISPLAY_NAME = QT_TRANSLATE_NOOP("OpenWith::Editors", "GLSL Editor");
const char * const TASK_INDEX = "GLSLEditor.TaskIndex";
const char * const TASK_SEARCH = "GLSLEditor.TaskSearch";
const char * const GLSL_MIMETYPE = "application/x-glsl";
} // namespace Constants
} // namespace GLSLEditor
#endif // GLSLEDITOR_CONSTANTS_H
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).