Commit e82b9b9d authored by hjk's avatar hjk
Browse files

GlslEditor: General editor related code consolidation



Merge editor files, convert to new editor setup scheme,
fix names according to convention.

Change-Id: I13682c0c86ac22e4cba3a826505248c7a0291a55
Reviewed-by: default avatarChristian Stenger <christian.stenger@digia.com>
parent d85a4f61
...@@ -28,7 +28,6 @@ ...@@ -28,7 +28,6 @@
****************************************************************************/ ****************************************************************************/
#include "glsleditor.h" #include "glsleditor.h"
#include "glsleditoreditable.h"
#include "glsleditorconstants.h" #include "glsleditorconstants.h"
#include "glsleditorplugin.h" #include "glsleditorplugin.h"
#include "glslhighlighter.h" #include "glslhighlighter.h"
...@@ -44,20 +43,29 @@ ...@@ -44,20 +43,29 @@
#include <coreplugin/actionmanager/actionmanager.h> #include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/actionmanager/actioncontainer.h> #include <coreplugin/actionmanager/actioncontainer.h>
#include <coreplugin/id.h>
#include <coreplugin/actionmanager/command.h> #include <coreplugin/actionmanager/command.h>
#include <coreplugin/editormanager/editormanager.h> #include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <coreplugin/id.h>
#include <coreplugin/mimedatabase.h> #include <coreplugin/mimedatabase.h>
#include <extensionsystem/pluginmanager.h> #include <extensionsystem/pluginmanager.h>
#include <texteditor/basetextdocument.h> #include <extensionsystem/pluginspec.h>
#include <texteditor/texteditorconstants.h>
#include <texteditor/syntaxhighlighter.h>
#include <texteditor/refactoroverlay.h> #include <texteditor/refactoroverlay.h>
#include <texteditor/syntaxhighlighter.h>
#include <texteditor/texteditoractionhandler.h>
#include <texteditor/texteditorconstants.h>
#include <texteditor/texteditorsettings.h>
#include <qmldesigner/qmldesignerconstants.h> #include <qmldesigner/qmldesignerconstants.h>
#include <utils/changeset.h> #include <utils/changeset.h>
#include <utils/qtcassert.h>
#include <utils/uncommentselection.h> #include <utils/uncommentselection.h>
#include <QCoreApplication>
#include <QSettings>
#include <QComboBox> #include <QComboBox>
#include <QFileInfo> #include <QFileInfo>
#include <QHeaderView> #include <QHeaderView>
...@@ -65,16 +73,17 @@ ...@@ -65,16 +73,17 @@
#include <QTimer> #include <QTimer>
#include <QTreeView> #include <QTreeView>
using namespace TextEditor;
using namespace GLSL; using namespace GLSL;
using namespace GLSLEditor; using namespace GLSLEditor::Constants;
using namespace GLSLEditor::Internal;
namespace GLSLEditor {
namespace Internal {
enum { enum {
UPDATE_DOCUMENT_DEFAULT_INTERVAL = 150 UPDATE_DOCUMENT_DEFAULT_INTERVAL = 150
}; };
namespace {
class CreateRanges: protected GLSL::Visitor class CreateRanges: protected GLSL::Visitor
{ {
QTextDocument *textDocument; QTextDocument *textDocument;
...@@ -100,14 +109,11 @@ protected: ...@@ -100,14 +109,11 @@ protected:
} }
}; };
} // end of anonymous namespace
Document::Document() Document::Document()
: _engine(0) : _engine(0)
, _ast(0) , _ast(0)
, _globalScope(0) , _globalScope(0)
{ {
} }
Document::~Document() Document::~Document()
...@@ -133,24 +139,21 @@ void Document::addRange(const QTextCursor &cursor, GLSL::Scope *scope) ...@@ -133,24 +139,21 @@ void Document::addRange(const QTextCursor &cursor, GLSL::Scope *scope)
_cursors.append(c); _cursors.append(c);
} }
GlslEditorWidget::GlslEditorWidget(const TextEditor::BaseTextDocumentPtr &doc) GlslEditorWidget::GlslEditorWidget()
{ {
setTextDocument(doc);
setAutoCompleter(new GLSLCompleter); setAutoCompleter(new GLSLCompleter);
m_outlineCombo = 0; m_outlineCombo = 0;
setParenthesesMatchingEnabled(true); setParenthesesMatchingEnabled(true);
setMarksVisible(true); setMarksVisible(true);
setCodeFoldingSupported(true); setCodeFoldingSupported(true);
m_updateDocumentTimer = new QTimer(this); m_updateDocumentTimer.setInterval(UPDATE_DOCUMENT_DEFAULT_INTERVAL);
m_updateDocumentTimer->setInterval(UPDATE_DOCUMENT_DEFAULT_INTERVAL); m_updateDocumentTimer.setSingleShot(true);
m_updateDocumentTimer->setSingleShot(true); connect(&m_updateDocumentTimer, &QTimer::timeout,
connect(m_updateDocumentTimer, SIGNAL(timeout()), this, SLOT(updateDocumentNow())); this, &GlslEditorWidget::updateDocumentNow);
connect(this, SIGNAL(textChanged()), this, SLOT(updateDocument())); connect(this, &QPlainTextEdit::textChanged,
[this]() { m_updateDocumentTimer.start(); });
new Highlighter(textDocument());
m_outlineCombo = new QComboBox; m_outlineCombo = new QComboBox;
m_outlineCombo->setMinimumContentsLength(22); m_outlineCombo->setMinimumContentsLength(22);
...@@ -171,7 +174,7 @@ GlslEditorWidget::GlslEditorWidget(const TextEditor::BaseTextDocumentPtr &doc) ...@@ -171,7 +174,7 @@ GlslEditorWidget::GlslEditorWidget(const TextEditor::BaseTextDocumentPtr &doc)
policy.setHorizontalPolicy(QSizePolicy::Expanding); policy.setHorizontalPolicy(QSizePolicy::Expanding);
m_outlineCombo->setSizePolicy(policy); m_outlineCombo->setSizePolicy(policy);
insertExtraToolBarWidget(TextEditor::BaseTextEditorWidget::Left, m_outlineCombo); insertExtraToolBarWidget(BaseTextEditorWidget::Left, m_outlineCombo);
// if (m_modelManager) { // if (m_modelManager) {
// m_semanticHighlighter->setModelManager(m_modelManager); // m_semanticHighlighter->setModelManager(m_modelManager);
...@@ -197,16 +200,10 @@ bool GlslEditorWidget::isOutdated() const ...@@ -197,16 +200,10 @@ bool GlslEditorWidget::isOutdated() const
return false; return false;
} }
Core::IEditor *GlslEditor::duplicate()
{
GlslEditorWidget *newEditor = new GlslEditorWidget(editorWidget()->textDocumentPtr());
return newEditor->editor();
}
bool GlslEditor::open(QString *errorString, const QString &fileName, const QString &realFileName) bool GlslEditor::open(QString *errorString, const QString &fileName, const QString &realFileName)
{ {
textDocument()->setMimeType(Core::MimeDatabase::findByFile(QFileInfo(fileName)).type()); textDocument()->setMimeType(Core::MimeDatabase::findByFile(QFileInfo(fileName)).type());
bool b = TextEditor::BaseTextEditor::open(errorString, fileName, realFileName); bool b = BaseTextEditor::open(errorString, fileName, realFileName);
return b; return b;
} }
...@@ -223,26 +220,21 @@ QString GlslEditorWidget::wordUnderCursor() const ...@@ -223,26 +220,21 @@ QString GlslEditorWidget::wordUnderCursor() const
return word; return word;
} }
TextEditor::BaseTextEditor *GlslEditorWidget::createEditor() BaseTextEditor *GlslEditorWidget::createEditor()
{ {
return new GlslEditor; QTC_ASSERT("should not happen anymore" && false, return 0);
}
void GlslEditorWidget::updateDocument()
{
m_updateDocumentTimer->start();
} }
void GlslEditorWidget::updateDocumentNow() void GlslEditorWidget::updateDocumentNow()
{ {
m_updateDocumentTimer->stop(); m_updateDocumentTimer.stop();
int variant = languageVariant(textDocument()->mimeType()); int variant = languageVariant(textDocument()->mimeType());
const QString contents = toPlainText(); // get the code from the editor const QString contents = toPlainText(); // get the code from the editor
const QByteArray preprocessedCode = contents.toLatin1(); // ### use the QtCreator C++ preprocessor. const QByteArray preprocessedCode = contents.toLatin1(); // ### use the QtCreator C++ preprocessor.
Document::Ptr doc(new Document()); Document::Ptr doc(new Document());
GLSL::Engine *engine = new GLSL::Engine(); Engine *engine = new GLSL::Engine();
doc->_engine = new GLSL::Engine(); doc->_engine = new GLSL::Engine();
Parser parser(doc->_engine, preprocessedCode.constData(), preprocessedCode.size(), variant); Parser parser(doc->_engine, preprocessedCode.constData(), preprocessedCode.size(), variant);
TranslationUnitAST *ast = parser.parse(); TranslationUnitAST *ast = parser.parse();
...@@ -336,11 +328,10 @@ int GlslEditorWidget::languageVariant(const QString &type) ...@@ -336,11 +328,10 @@ int GlslEditorWidget::languageVariant(const QString &type)
return variant; return variant;
} }
TextEditor::IAssistInterface *GlslEditorWidget::createAssistInterface( IAssistInterface *GlslEditorWidget::createAssistInterface(
TextEditor::AssistKind kind, AssistKind kind, AssistReason reason) const
TextEditor::AssistReason reason) const
{ {
if (kind == TextEditor::Completion) if (kind == Completion)
return new GLSLCompletionAssistInterface(document(), return new GLSLCompletionAssistInterface(document(),
position(), position(),
editor()->document()->filePath(), editor()->document()->filePath(),
...@@ -349,3 +340,59 @@ TextEditor::IAssistInterface *GlslEditorWidget::createAssistInterface( ...@@ -349,3 +340,59 @@ TextEditor::IAssistInterface *GlslEditorWidget::createAssistInterface(
m_glslDocument); m_glslDocument);
return BaseTextEditorWidget::createAssistInterface(kind, reason); return BaseTextEditorWidget::createAssistInterface(kind, reason);
} }
//////////////////////////////////////////////////////////////////
//
// GlslEditor
//
//////////////////////////////////////////////////////////////////
GlslEditor::GlslEditor()
{
addContext(C_GLSLEDITOR_ID);
setDuplicateSupported(true);
setCommentStyle(Utils::CommentDefinition::CppStyle);
setCompletionAssistProvider(ExtensionSystem::PluginManager::getObject<GLSLCompletionAssistProvider>());
setEditorCreator([]() { return new GlslEditor; });
setWidgetCreator([]() { return new GlslEditorWidget; });
setDocumentCreator([]() -> BaseTextDocument * {
auto doc = new BaseTextDocument(C_GLSLEDITOR_ID);
doc->setIndenter(new GLSLIndenter);
new Highlighter(doc);
return doc;
});
}
//////////////////////////////////////////////////////////////////
//
// GlslEditorFactory
//
//////////////////////////////////////////////////////////////////
GlslEditorFactory::GlslEditorFactory()
{
setId(C_GLSLEDITOR_ID);
setDisplayName(qApp->translate("OpenWith::Editors", C_GLSLEDITOR_DISPLAY_NAME));
addMimeType(GLSL_MIMETYPE);
addMimeType(GLSL_MIMETYPE_VERT);
addMimeType(GLSL_MIMETYPE_FRAG);
addMimeType(GLSL_MIMETYPE_VERT_ES);
addMimeType(GLSL_MIMETYPE_FRAG_ES);
new TextEditorActionHandler(this, C_GLSLEDITOR_ID,
TextEditorActionHandler::Format
| TextEditorActionHandler::UnCommentSelection
| TextEditorActionHandler::UnCollapseAll);
}
Core::IEditor *GlslEditorFactory::createEditor()
{
return new GlslEditor;
}
} // namespace Internal
} // namespace GLSLEditor
...@@ -31,13 +31,14 @@ ...@@ -31,13 +31,14 @@
#define GLSLEDITOR_H #define GLSLEDITOR_H
#include <texteditor/basetexteditor.h> #include <texteditor/basetexteditor.h>
#include <coreplugin/editormanager/ieditorfactory.h>
#include <QSharedPointer> #include <QSharedPointer>
#include <QSet> #include <QSet>
#include <QTimer>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QComboBox; class QComboBox;
class QTimer;
QT_END_NAMESPACE QT_END_NAMESPACE
namespace GLSL { namespace GLSL {
...@@ -86,7 +87,7 @@ class GlslEditorWidget : public TextEditor::BaseTextEditorWidget ...@@ -86,7 +87,7 @@ class GlslEditorWidget : public TextEditor::BaseTextEditorWidget
Q_OBJECT Q_OBJECT
public: public:
GlslEditorWidget(const TextEditor::BaseTextDocumentPtr &doc); GlslEditorWidget();
int editorRevision() const; int editorRevision() const;
bool isOutdated() const; bool isOutdated() const;
...@@ -98,22 +99,38 @@ public: ...@@ -98,22 +99,38 @@ public:
TextEditor::IAssistInterface *createAssistInterface(TextEditor::AssistKind assistKind, TextEditor::IAssistInterface *createAssistInterface(TextEditor::AssistKind assistKind,
TextEditor::AssistReason reason) const; TextEditor::AssistReason reason) const;
private slots: private:
void updateDocument();
void updateDocumentNow();
protected:
TextEditor::BaseTextEditor *createEditor(); TextEditor::BaseTextEditor *createEditor();
private: void updateDocumentNow();
void setSelectedElements(); void setSelectedElements();
QString wordUnderCursor() const; QString wordUnderCursor() const;
QTimer *m_updateDocumentTimer; QTimer m_updateDocumentTimer;
QComboBox *m_outlineCombo; QComboBox *m_outlineCombo;
Document::Ptr m_glslDocument; Document::Ptr m_glslDocument;
}; };
class GlslEditor : public TextEditor::BaseTextEditor
{
Q_OBJECT
public:
GlslEditor();
bool open(QString *errorString, const QString &fileName, const QString &realFileName);
};
class GlslEditorFactory : public Core::IEditorFactory
{
Q_OBJECT
public:
GlslEditorFactory();
Core::IEditor *createEditor();
};
} // namespace Internal } // namespace Internal
} // namespace GLSLEditor } // namespace GLSLEditor
......
...@@ -6,8 +6,6 @@ DEFINES += \ ...@@ -6,8 +6,6 @@ DEFINES += \
HEADERS += \ HEADERS += \
glsleditor.h \ glsleditor.h \
glsleditorconstants.h \ glsleditorconstants.h \
glsleditoreditable.h \
glsleditorfactory.h \
glsleditorplugin.h \ glsleditorplugin.h \
glslfilewizard.h \ glslfilewizard.h \
glslhighlighter.h \ glslhighlighter.h \
...@@ -19,8 +17,6 @@ glslhoverhandler.h \ ...@@ -19,8 +17,6 @@ glslhoverhandler.h \
SOURCES += \ SOURCES += \
glsleditor.cpp \ glsleditor.cpp \
glsleditoreditable.cpp \
glsleditorfactory.cpp \
glsleditorplugin.cpp \ glsleditorplugin.cpp \
glslfilewizard.cpp \ glslfilewizard.cpp \
glslhighlighter.cpp \ glslhighlighter.cpp \
......
...@@ -24,10 +24,6 @@ QtcPlugin { ...@@ -24,10 +24,6 @@ QtcPlugin {
"glsleditor.h", "glsleditor.h",
"glsleditor.qrc", "glsleditor.qrc",
"glsleditorconstants.h", "glsleditorconstants.h",
"glsleditoreditable.cpp",
"glsleditoreditable.h",
"glsleditorfactory.cpp",
"glsleditorfactory.h",
"glsleditorplugin.cpp", "glsleditorplugin.cpp",
"glsleditorplugin.h", "glsleditorplugin.h",
"glslfilewizard.cpp", "glslfilewizard.cpp",
......
...@@ -35,7 +35,6 @@ ...@@ -35,7 +35,6 @@
namespace GLSLEditor { namespace GLSLEditor {
namespace Constants { namespace Constants {
// menus
const char M_CONTEXT[] = "GLSL Editor.ContextMenu"; const char M_CONTEXT[] = "GLSL Editor.ContextMenu";
const char M_TOOLS_GLSL[] = "GLSLEditor.Tools.Menu"; const char M_TOOLS_GLSL[] = "GLSLEditor.Tools.Menu";
......
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** 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.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#include "glsleditoreditable.h"
#include "glsleditorconstants.h"
#include "glslcompletionassist.h"
#include "glslautocompleter.h"
#include <texteditor/texteditorconstants.h>
#include <coreplugin/icore.h>
#include <extensionsystem/pluginmanager.h>
namespace GLSLEditor {
namespace Internal {
GlslEditor::GlslEditor()
{
setContext(Core::Context(GLSLEditor::Constants::C_GLSLEDITOR_ID,
TextEditor::Constants::C_TEXTEDITOR));
setDuplicateSupported(true);
setCommentStyle(Utils::CommentDefinition::CppStyle);
setCompletionAssistProvider(ExtensionSystem::PluginManager::getObject<GLSLCompletionAssistProvider>());
}
} // namespace Internal
} // namespace GLSLEditor
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** 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.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#ifndef GLSLEDITOREDITABLE_H
#define GLSLEDITOREDITABLE_H
#include <texteditor/basetexteditor.h>
namespace GLSLEditor {
namespace Internal {
class GlslEditor : public TextEditor::BaseTextEditor
{
Q_OBJECT
public:
GlslEditor();
Core::IEditor *duplicate();
bool open(QString *errorString, const QString &fileName, const QString &realFileName);
};
} // namespace Internal
} // namespace GLSLEditor
#endif // GLSLEDITOREDITABLE_H
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** 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.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#include "glsleditorfactory.h"
#include "glsleditoreditable.h"
#include "glsleditor.h"
#include "glsleditorconstants.h"
#include "glsleditorplugin.h"
#include "glslindenter.h"
#include <extensionsystem/pluginmanager.h>
#include <extensionsystem/pluginspec.h>