forked from qt-creator/qt-creator
Snippets: Make it easier for plugins to add snippets groups
Groups are no longer enum values but identified from snippet providers.
This commit is contained in:
@@ -30,6 +30,7 @@
|
||||
#include "qmljscodecompletion.h"
|
||||
#include "qmlexpressionundercursor.h"
|
||||
#include "qmljseditor.h"
|
||||
#include "qmljseditorconstants.h"
|
||||
|
||||
#include <qmljs/qmljsmodelmanagerinterface.h>
|
||||
#include <qmljs/parser/qmljsast_p.h>
|
||||
@@ -487,7 +488,7 @@ CodeCompletion::CodeCompletion(ModelManagerInterface *modelManager, QObject *par
|
||||
m_editor(0),
|
||||
m_startPosition(0),
|
||||
m_restartCompletion(false),
|
||||
m_snippetProvider(TextEditor::Snippet::Qml, iconForColor(Qt::red), SnippetOrder)
|
||||
m_snippetProvider(Constants::QML_SNIPPETS_GROUP_ID, iconForColor(Qt::red), SnippetOrder)
|
||||
{
|
||||
Q_ASSERT(modelManager);
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
|
||||
#include <qmljs/qmljsdocument.h>
|
||||
#include <texteditor/icompletioncollector.h>
|
||||
#include <texteditor/snippets/snippetprovider.h>
|
||||
#include <texteditor/snippets/snippetcollector.h>
|
||||
#include <QtCore/QDateTime>
|
||||
#include <QtCore/QPointer>
|
||||
|
||||
@@ -97,7 +97,7 @@ private:
|
||||
TextEditor::ITextEditable *m_editor;
|
||||
int m_startPosition;
|
||||
bool m_restartCompletion;
|
||||
TextEditor::SnippetProvider m_snippetProvider;
|
||||
TextEditor::SnippetCollector m_snippetProvider;
|
||||
QList<TextEditor::CompletionItem> m_completions;
|
||||
QPointer<FunctionArgumentWidget> m_functionArgumentWidget;
|
||||
};
|
||||
|
||||
@@ -35,7 +35,7 @@ HEADERS += \
|
||||
qmljsindenter.h \
|
||||
qmljsautocompleter.h \
|
||||
jsfilewizard.h \
|
||||
qmljssnippeteditordecorator.h
|
||||
qmljssnippetprovider.h
|
||||
|
||||
SOURCES += \
|
||||
qmljscodecompletion.cpp \
|
||||
@@ -64,7 +64,7 @@ SOURCES += \
|
||||
qmljsindenter.cpp \
|
||||
qmljsautocompleter.cpp \
|
||||
jsfilewizard.cpp \
|
||||
qmljssnippeteditordecorator.cpp
|
||||
qmljssnippetprovider.cpp
|
||||
|
||||
RESOURCES += qmljseditor.qrc
|
||||
OTHER_FILES += QmlJSEditor.mimetypes.xml
|
||||
|
||||
@@ -60,6 +60,7 @@ const char *const TASK_CATEGORY_QML = "Task.Category.Qml";
|
||||
const char * const WIZARD_CATEGORY_QML = "S.Qml";
|
||||
const char * const WIZARD_TR_CATEGORY_QML = QT_TRANSLATE_NOOP("QmlJsEditor", "QML");
|
||||
|
||||
const char * const QML_SNIPPETS_GROUP_ID = "QML";
|
||||
|
||||
} // namespace Constants
|
||||
} // namespace QmlJSEditor
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
#include "qmljsoutline.h"
|
||||
#include "qmljspreviewrunner.h"
|
||||
#include "qmljsquickfix.h"
|
||||
#include "qmljssnippeteditordecorator.h"
|
||||
#include "qmljssnippetprovider.h"
|
||||
#include "qmltaskmanager.h"
|
||||
#include "quicktoolbar.h"
|
||||
#include "quicktoolbarsettingspage.h"
|
||||
@@ -129,7 +129,7 @@ bool QmlJSEditorPlugin::initialize(const QStringList & /*arguments*/, QString *e
|
||||
return false;
|
||||
|
||||
m_modelManager = QmlJS::ModelManagerInterface::instance();
|
||||
addAutoReleasedObject(new QmlJSSnippetEditorDecorator);
|
||||
addAutoReleasedObject(new QmlJSSnippetProvider);
|
||||
|
||||
Core::Context context(QmlJSEditor::Constants::C_QMLJSEDITOR_ID);
|
||||
|
||||
|
||||
@@ -27,35 +27,41 @@
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#include "qmljssnippeteditordecorator.h"
|
||||
#include "qmljssnippetprovider.h"
|
||||
#include "qmljshighlighter.h"
|
||||
#include "qmljseditor.h"
|
||||
#include "qmljsindenter.h"
|
||||
#include "qmljsautocompleter.h"
|
||||
#include "qmljseditorconstants.h"
|
||||
|
||||
#include <texteditor/texteditorsettings.h>
|
||||
#include <texteditor/fontsettings.h>
|
||||
#include <texteditor/texteditorconstants.h>
|
||||
#include <texteditor/snippets/snippeteditor.h>
|
||||
|
||||
#include <QtCore/QLatin1String>
|
||||
|
||||
using namespace QmlJSEditor;
|
||||
using namespace Internal;
|
||||
|
||||
QmlJSSnippetEditorDecorator::QmlJSSnippetEditorDecorator() :
|
||||
TextEditor::ISnippetEditorDecorator()
|
||||
QmlJSSnippetProvider::QmlJSSnippetProvider() :
|
||||
TextEditor::ISnippetProvider()
|
||||
{}
|
||||
|
||||
QmlJSSnippetEditorDecorator::~QmlJSSnippetEditorDecorator()
|
||||
QmlJSSnippetProvider::~QmlJSSnippetProvider()
|
||||
{}
|
||||
|
||||
bool QmlJSSnippetEditorDecorator::supports(TextEditor::Snippet::Group group) const
|
||||
QString QmlJSSnippetProvider::groupId() const
|
||||
{
|
||||
if (group == TextEditor::Snippet::Qml)
|
||||
return true;
|
||||
return false;
|
||||
return QLatin1String(Constants::QML_SNIPPETS_GROUP_ID);
|
||||
}
|
||||
|
||||
void QmlJSSnippetEditorDecorator::apply(TextEditor::SnippetEditor *editor) const
|
||||
QString QmlJSSnippetProvider::displayName() const
|
||||
{
|
||||
return tr("QML");
|
||||
}
|
||||
|
||||
void QmlJSSnippetProvider::decorateEditor(TextEditor::SnippetEditor *editor) const
|
||||
{
|
||||
Highlighter *highlighter = new Highlighter;
|
||||
const TextEditor::FontSettings &fs = TextEditor::TextEditorSettings::instance()->fontSettings();
|
||||
@@ -30,20 +30,21 @@
|
||||
#ifndef QMLJSSNIPPETEDITORDECORATOR_H
|
||||
#define QMLJSSNIPPETEDITORDECORATOR_H
|
||||
|
||||
#include <texteditor/snippets/isnippeteditordecorator.h>
|
||||
#include <texteditor/snippets/isnippetprovider.h>
|
||||
|
||||
namespace QmlJSEditor {
|
||||
namespace Internal {
|
||||
|
||||
class QmlJSSnippetEditorDecorator : public TextEditor::ISnippetEditorDecorator
|
||||
class QmlJSSnippetProvider : public TextEditor::ISnippetProvider
|
||||
{
|
||||
public:
|
||||
QmlJSSnippetEditorDecorator();
|
||||
virtual ~QmlJSSnippetEditorDecorator();
|
||||
QmlJSSnippetProvider();
|
||||
virtual ~QmlJSSnippetProvider();
|
||||
|
||||
public:
|
||||
virtual bool supports(TextEditor::Snippet::Group group) const;
|
||||
virtual void apply(TextEditor::SnippetEditor *editor) const;
|
||||
virtual QString groupId() const;
|
||||
virtual QString displayName() const;
|
||||
virtual void decorateEditor(TextEditor::SnippetEditor *editor) const;
|
||||
};
|
||||
|
||||
} // Internal
|
||||
Reference in New Issue
Block a user