Commit 1175705b authored by Leandro Melo's avatar Leandro Melo
Browse files

Snippets: Make it easier for plugins to add snippets groups

Groups are no longer enum values but identified from snippet providers.
parent fdbb34ad
...@@ -26,7 +26,7 @@ HEADERS += cppplugin.h \ ...@@ -26,7 +26,7 @@ HEADERS += cppplugin.h \
cppqtstyleindenter.h \ cppqtstyleindenter.h \
cppautocompleter.h \ cppautocompleter.h \
cppcompleteswitch.h \ cppcompleteswitch.h \
cppsnippeteditordecorator.h cppsnippetprovider.h
SOURCES += cppplugin.cpp \ SOURCES += cppplugin.cpp \
cppeditor.cpp \ cppeditor.cpp \
...@@ -47,7 +47,7 @@ SOURCES += cppplugin.cpp \ ...@@ -47,7 +47,7 @@ SOURCES += cppplugin.cpp \
cppqtstyleindenter.cpp \ cppqtstyleindenter.cpp \
cppautocompleter.cpp \ cppautocompleter.cpp \
cppcompleteswitch.cpp \ cppcompleteswitch.cpp \
cppsnippeteditordecorator.cpp cppsnippetprovider.cpp
RESOURCES += cppeditor.qrc RESOURCES += cppeditor.qrc
OTHER_FILES += CppEditor.mimetypes.xml OTHER_FILES += CppEditor.mimetypes.xml
...@@ -68,6 +68,8 @@ const char * const CPP_HEADER_MIMETYPE = "text/x-c++hdr"; ...@@ -68,6 +68,8 @@ const char * const CPP_HEADER_MIMETYPE = "text/x-c++hdr";
const char * const WIZARD_CATEGORY = "O.C++"; const char * const WIZARD_CATEGORY = "O.C++";
const char * const WIZARD_TR_CATEGORY = QT_TRANSLATE_NOOP("CppEditor", "C++"); const char * const WIZARD_TR_CATEGORY = QT_TRANSLATE_NOOP("CppEditor", "C++");
const char * const CPP_SNIPPETS_GROUP_ID = "C++";
} // namespace Constants } // namespace Constants
} // namespace CppEditor } // namespace CppEditor
......
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
#include "cppoutline.h" #include "cppoutline.h"
#include "cppquickfixcollector.h" #include "cppquickfixcollector.h"
#include "cpptypehierarchy.h" #include "cpptypehierarchy.h"
#include "cppsnippeteditordecorator.h" #include "cppsnippetprovider.h"
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <coreplugin/coreconstants.h> #include <coreplugin/coreconstants.h>
...@@ -212,7 +212,7 @@ bool CppPlugin::initialize(const QStringList & /*arguments*/, QString *errorMess ...@@ -212,7 +212,7 @@ bool CppPlugin::initialize(const QStringList & /*arguments*/, QString *errorMess
addAutoReleasedObject(new CppHoverHandler); addAutoReleasedObject(new CppHoverHandler);
addAutoReleasedObject(new CppOutlineWidgetFactory); addAutoReleasedObject(new CppOutlineWidgetFactory);
addAutoReleasedObject(new CppTypeHierarchyFactory); addAutoReleasedObject(new CppTypeHierarchyFactory);
addAutoReleasedObject(new CppSnippetEditorDecorator); addAutoReleasedObject(new CppSnippetProvider);
m_quickFixCollector = new CppQuickFixCollector; m_quickFixCollector = new CppQuickFixCollector;
addAutoReleasedObject(m_quickFixCollector); addAutoReleasedObject(m_quickFixCollector);
......
...@@ -27,35 +27,41 @@ ...@@ -27,35 +27,41 @@
** **
**************************************************************************/ **************************************************************************/
#include "cppsnippeteditordecorator.h" #include "cppsnippetprovider.h"
#include "cpphighlighter.h" #include "cpphighlighter.h"
#include "cppeditor.h" #include "cppeditor.h"
#include "cppqtstyleindenter.h" #include "cppqtstyleindenter.h"
#include "cppautocompleter.h" #include "cppautocompleter.h"
#include "cppeditorconstants.h"
#include <texteditor/texteditorsettings.h> #include <texteditor/texteditorsettings.h>
#include <texteditor/fontsettings.h> #include <texteditor/fontsettings.h>
#include <texteditor/texteditorconstants.h> #include <texteditor/texteditorconstants.h>
#include <texteditor/snippets/snippeteditor.h> #include <texteditor/snippets/snippeteditor.h>
#include <QtCore/QLatin1String>
using namespace CppEditor; using namespace CppEditor;
using namespace Internal; using namespace Internal;
CppSnippetEditorDecorator::CppSnippetEditorDecorator() : CppSnippetProvider::CppSnippetProvider() :
TextEditor::ISnippetEditorDecorator() TextEditor::ISnippetProvider()
{} {}
CppSnippetEditorDecorator::~CppSnippetEditorDecorator() CppSnippetProvider::~CppSnippetProvider()
{} {}
bool CppSnippetEditorDecorator::supports(TextEditor::Snippet::Group group) const QString CppSnippetProvider::groupId() const
{
return QLatin1String(Constants::CPP_SNIPPETS_GROUP_ID);
}
QString CppSnippetProvider::displayName() const
{ {
if (group == TextEditor::Snippet::Cpp) return tr("C++");
return true;
return false;
} }
void CppSnippetEditorDecorator::apply(TextEditor::SnippetEditor *editor) const void CppSnippetProvider::decorateEditor(TextEditor::SnippetEditor *editor) const
{ {
CppHighlighter *highlighter = new CppHighlighter; CppHighlighter *highlighter = new CppHighlighter;
const TextEditor::FontSettings &fs = TextEditor::TextEditorSettings::instance()->fontSettings(); const TextEditor::FontSettings &fs = TextEditor::TextEditorSettings::instance()->fontSettings();
......
...@@ -30,20 +30,21 @@ ...@@ -30,20 +30,21 @@
#ifndef CPPSNIPPETEDITORDECORATOR_H #ifndef CPPSNIPPETEDITORDECORATOR_H
#define CPPSNIPPETEDITORDECORATOR_H #define CPPSNIPPETEDITORDECORATOR_H
#include <texteditor/snippets/isnippeteditordecorator.h> #include <texteditor/snippets/isnippetprovider.h>
namespace CppEditor { namespace CppEditor {
namespace Internal { namespace Internal {
class CppSnippetEditorDecorator : public TextEditor::ISnippetEditorDecorator class CppSnippetProvider : public TextEditor::ISnippetProvider
{ {
public: public:
CppSnippetEditorDecorator(); CppSnippetProvider();
virtual ~CppSnippetEditorDecorator(); virtual ~CppSnippetProvider();
public: public:
virtual bool supports(TextEditor::Snippet::Group group) const; virtual QString groupId() const;
virtual void apply(TextEditor::SnippetEditor *editor) const; virtual QString displayName() const;
virtual void decorateEditor(TextEditor::SnippetEditor *editor) const;
}; };
} // Internal } // Internal
......
...@@ -52,6 +52,8 @@ ...@@ -52,6 +52,8 @@
#include <cplusplus/BackwardsScanner.h> #include <cplusplus/BackwardsScanner.h>
#include <cplusplus/LookupContext.h> #include <cplusplus/LookupContext.h>
#include <cppeditor/cppeditorconstants.h>
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <coreplugin/mimedatabase.h> #include <coreplugin/mimedatabase.h>
#include <coreplugin/editormanager/editormanager.h> #include <coreplugin/editormanager/editormanager.h>
...@@ -463,7 +465,7 @@ CppCodeCompletion::CppCodeCompletion(CppModelManager *manager) ...@@ -463,7 +465,7 @@ CppCodeCompletion::CppCodeCompletion(CppModelManager *manager)
m_automaticCompletion(false), m_automaticCompletion(false),
m_completionOperator(T_EOF_SYMBOL), m_completionOperator(T_EOF_SYMBOL),
m_objcEnabled(true), m_objcEnabled(true),
m_snippetProvider(TextEditor::Snippet::Cpp, m_snippetProvider(CppEditor::Constants::CPP_SNIPPETS_GROUP_ID,
QIcon(QLatin1String(":/texteditor/images/snippet.png"))) QIcon(QLatin1String(":/texteditor/images/snippet.png")))
{ {
} }
......
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
#include <cplusplus/TypeOfExpression.h> #include <cplusplus/TypeOfExpression.h>
#include <texteditor/icompletioncollector.h> #include <texteditor/icompletioncollector.h>
#include <texteditor/snippets/snippetprovider.h> #include <texteditor/snippets/snippetcollector.h>
#include <QtCore/QObject> #include <QtCore/QObject>
#include <QtCore/QPointer> #include <QtCore/QPointer>
...@@ -153,7 +153,7 @@ private: ...@@ -153,7 +153,7 @@ private:
unsigned m_completionOperator; unsigned m_completionOperator;
bool m_objcEnabled; bool m_objcEnabled;
TextEditor::SnippetProvider m_snippetProvider; TextEditor::SnippetCollector m_snippetProvider;
CPlusPlus::Icons m_icons; CPlusPlus::Icons m_icons;
CPlusPlus::Overview overview; CPlusPlus::Overview overview;
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include "qmljscodecompletion.h" #include "qmljscodecompletion.h"
#include "qmlexpressionundercursor.h" #include "qmlexpressionundercursor.h"
#include "qmljseditor.h" #include "qmljseditor.h"
#include "qmljseditorconstants.h"
#include <qmljs/qmljsmodelmanagerinterface.h> #include <qmljs/qmljsmodelmanagerinterface.h>
#include <qmljs/parser/qmljsast_p.h> #include <qmljs/parser/qmljsast_p.h>
...@@ -487,7 +488,7 @@ CodeCompletion::CodeCompletion(ModelManagerInterface *modelManager, QObject *par ...@@ -487,7 +488,7 @@ CodeCompletion::CodeCompletion(ModelManagerInterface *modelManager, QObject *par
m_editor(0), m_editor(0),
m_startPosition(0), m_startPosition(0),
m_restartCompletion(false), 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); Q_ASSERT(modelManager);
} }
......
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
#include <qmljs/qmljsdocument.h> #include <qmljs/qmljsdocument.h>
#include <texteditor/icompletioncollector.h> #include <texteditor/icompletioncollector.h>
#include <texteditor/snippets/snippetprovider.h> #include <texteditor/snippets/snippetcollector.h>
#include <QtCore/QDateTime> #include <QtCore/QDateTime>
#include <QtCore/QPointer> #include <QtCore/QPointer>
...@@ -97,7 +97,7 @@ private: ...@@ -97,7 +97,7 @@ private:
TextEditor::ITextEditable *m_editor; TextEditor::ITextEditable *m_editor;
int m_startPosition; int m_startPosition;
bool m_restartCompletion; bool m_restartCompletion;
TextEditor::SnippetProvider m_snippetProvider; TextEditor::SnippetCollector m_snippetProvider;
QList<TextEditor::CompletionItem> m_completions; QList<TextEditor::CompletionItem> m_completions;
QPointer<FunctionArgumentWidget> m_functionArgumentWidget; QPointer<FunctionArgumentWidget> m_functionArgumentWidget;
}; };
......
...@@ -35,7 +35,7 @@ HEADERS += \ ...@@ -35,7 +35,7 @@ HEADERS += \
qmljsindenter.h \ qmljsindenter.h \
qmljsautocompleter.h \ qmljsautocompleter.h \
jsfilewizard.h \ jsfilewizard.h \
qmljssnippeteditordecorator.h qmljssnippetprovider.h
SOURCES += \ SOURCES += \
qmljscodecompletion.cpp \ qmljscodecompletion.cpp \
...@@ -64,7 +64,7 @@ SOURCES += \ ...@@ -64,7 +64,7 @@ SOURCES += \
qmljsindenter.cpp \ qmljsindenter.cpp \
qmljsautocompleter.cpp \ qmljsautocompleter.cpp \
jsfilewizard.cpp \ jsfilewizard.cpp \
qmljssnippeteditordecorator.cpp qmljssnippetprovider.cpp
RESOURCES += qmljseditor.qrc RESOURCES += qmljseditor.qrc
OTHER_FILES += QmlJSEditor.mimetypes.xml OTHER_FILES += QmlJSEditor.mimetypes.xml
......
...@@ -60,6 +60,7 @@ const char *const TASK_CATEGORY_QML = "Task.Category.Qml"; ...@@ -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_CATEGORY_QML = "S.Qml";
const char * const WIZARD_TR_CATEGORY_QML = QT_TRANSLATE_NOOP("QmlJsEditor", "QML"); const char * const WIZARD_TR_CATEGORY_QML = QT_TRANSLATE_NOOP("QmlJsEditor", "QML");
const char * const QML_SNIPPETS_GROUP_ID = "QML";
} // namespace Constants } // namespace Constants
} // namespace QmlJSEditor } // namespace QmlJSEditor
......
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
#include "qmljsoutline.h" #include "qmljsoutline.h"
#include "qmljspreviewrunner.h" #include "qmljspreviewrunner.h"
#include "qmljsquickfix.h" #include "qmljsquickfix.h"
#include "qmljssnippeteditordecorator.h" #include "qmljssnippetprovider.h"
#include "qmltaskmanager.h" #include "qmltaskmanager.h"
#include "quicktoolbar.h" #include "quicktoolbar.h"
#include "quicktoolbarsettingspage.h" #include "quicktoolbarsettingspage.h"
...@@ -129,7 +129,7 @@ bool QmlJSEditorPlugin::initialize(const QStringList & /*arguments*/, QString *e ...@@ -129,7 +129,7 @@ bool QmlJSEditorPlugin::initialize(const QStringList & /*arguments*/, QString *e
return false; return false;
m_modelManager = QmlJS::ModelManagerInterface::instance(); m_modelManager = QmlJS::ModelManagerInterface::instance();
addAutoReleasedObject(new QmlJSSnippetEditorDecorator); addAutoReleasedObject(new QmlJSSnippetProvider);
Core::Context context(QmlJSEditor::Constants::C_QMLJSEDITOR_ID); Core::Context context(QmlJSEditor::Constants::C_QMLJSEDITOR_ID);
......
...@@ -27,35 +27,41 @@ ...@@ -27,35 +27,41 @@
** **
**************************************************************************/ **************************************************************************/
#include "qmljssnippeteditordecorator.h" #include "qmljssnippetprovider.h"
#include "qmljshighlighter.h" #include "qmljshighlighter.h"
#include "qmljseditor.h" #include "qmljseditor.h"
#include "qmljsindenter.h" #include "qmljsindenter.h"
#include "qmljsautocompleter.h" #include "qmljsautocompleter.h"
#include "qmljseditorconstants.h"
#include <texteditor/texteditorsettings.h> #include <texteditor/texteditorsettings.h>
#include <texteditor/fontsettings.h> #include <texteditor/fontsettings.h>
#include <texteditor/texteditorconstants.h> #include <texteditor/texteditorconstants.h>
#include <texteditor/snippets/snippeteditor.h> #include <texteditor/snippets/snippeteditor.h>
#include <QtCore/QLatin1String>
using namespace QmlJSEditor; using namespace QmlJSEditor;
using namespace Internal; using namespace Internal;
QmlJSSnippetEditorDecorator::QmlJSSnippetEditorDecorator() : QmlJSSnippetProvider::QmlJSSnippetProvider() :
TextEditor::ISnippetEditorDecorator() TextEditor::ISnippetProvider()
{} {}
QmlJSSnippetEditorDecorator::~QmlJSSnippetEditorDecorator() QmlJSSnippetProvider::~QmlJSSnippetProvider()
{} {}
bool QmlJSSnippetEditorDecorator::supports(TextEditor::Snippet::Group group) const QString QmlJSSnippetProvider::groupId() const
{
return QLatin1String(Constants::QML_SNIPPETS_GROUP_ID);
}
QString QmlJSSnippetProvider::displayName() const
{ {
if (group == TextEditor::Snippet::Qml) return tr("QML");
return true;
return false;
} }
void QmlJSSnippetEditorDecorator::apply(TextEditor::SnippetEditor *editor) const void QmlJSSnippetProvider::decorateEditor(TextEditor::SnippetEditor *editor) const
{ {
Highlighter *highlighter = new Highlighter; Highlighter *highlighter = new Highlighter;
const TextEditor::FontSettings &fs = TextEditor::TextEditorSettings::instance()->fontSettings(); const TextEditor::FontSettings &fs = TextEditor::TextEditorSettings::instance()->fontSettings();
......
...@@ -30,20 +30,21 @@ ...@@ -30,20 +30,21 @@
#ifndef QMLJSSNIPPETEDITORDECORATOR_H #ifndef QMLJSSNIPPETEDITORDECORATOR_H
#define QMLJSSNIPPETEDITORDECORATOR_H #define QMLJSSNIPPETEDITORDECORATOR_H
#include <texteditor/snippets/isnippeteditordecorator.h> #include <texteditor/snippets/isnippetprovider.h>
namespace QmlJSEditor { namespace QmlJSEditor {
namespace Internal { namespace Internal {
class QmlJSSnippetEditorDecorator : public TextEditor::ISnippetEditorDecorator class QmlJSSnippetProvider : public TextEditor::ISnippetProvider
{ {
public: public:
QmlJSSnippetEditorDecorator(); QmlJSSnippetProvider();
virtual ~QmlJSSnippetEditorDecorator(); virtual ~QmlJSSnippetProvider();
public: public:
virtual bool supports(TextEditor::Snippet::Group group) const; virtual QString groupId() const;
virtual void apply(TextEditor::SnippetEditor *editor) const; virtual QString displayName() const;
virtual void decorateEditor(TextEditor::SnippetEditor *editor) const;
}; };
} // Internal } // Internal
......
...@@ -27,12 +27,12 @@ ...@@ -27,12 +27,12 @@
** **
**************************************************************************/ **************************************************************************/
#include "isnippeteditordecorator.h" #include "isnippetprovider.h"
using namespace TextEditor; using namespace TextEditor;
ISnippetEditorDecorator::ISnippetEditorDecorator() : QObject() ISnippetProvider::ISnippetProvider() : QObject()
{} {}
ISnippetEditorDecorator::~ISnippetEditorDecorator() ISnippetProvider::~ISnippetProvider()
{} {}
...@@ -40,17 +40,18 @@ namespace TextEditor { ...@@ -40,17 +40,18 @@ namespace TextEditor {
class SnippetEditor; class SnippetEditor;
class TEXTEDITOR_EXPORT ISnippetEditorDecorator : public QObject class TEXTEDITOR_EXPORT ISnippetProvider : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
virtual ~ISnippetEditorDecorator(); virtual ~ISnippetProvider();
virtual bool supports(Snippet::Group group) const = 0; virtual QString groupId() const = 0;
virtual void apply(SnippetEditor *editor) const = 0; virtual QString displayName() const = 0;
virtual void decorateEditor(SnippetEditor *editor) const = 0;
protected: protected:
ISnippetEditorDecorator(); ISnippetProvider();
}; };
} // TextEditor } // TextEditor
......
/**************************************************************************
**
** 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 "plaintextsnippetprovider.h"
#include <texteditor/texteditorconstants.h>
#include <QtCore/QLatin1String>
using namespace TextEditor;
using namespace Internal;
PlainTextSnippetProvider::PlainTextSnippetProvider()
{}
PlainTextSnippetProvider::~PlainTextSnippetProvider()
{}
QString PlainTextSnippetProvider::groupId() const
{
return QLatin1String(Constants::TEXT_SNIPPET_GROUP_ID);
}
QString PlainTextSnippetProvider::displayName() const
{
return tr("Text");
}
void PlainTextSnippetProvider::decorateEditor(TextEditor::SnippetEditor *) const
{}
/**************************************************************************
**
** 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