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:
@@ -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 \
|
|||||||
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";
|
|||||||
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 @@
|
|||||||
#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
|
|||||||
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 @@
|
|||||||
**
|
**
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
#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
|
||||||
{
|
{
|
||||||
if (group == TextEditor::Snippet::Cpp)
|
return QLatin1String(Constants::CPP_SNIPPETS_GROUP_ID);
|
||||||
return true;
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CppSnippetEditorDecorator::apply(TextEditor::SnippetEditor *editor) const
|
QString CppSnippetProvider::displayName() const
|
||||||
|
{
|
||||||
|
return tr("C++");
|
||||||
|
}
|
||||||
|
|
||||||
|
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 @@
|
|||||||
#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 @@
|
|||||||
#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)
|
|||||||
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 @@
|
|||||||
#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:
|
|||||||
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 @@
|
|||||||
#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
|
|||||||
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 @@
|
|||||||
|
|
||||||
#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:
|
|||||||
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 += \
|
|||||||
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 += \
|
|||||||
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";
|
|||||||
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 @@
|
|||||||
#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
|
|||||||
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 @@
|
|||||||
**
|
**
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
#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
|
||||||
{
|
{
|
||||||
if (group == TextEditor::Snippet::Qml)
|
return QLatin1String(Constants::QML_SNIPPETS_GROUP_ID);
|
||||||
return true;
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
Highlighter *highlighter = new Highlighter;
|
||||||
const TextEditor::FontSettings &fs = TextEditor::TextEditorSettings::instance()->fontSettings();
|
const TextEditor::FontSettings &fs = TextEditor::TextEditorSettings::instance()->fontSettings();
|
||||||
@@ -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 @@
|
|||||||
**
|
**
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
#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 {
|
|||||||
|
|
||||||
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
|
||||||
56
src/plugins/texteditor/snippets/plaintextsnippetprovider.cpp
Normal file
56
src/plugins/texteditor/snippets/plaintextsnippetprovider.cpp
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
/**************************************************************************
|
||||||
|
**
|
||||||
|
** 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
|
||||||
|
{}
|
||||||
53
src/plugins/texteditor/snippets/plaintextsnippetprovider.h
Normal file
53
src/plugins/texteditor/snippets/plaintextsnippetprovider.h
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
/**************************************************************************
|
||||||
|
**
|
||||||
|
** 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 PLAINTEXTSNIPPETPROVIDER_H
|
||||||
|
#define PLAINTEXTSNIPPETPROVIDER_H
|
||||||
|
|
||||||
|
#include "isnippetprovider.h"
|
||||||
|
|
||||||
|
namespace TextEditor {
|
||||||
|
namespace Internal {
|
||||||
|
|
||||||
|
class PlainTextSnippetProvider : public ISnippetProvider
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
PlainTextSnippetProvider();
|
||||||
|
virtual ~PlainTextSnippetProvider();
|
||||||
|
|
||||||
|
public:
|
||||||
|
virtual QString groupId() const;
|
||||||
|
virtual QString displayName() const;
|
||||||
|
virtual void decorateEditor(TextEditor::SnippetEditor *editor) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // Internal
|
||||||
|
} // TextEditor
|
||||||
|
|
||||||
|
#endif // PLAINTEXTSNIPPETPROVIDER_H
|
||||||
@@ -30,41 +30,15 @@
|
|||||||
#ifndef REUSE_H
|
#ifndef REUSE_H
|
||||||
#define REUSE_H
|
#define REUSE_H
|
||||||
|
|
||||||
#include "snippet.h"
|
|
||||||
|
|
||||||
#include <QtCore/QString>
|
#include <QtCore/QString>
|
||||||
#include <QtCore/QLatin1String>
|
#include <QtCore/QLatin1String>
|
||||||
|
|
||||||
namespace TextEditor {
|
namespace TextEditor {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
const QLatin1String kCpp("C++");
|
|
||||||
const QLatin1String kQml("QML");
|
|
||||||
const QLatin1String kText("Text");
|
|
||||||
const QLatin1String kTrue("true");
|
const QLatin1String kTrue("true");
|
||||||
const QLatin1String kFalse("false");
|
const QLatin1String kFalse("false");
|
||||||
|
|
||||||
inline Snippet::Group toSnippetGroup(const QString &s)
|
|
||||||
{
|
|
||||||
const QString &upper = s.toUpper();
|
|
||||||
if (upper == kCpp)
|
|
||||||
return Snippet::Cpp;
|
|
||||||
else if (upper == kQml)
|
|
||||||
return Snippet::Qml;
|
|
||||||
else
|
|
||||||
return Snippet::PlainText;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline QString fromSnippetGroup(Snippet::Group group)
|
|
||||||
{
|
|
||||||
if (group == Snippet::Cpp)
|
|
||||||
return kCpp;
|
|
||||||
else if (group == Snippet::Qml)
|
|
||||||
return kQml;
|
|
||||||
else
|
|
||||||
return kText;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool toBool(const QString &s)
|
inline bool toBool(const QString &s)
|
||||||
{
|
{
|
||||||
if (s == kTrue)
|
if (s == kTrue)
|
||||||
|
|||||||
@@ -37,7 +37,8 @@ using namespace TextEditor;
|
|||||||
|
|
||||||
const QChar Snippet::kVariableDelimiter(QLatin1Char('$'));
|
const QChar Snippet::kVariableDelimiter(QLatin1Char('$'));
|
||||||
|
|
||||||
Snippet::Snippet(const QString &id) : m_isRemoved(false), m_isModified(false), m_id(id)
|
Snippet::Snippet(const QString &groupId, const QString &id) :
|
||||||
|
m_isRemoved(false), m_isModified(false), m_groupId(groupId), m_id(id)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
Snippet::~Snippet()
|
Snippet::~Snippet()
|
||||||
@@ -48,6 +49,11 @@ const QString &Snippet::id() const
|
|||||||
return m_id;
|
return m_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const QString &Snippet::groupId() const
|
||||||
|
{
|
||||||
|
return m_groupId;
|
||||||
|
}
|
||||||
|
|
||||||
bool Snippet::isBuiltIn() const
|
bool Snippet::isBuiltIn() const
|
||||||
{
|
{
|
||||||
return !m_id.isEmpty();
|
return !m_id.isEmpty();
|
||||||
@@ -103,16 +109,6 @@ bool Snippet::isModified() const
|
|||||||
return m_isModified;
|
return m_isModified;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Snippet::setGroup(Group group)
|
|
||||||
{
|
|
||||||
m_group = group;
|
|
||||||
}
|
|
||||||
|
|
||||||
Snippet::Group Snippet::group() const
|
|
||||||
{
|
|
||||||
return m_group;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString Snippet::generateTip() const
|
QString Snippet::generateTip() const
|
||||||
{
|
{
|
||||||
static const QLatin1Char kNewLine('\n');
|
static const QLatin1Char kNewLine('\n');
|
||||||
|
|||||||
@@ -40,18 +40,11 @@ namespace TextEditor {
|
|||||||
class TEXTEDITOR_EXPORT Snippet
|
class TEXTEDITOR_EXPORT Snippet
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Snippet(const QString &id = QString());
|
Snippet(const QString &groupId = QString(), const QString &id = QString());
|
||||||
~Snippet();
|
~Snippet();
|
||||||
|
|
||||||
// Values from this enumeration need to be contiguous (they are used as indexes).
|
|
||||||
enum Group {
|
|
||||||
Cpp = 0,
|
|
||||||
Qml,
|
|
||||||
PlainText,
|
|
||||||
GroupSize
|
|
||||||
};
|
|
||||||
|
|
||||||
const QString &id() const;
|
const QString &id() const;
|
||||||
|
const QString &groupId() const;
|
||||||
|
|
||||||
bool isBuiltIn() const;
|
bool isBuiltIn() const;
|
||||||
|
|
||||||
@@ -70,9 +63,6 @@ public:
|
|||||||
void setIsModified(bool modified);
|
void setIsModified(bool modified);
|
||||||
bool isModified() const;
|
bool isModified() const;
|
||||||
|
|
||||||
void setGroup(Group group);
|
|
||||||
Group group() const;
|
|
||||||
|
|
||||||
QString generateTip() const;
|
QString generateTip() const;
|
||||||
|
|
||||||
static const QChar kVariableDelimiter;
|
static const QChar kVariableDelimiter;
|
||||||
@@ -80,19 +70,13 @@ public:
|
|||||||
private:
|
private:
|
||||||
bool m_isRemoved;
|
bool m_isRemoved;
|
||||||
bool m_isModified;
|
bool m_isModified;
|
||||||
|
QString m_groupId;
|
||||||
QString m_id; // Only built-in snippets have an id.
|
QString m_id; // Only built-in snippets have an id.
|
||||||
QString m_trigger;
|
QString m_trigger;
|
||||||
QString m_content;
|
QString m_content;
|
||||||
QString m_complement;
|
QString m_complement;
|
||||||
Group m_group;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
inline Snippet::Group& operator++(Snippet::Group& group)
|
|
||||||
{
|
|
||||||
group = Snippet::Group(group + 1);
|
|
||||||
return group;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // TextEditor
|
} // TextEditor
|
||||||
|
|
||||||
#endif // SNIPPET_H
|
#endif // SNIPPET_H
|
||||||
|
|||||||
@@ -27,10 +27,12 @@
|
|||||||
**
|
**
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
#include "snippetprovider.h"
|
#include "snippetcollector.h"
|
||||||
#include "snippetsmanager.h"
|
#include "snippetsmanager.h"
|
||||||
#include "snippetscollection.h"
|
#include "snippetscollection.h"
|
||||||
|
|
||||||
|
#include <texteditor/texteditorconstants.h>
|
||||||
|
|
||||||
using namespace TextEditor;
|
using namespace TextEditor;
|
||||||
using namespace Internal;
|
using namespace Internal;
|
||||||
|
|
||||||
@@ -38,15 +40,15 @@ namespace {
|
|||||||
|
|
||||||
void appendSnippets(ICompletionCollector *collector,
|
void appendSnippets(ICompletionCollector *collector,
|
||||||
QList<CompletionItem> *completionItems,
|
QList<CompletionItem> *completionItems,
|
||||||
Snippet::Group group,
|
const QString &groupId,
|
||||||
const QIcon &icon,
|
const QIcon &icon,
|
||||||
int order)
|
int order)
|
||||||
{
|
{
|
||||||
QSharedPointer<SnippetsCollection> collection =
|
QSharedPointer<SnippetsCollection> collection =
|
||||||
SnippetsManager::instance()->snippetsCollection();
|
SnippetsManager::instance()->snippetsCollection();
|
||||||
const int size = collection->totalActiveSnippets(group);
|
const int size = collection->totalActiveSnippets(groupId);
|
||||||
for (int i = 0; i < size; ++i) {
|
for (int i = 0; i < size; ++i) {
|
||||||
const Snippet &snippet = collection->snippet(i, group);
|
const Snippet &snippet = collection->snippet(i, groupId);
|
||||||
CompletionItem item(collector);
|
CompletionItem item(collector);
|
||||||
item.text = snippet.trigger() + QLatin1Char(' ') + snippet.complement();
|
item.text = snippet.trigger() + QLatin1Char(' ') + snippet.complement();
|
||||||
item.data = snippet.content();
|
item.data = snippet.content();
|
||||||
@@ -60,17 +62,17 @@ void appendSnippets(ICompletionCollector *collector,
|
|||||||
|
|
||||||
} // anonymous
|
} // anonymous
|
||||||
|
|
||||||
SnippetProvider::SnippetProvider(Snippet::Group group, const QIcon &icon, int order) :
|
SnippetCollector::SnippetCollector(const QString &groupId, const QIcon &icon, int order) :
|
||||||
m_group(group), m_icon(icon), m_order(order)
|
m_groupId(groupId), m_icon(icon), m_order(order)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
SnippetProvider::~SnippetProvider()
|
SnippetCollector::~SnippetCollector()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
QList<CompletionItem> SnippetProvider::getSnippets(ICompletionCollector *collector) const
|
QList<CompletionItem> SnippetCollector::getSnippets(ICompletionCollector *collector) const
|
||||||
{
|
{
|
||||||
QList<CompletionItem> completionItems;
|
QList<CompletionItem> completionItems;
|
||||||
appendSnippets(collector, &completionItems, m_group, m_icon, m_order);
|
appendSnippets(collector, &completionItems, m_groupId, m_icon, m_order);
|
||||||
appendSnippets(collector, &completionItems, Snippet::PlainText, m_icon, m_order);
|
appendSnippets(collector, &completionItems, Constants::TEXT_SNIPPET_GROUP_ID, m_icon, m_order);
|
||||||
return completionItems;
|
return completionItems;
|
||||||
}
|
}
|
||||||
@@ -30,26 +30,25 @@
|
|||||||
#ifndef SNIPPETPROVIDER_H
|
#ifndef SNIPPETPROVIDER_H
|
||||||
#define SNIPPETPROVIDER_H
|
#define SNIPPETPROVIDER_H
|
||||||
|
|
||||||
#include "snippet.h"
|
|
||||||
|
|
||||||
#include <texteditor/texteditor_global.h>
|
#include <texteditor/texteditor_global.h>
|
||||||
#include <texteditor/icompletioncollector.h>
|
#include <texteditor/icompletioncollector.h>
|
||||||
|
|
||||||
|
#include <QtCore/QString>
|
||||||
#include <QtCore/QList>
|
#include <QtCore/QList>
|
||||||
#include <QtGui/QIcon>
|
#include <QtGui/QIcon>
|
||||||
|
|
||||||
namespace TextEditor {
|
namespace TextEditor {
|
||||||
|
|
||||||
class TEXTEDITOR_EXPORT SnippetProvider
|
class TEXTEDITOR_EXPORT SnippetCollector
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SnippetProvider(Snippet::Group group, const QIcon &icon, int order = 0);
|
SnippetCollector(const QString &groupId, const QIcon &icon, int order = 0);
|
||||||
~SnippetProvider();
|
~SnippetCollector();
|
||||||
|
|
||||||
QList<CompletionItem> getSnippets(ICompletionCollector *collector) const;
|
QList<CompletionItem> getSnippets(ICompletionCollector *collector) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Snippet::Group m_group;
|
QString m_groupId;
|
||||||
QIcon m_icon;
|
QIcon m_icon;
|
||||||
int m_order;
|
int m_order;
|
||||||
};
|
};
|
||||||
@@ -117,4 +117,5 @@ public:
|
|||||||
<snippet group="QML" trigger="PropertyAction" id="propertyactionwithtarget" complement="with target">PropertyAction { target: $name$; property: "$name$"; value: $value$ }</snippet>
|
<snippet group="QML" trigger="PropertyAction" id="propertyactionwithtarget" complement="with target">PropertyAction { target: $name$; property: "$name$"; value: $value$ }</snippet>
|
||||||
<snippet group="QML" trigger="PauseAnimation" id="pauseanimation">PauseAnimation { duration: $200$ }</snippet>
|
<snippet group="QML" trigger="PauseAnimation" id="pauseanimation">PauseAnimation { duration: $200$ }</snippet>
|
||||||
<snippet group="QML" trigger="ColorAnimation" id="coloranimation">ColorAnimation { from: $"white"$; to: $"black"$; duration: $200$ }</snippet>
|
<snippet group="QML" trigger="ColorAnimation" id="coloranimation">ColorAnimation { from: $"white"$; to: $"black"$; duration: $200$ }</snippet>
|
||||||
|
<snippet group="Text" trigger="global" id="global" complement="example">// This is available in all editors.</snippet>
|
||||||
</snippets>
|
</snippets>
|
||||||
|
|||||||
@@ -28,15 +28,16 @@
|
|||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
#include "snippetscollection.h"
|
#include "snippetscollection.h"
|
||||||
|
#include "isnippetprovider.h"
|
||||||
#include "reuse.h"
|
#include "reuse.h"
|
||||||
|
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
|
#include <extensionsystem/pluginmanager.h>
|
||||||
|
|
||||||
#include <QtCore/QLatin1String>
|
#include <QtCore/QLatin1String>
|
||||||
#include <QtCore/QFile>
|
#include <QtCore/QFile>
|
||||||
#include <QtCore/QFileInfo>
|
#include <QtCore/QFileInfo>
|
||||||
#include <QtCore/QDir>
|
#include <QtCore/QDir>
|
||||||
#include <QtCore/QHash>
|
|
||||||
#include <QtCore/QDebug>
|
#include <QtCore/QDebug>
|
||||||
#include <QtCore/QXmlStreamReader>
|
#include <QtCore/QXmlStreamReader>
|
||||||
#include <QtCore/QXmlStreamWriter>
|
#include <QtCore/QXmlStreamWriter>
|
||||||
@@ -99,28 +100,24 @@ int SnippetsCollection::Hint::index() const
|
|||||||
|
|
||||||
// SnippetsCollection
|
// SnippetsCollection
|
||||||
SnippetsCollection::SnippetsCollection() :
|
SnippetsCollection::SnippetsCollection() :
|
||||||
m_snippets(Snippet::GroupSize),
|
|
||||||
m_activeSnippetsEnd(Snippet::GroupSize),
|
|
||||||
m_builtInSnippetsPath(QLatin1String(":/texteditor/snippets/")),
|
m_builtInSnippetsPath(QLatin1String(":/texteditor/snippets/")),
|
||||||
m_userSnippetsPath(Core::ICore::instance()->userResourcePath() + QLatin1String("/snippets/")),
|
m_userSnippetsPath(Core::ICore::instance()->userResourcePath() + QLatin1String("/snippets/")),
|
||||||
m_snippetsFileName(QLatin1String("snippets.xml"))
|
m_snippetsFileName(QLatin1String("snippets.xml"))
|
||||||
{
|
{
|
||||||
for (Snippet::Group group = Snippet::Cpp; group < Snippet::GroupSize; ++group)
|
connect(Core::ICore::instance(), SIGNAL(coreOpened()), this, SLOT(identifyGroups()));
|
||||||
m_activeSnippetsEnd[group] = m_snippets[group].end();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SnippetsCollection::~SnippetsCollection()
|
SnippetsCollection::~SnippetsCollection()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void SnippetsCollection::insertSnippet(const Snippet &snippet, Snippet::Group group)
|
void SnippetsCollection::insertSnippet(const Snippet &snippet)
|
||||||
{
|
{
|
||||||
insertSnippet(snippet, group, computeInsertionHint(snippet, group));
|
insertSnippet(snippet, computeInsertionHint(snippet));
|
||||||
}
|
}
|
||||||
|
|
||||||
void SnippetsCollection::insertSnippet(const Snippet &snippet,
|
void SnippetsCollection::insertSnippet(const Snippet &snippet, const Hint &hint)
|
||||||
Snippet::Group group,
|
|
||||||
const Hint &hint)
|
|
||||||
{
|
{
|
||||||
|
const int group = groupIndex(snippet.groupId());
|
||||||
if (snippet.isBuiltIn() && snippet.isRemoved()) {
|
if (snippet.isBuiltIn() && snippet.isRemoved()) {
|
||||||
m_activeSnippetsEnd[group] = m_snippets[group].insert(m_activeSnippetsEnd[group], snippet);
|
m_activeSnippetsEnd[group] = m_snippets[group].insert(m_activeSnippetsEnd[group], snippet);
|
||||||
} else {
|
} else {
|
||||||
@@ -129,25 +126,23 @@ void SnippetsCollection::insertSnippet(const Snippet &snippet,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SnippetsCollection::Hint SnippetsCollection::computeInsertionHint(const Snippet &snippet,
|
SnippetsCollection::Hint SnippetsCollection::computeInsertionHint(const Snippet &snippet)
|
||||||
Snippet::Group group)
|
|
||||||
{
|
{
|
||||||
|
const int group = groupIndex(snippet.groupId());
|
||||||
QList<Snippet> &snippets = m_snippets[group];
|
QList<Snippet> &snippets = m_snippets[group];
|
||||||
QList<Snippet>::iterator it = qUpperBound(
|
QList<Snippet>::iterator it = qUpperBound(
|
||||||
snippets.begin(), m_activeSnippetsEnd.at(group), snippet, snippetComp);
|
snippets.begin(), m_activeSnippetsEnd.at(group), snippet, snippetComp);
|
||||||
return Hint(static_cast<int>(std::distance(snippets.begin(), it)), it);
|
return Hint(static_cast<int>(std::distance(snippets.begin(), it)), it);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SnippetsCollection::replaceSnippet(int index, const Snippet &snippet, Snippet::Group group)
|
void SnippetsCollection::replaceSnippet(int index, const Snippet &snippet)
|
||||||
{
|
{
|
||||||
replaceSnippet(index, snippet, group, computeReplacementHint(index, snippet, group));
|
replaceSnippet(index, snippet, computeReplacementHint(index, snippet));
|
||||||
}
|
}
|
||||||
|
|
||||||
void SnippetsCollection::replaceSnippet(int index,
|
void SnippetsCollection::replaceSnippet(int index, const Snippet &snippet, const Hint &hint)
|
||||||
const Snippet &snippet,
|
|
||||||
Snippet::Group group,
|
|
||||||
const Hint &hint)
|
|
||||||
{
|
{
|
||||||
|
const int group = groupIndex(snippet.groupId());
|
||||||
Snippet replacement(snippet);
|
Snippet replacement(snippet);
|
||||||
if (replacement.isBuiltIn() && !replacement.isModified())
|
if (replacement.isBuiltIn() && !replacement.isModified())
|
||||||
replacement.setIsModified(true);
|
replacement.setIsModified(true);
|
||||||
@@ -155,7 +150,7 @@ void SnippetsCollection::replaceSnippet(int index,
|
|||||||
if (index == hint.index()) {
|
if (index == hint.index()) {
|
||||||
m_snippets[group][index] = replacement;
|
m_snippets[group][index] = replacement;
|
||||||
} else {
|
} else {
|
||||||
insertSnippet(replacement, group, hint);
|
insertSnippet(replacement, hint);
|
||||||
// Consider whether the row moved up towards the beginning or down towards the end.
|
// Consider whether the row moved up towards the beginning or down towards the end.
|
||||||
if (index < hint.index())
|
if (index < hint.index())
|
||||||
m_snippets[group].removeAt(index);
|
m_snippets[group].removeAt(index);
|
||||||
@@ -166,9 +161,9 @@ void SnippetsCollection::replaceSnippet(int index,
|
|||||||
}
|
}
|
||||||
|
|
||||||
SnippetsCollection::Hint SnippetsCollection::computeReplacementHint(int index,
|
SnippetsCollection::Hint SnippetsCollection::computeReplacementHint(int index,
|
||||||
const Snippet &snippet,
|
const Snippet &snippet)
|
||||||
Snippet::Group group)
|
|
||||||
{
|
{
|
||||||
|
const int group = groupIndex(snippet.groupId());
|
||||||
QList<Snippet> &snippets = m_snippets[group];
|
QList<Snippet> &snippets = m_snippets[group];
|
||||||
QList<Snippet>::iterator it = qLowerBound(
|
QList<Snippet>::iterator it = qLowerBound(
|
||||||
snippets.begin(), m_activeSnippetsEnd.at(group), snippet, snippetComp);
|
snippets.begin(), m_activeSnippetsEnd.at(group), snippet, snippetComp);
|
||||||
@@ -183,8 +178,9 @@ SnippetsCollection::Hint SnippetsCollection::computeReplacementHint(int index,
|
|||||||
return Hint(index);
|
return Hint(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SnippetsCollection::removeSnippet(int index, Snippet::Group group)
|
void SnippetsCollection::removeSnippet(int index, const QString &groupId)
|
||||||
{
|
{
|
||||||
|
const int group = groupIndex(groupId);
|
||||||
Snippet snippet(m_snippets.at(group).at(index));
|
Snippet snippet(m_snippets.at(group).at(index));
|
||||||
m_snippets[group].removeAt(index);
|
m_snippets[group].removeAt(index);
|
||||||
if (snippet.isBuiltIn()) {
|
if (snippet.isBuiltIn()) {
|
||||||
@@ -195,90 +191,99 @@ void SnippetsCollection::removeSnippet(int index, Snippet::Group group)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const Snippet &SnippetsCollection::snippet(int index, Snippet::Group group) const
|
const Snippet &SnippetsCollection::snippet(int index, const QString &groupId) const
|
||||||
{
|
{
|
||||||
return m_snippets.at(group).at(index);
|
return m_snippets.at(groupIndex(groupId)).at(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SnippetsCollection::setSnippetContent(int index, Snippet::Group group, const QString &content)
|
void SnippetsCollection::setSnippetContent(int index,
|
||||||
|
const QString &groupId,
|
||||||
|
const QString &content)
|
||||||
{
|
{
|
||||||
Snippet &snippet = m_snippets[group][index];
|
Snippet &snippet = m_snippets[groupIndex(groupId)][index];
|
||||||
snippet.setContent(content);
|
snippet.setContent(content);
|
||||||
if (snippet.isBuiltIn() && !snippet.isModified())
|
if (snippet.isBuiltIn() && !snippet.isModified())
|
||||||
snippet.setIsModified(true);
|
snippet.setIsModified(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
int SnippetsCollection::totalActiveSnippets(Snippet::Group group) const
|
int SnippetsCollection::totalActiveSnippets(const QString &groupId) const
|
||||||
{
|
{
|
||||||
|
const int group = groupIndex(groupId);
|
||||||
return std::distance<QList<Snippet>::const_iterator>(m_snippets.at(group).begin(),
|
return std::distance<QList<Snippet>::const_iterator>(m_snippets.at(group).begin(),
|
||||||
m_activeSnippetsEnd.at(group));
|
m_activeSnippetsEnd.at(group));
|
||||||
}
|
}
|
||||||
|
|
||||||
int SnippetsCollection::totalSnippets(Snippet::Group group) const
|
int SnippetsCollection::totalSnippets(const QString &groupId) const
|
||||||
{
|
{
|
||||||
return m_snippets.at(group).size();
|
return m_snippets.at(groupIndex(groupId)).size();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SnippetsCollection::clear()
|
QList<QString> SnippetsCollection::groupIds() const
|
||||||
{
|
{
|
||||||
for (Snippet::Group group = Snippet::Cpp; group < Snippet::GroupSize; ++group)
|
return m_groupIndexById.keys();
|
||||||
clear(group);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SnippetsCollection::clear(Snippet::Group group)
|
void SnippetsCollection::clearSnippets()
|
||||||
{
|
{
|
||||||
m_snippets[group].clear();
|
for (int group = 0; group < m_groupIndexById.size(); ++group)
|
||||||
m_activeSnippetsEnd[group] = m_snippets[group].end();
|
clearSnippets(group);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SnippetsCollection::updateActiveSnippetsEnd(Snippet::Group group)
|
void SnippetsCollection::clearSnippets(int groupIndex)
|
||||||
{
|
{
|
||||||
m_activeSnippetsEnd[group] = std::find_if(m_snippets[group].begin(),
|
m_snippets[groupIndex].clear();
|
||||||
m_snippets[group].end(),
|
m_activeSnippetsEnd[groupIndex] = m_snippets[groupIndex].end();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SnippetsCollection::updateActiveSnippetsEnd(int groupIndex)
|
||||||
|
{
|
||||||
|
m_activeSnippetsEnd[groupIndex] = std::find_if(m_snippets[groupIndex].begin(),
|
||||||
|
m_snippets[groupIndex].end(),
|
||||||
removedSnippetPred);
|
removedSnippetPred);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SnippetsCollection::restoreRemovedSnippets(Snippet::Group group)
|
void SnippetsCollection::restoreRemovedSnippets(const QString &groupId)
|
||||||
{
|
{
|
||||||
// The version restored contains the last modifications (if any) by the user.
|
// The version restored contains the last modifications (if any) by the user.
|
||||||
// Reverting the snippet can still bring it to the original version.
|
// Reverting the snippet can still bring it to the original version
|
||||||
|
const int group = groupIndex(groupId);
|
||||||
QVector<Snippet> toRestore(std::distance(m_activeSnippetsEnd[group], m_snippets[group].end()));
|
QVector<Snippet> toRestore(std::distance(m_activeSnippetsEnd[group], m_snippets[group].end()));
|
||||||
qCopy(m_activeSnippetsEnd[group], m_snippets[group].end(), toRestore.begin());
|
qCopy(m_activeSnippetsEnd[group], m_snippets[group].end(), toRestore.begin());
|
||||||
m_snippets[group].erase(m_activeSnippetsEnd[group], m_snippets[group].end());
|
m_snippets[group].erase(m_activeSnippetsEnd[group], m_snippets[group].end());
|
||||||
foreach (Snippet snippet, toRestore) {
|
foreach (Snippet snippet, toRestore) {
|
||||||
snippet.setIsRemoved(false);
|
snippet.setIsRemoved(false);
|
||||||
insertSnippet(snippet, group);
|
insertSnippet(snippet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Snippet SnippetsCollection::revertedSnippet(int index, Snippet::Group group) const
|
Snippet SnippetsCollection::revertedSnippet(int index, const QString &groupId) const
|
||||||
{
|
{
|
||||||
const Snippet &candidate = snippet(index, group);
|
const Snippet &candidate = snippet(index, groupId);
|
||||||
Q_ASSERT(candidate.isBuiltIn());
|
Q_ASSERT(candidate.isBuiltIn());
|
||||||
|
|
||||||
const QList<Snippet> &builtIn =
|
const QList<Snippet> &builtIn =
|
||||||
readXML(m_builtInSnippetsPath + m_snippetsFileName, candidate.id());
|
readXML(m_builtInSnippetsPath + m_snippetsFileName, candidate.id());
|
||||||
if (builtIn.size() == 1)
|
if (builtIn.size() == 1)
|
||||||
return builtIn.at(0);
|
return builtIn.at(0);
|
||||||
return Snippet();
|
return Snippet(groupId);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SnippetsCollection::reset(Snippet::Group group)
|
void SnippetsCollection::reset(const QString &groupId)
|
||||||
{
|
{
|
||||||
clear(group);
|
clearSnippets(groupIndex(groupId));
|
||||||
|
|
||||||
const QList<Snippet> &builtInSnippets = readXML(m_builtInSnippetsPath + m_snippetsFileName);
|
const QList<Snippet> &builtInSnippets = readXML(m_builtInSnippetsPath + m_snippetsFileName);
|
||||||
foreach (const Snippet &snippet, builtInSnippets)
|
foreach (const Snippet &snippet, builtInSnippets)
|
||||||
if (group == snippet.group())
|
if (groupId == snippet.groupId())
|
||||||
insertSnippet(snippet, snippet.group());
|
insertSnippet(snippet);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SnippetsCollection::reload()
|
void SnippetsCollection::reload()
|
||||||
{
|
{
|
||||||
clear();
|
clearSnippets();
|
||||||
|
|
||||||
QHash<QString, Snippet> activeBuiltInSnippets;
|
|
||||||
const QList<Snippet> &builtInSnippets = readXML(m_builtInSnippetsPath + m_snippetsFileName);
|
const QList<Snippet> &builtInSnippets = readXML(m_builtInSnippetsPath + m_snippetsFileName);
|
||||||
|
QHash<QString, Snippet> activeBuiltInSnippets;
|
||||||
foreach (const Snippet &snippet, builtInSnippets)
|
foreach (const Snippet &snippet, builtInSnippets)
|
||||||
activeBuiltInSnippets.insert(snippet.id(), snippet);
|
activeBuiltInSnippets.insert(snippet.id(), snippet);
|
||||||
|
|
||||||
@@ -287,11 +292,11 @@ void SnippetsCollection::reload()
|
|||||||
if (snippet.isBuiltIn())
|
if (snippet.isBuiltIn())
|
||||||
// This user snippet overrides the corresponding built-in snippet.
|
// This user snippet overrides the corresponding built-in snippet.
|
||||||
activeBuiltInSnippets.remove(snippet.id());
|
activeBuiltInSnippets.remove(snippet.id());
|
||||||
insertSnippet(snippet, snippet.group());
|
insertSnippet(snippet);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (const Snippet &snippet, activeBuiltInSnippets)
|
foreach (const Snippet &snippet, activeBuiltInSnippets)
|
||||||
insertSnippet(snippet, snippet.group());
|
insertSnippet(snippet);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SnippetsCollection::synchronize()
|
void SnippetsCollection::synchronize()
|
||||||
@@ -303,10 +308,10 @@ void SnippetsCollection::synchronize()
|
|||||||
writer.setAutoFormatting(true);
|
writer.setAutoFormatting(true);
|
||||||
writer.writeStartDocument();
|
writer.writeStartDocument();
|
||||||
writer.writeStartElement(kSnippets);
|
writer.writeStartElement(kSnippets);
|
||||||
for (Snippet::Group group = Snippet::Cpp; group < Snippet::GroupSize; ++group) {
|
foreach (const QString &groupId, m_groupIndexById.keys()) {
|
||||||
const int size = totalSnippets(group);
|
const int size = m_snippets.at(groupIndex(groupId)).size();
|
||||||
for (int i = 0; i < size; ++i) {
|
for (int i = 0; i < size; ++i) {
|
||||||
const Snippet ¤t = snippet(i, group);
|
const Snippet ¤t = snippet(i, groupId);
|
||||||
if (!current.isBuiltIn() || current.isRemoved() || current.isModified())
|
if (!current.isBuiltIn() || current.isRemoved() || current.isModified())
|
||||||
writeSnippetXML(current, &writer);
|
writeSnippetXML(current, &writer);
|
||||||
}
|
}
|
||||||
@@ -320,10 +325,10 @@ void SnippetsCollection::synchronize()
|
|||||||
reload();
|
reload();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SnippetsCollection::writeSnippetXML(const Snippet &snippet, QXmlStreamWriter *writer)
|
void SnippetsCollection::writeSnippetXML(const Snippet &snippet, QXmlStreamWriter *writer) const
|
||||||
{
|
{
|
||||||
writer->writeStartElement(kSnippet);
|
writer->writeStartElement(kSnippet);
|
||||||
writer->writeAttribute(kGroup, fromSnippetGroup(snippet.group()));
|
writer->writeAttribute(kGroup, snippet.groupId());
|
||||||
writer->writeAttribute(kTrigger, snippet.trigger());
|
writer->writeAttribute(kTrigger, snippet.trigger());
|
||||||
writer->writeAttribute(kId, snippet.id());
|
writer->writeAttribute(kId, snippet.id());
|
||||||
writer->writeAttribute(kComplement, snippet.complement());
|
writer->writeAttribute(kComplement, snippet.complement());
|
||||||
@@ -333,7 +338,7 @@ void SnippetsCollection::writeSnippetXML(const Snippet &snippet, QXmlStreamWrite
|
|||||||
writer->writeEndElement();
|
writer->writeEndElement();
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<Snippet> SnippetsCollection::readXML(const QString &fileName, const QString &snippetId)
|
QList<Snippet> SnippetsCollection::readXML(const QString &fileName, const QString &snippetId) const
|
||||||
{
|
{
|
||||||
QList<Snippet> snippets;
|
QList<Snippet> snippets;
|
||||||
QFile file(fileName);
|
QFile file(fileName);
|
||||||
@@ -345,11 +350,11 @@ QList<Snippet> SnippetsCollection::readXML(const QString &fileName, const QStrin
|
|||||||
if (xml.name() == kSnippet) {
|
if (xml.name() == kSnippet) {
|
||||||
const QXmlStreamAttributes &atts = xml.attributes();
|
const QXmlStreamAttributes &atts = xml.attributes();
|
||||||
const QString &id = atts.value(kId).toString();
|
const QString &id = atts.value(kId).toString();
|
||||||
if (snippetId.isEmpty() || snippetId == id) {
|
const QString &groupId = atts.value(kGroup).toString();
|
||||||
Snippet snippet(id);
|
if (isGroupKnown(groupId) && (snippetId.isEmpty() || snippetId == id)) {
|
||||||
|
Snippet snippet(groupId, id);
|
||||||
snippet.setTrigger(atts.value(kTrigger).toString());
|
snippet.setTrigger(atts.value(kTrigger).toString());
|
||||||
snippet.setComplement(atts.value(kComplement).toString());
|
snippet.setComplement(atts.value(kComplement).toString());
|
||||||
snippet.setGroup(toSnippetGroup(atts.value(kGroup).toString()));
|
|
||||||
snippet.setIsRemoved(toBool(atts.value(kRemoved).toString()));
|
snippet.setIsRemoved(toBool(atts.value(kRemoved).toString()));
|
||||||
snippet.setIsModified(toBool(atts.value(kModified).toString()));
|
snippet.setIsModified(toBool(atts.value(kModified).toString()));
|
||||||
|
|
||||||
@@ -383,3 +388,28 @@ QList<Snippet> SnippetsCollection::readXML(const QString &fileName, const QStrin
|
|||||||
|
|
||||||
return snippets;
|
return snippets;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int SnippetsCollection::groupIndex(const QString &groupId) const
|
||||||
|
{
|
||||||
|
return m_groupIndexById.value(groupId);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SnippetsCollection::identifyGroups()
|
||||||
|
{
|
||||||
|
const QList<ISnippetProvider *> &providers =
|
||||||
|
ExtensionSystem::PluginManager::instance()->getObjects<ISnippetProvider>();
|
||||||
|
foreach (ISnippetProvider *provider, providers) {
|
||||||
|
const int groupIndex = m_groupIndexById.size();
|
||||||
|
m_groupIndexById.insert(provider->groupId(), groupIndex);
|
||||||
|
m_snippets.resize(groupIndex + 1);
|
||||||
|
m_activeSnippetsEnd.resize(groupIndex + 1);
|
||||||
|
m_activeSnippetsEnd[groupIndex] = m_snippets[groupIndex].end();
|
||||||
|
}
|
||||||
|
|
||||||
|
reload();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SnippetsCollection::isGroupKnown(const QString &groupId) const
|
||||||
|
{
|
||||||
|
return m_groupIndexById.value(groupId, -1) != -1;
|
||||||
|
}
|
||||||
|
|||||||
@@ -34,6 +34,7 @@
|
|||||||
|
|
||||||
#include <QtCore/QVector>
|
#include <QtCore/QVector>
|
||||||
#include <QtCore/QList>
|
#include <QtCore/QList>
|
||||||
|
#include <QtCore/QHash>
|
||||||
|
|
||||||
QT_FORWARD_DECLARE_CLASS(QXmlStreamWriter)
|
QT_FORWARD_DECLARE_CLASS(QXmlStreamWriter)
|
||||||
|
|
||||||
@@ -49,8 +50,9 @@ namespace Internal {
|
|||||||
// - Provide fast index access.
|
// - Provide fast index access.
|
||||||
// - Not thread-safe.
|
// - Not thread-safe.
|
||||||
|
|
||||||
class SnippetsCollection
|
class SnippetsCollection : public QObject
|
||||||
{
|
{
|
||||||
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
SnippetsCollection();
|
SnippetsCollection();
|
||||||
~SnippetsCollection();
|
~SnippetsCollection();
|
||||||
@@ -61,43 +63,52 @@ public:
|
|||||||
public:
|
public:
|
||||||
int index() const;
|
int index() const;
|
||||||
private:
|
private:
|
||||||
Hint(int index);
|
explicit Hint(int index);
|
||||||
Hint(int index, QList<Snippet>::iterator it);
|
Hint(int index, QList<Snippet>::iterator it);
|
||||||
int m_index;
|
int m_index;
|
||||||
QList<Snippet>::iterator m_it;
|
QList<Snippet>::iterator m_it;
|
||||||
};
|
};
|
||||||
|
|
||||||
void insertSnippet(const Snippet &snippet, Snippet::Group group);
|
void insertSnippet(const Snippet &snippet);
|
||||||
void insertSnippet(const Snippet &snippet, Snippet::Group group, const Hint &hint);
|
void insertSnippet(const Snippet &snippet, const Hint &hint);
|
||||||
Hint computeInsertionHint(const Snippet &snippet, Snippet::Group group);
|
Hint computeInsertionHint(const Snippet &snippet);
|
||||||
|
|
||||||
void replaceSnippet(int index, const Snippet &snippet, Snippet::Group group);
|
// Replace snippets only within the same group.
|
||||||
void replaceSnippet(int index, const Snippet &snippet, Snippet::Group group, const Hint &hint);
|
void replaceSnippet(int index, const Snippet &snippet);
|
||||||
Hint computeReplacementHint(int index, const Snippet &snippet, Snippet::Group group);
|
void replaceSnippet(int index, const Snippet &snippet, const Hint &hint);
|
||||||
|
Hint computeReplacementHint(int index, const Snippet &snippet);
|
||||||
|
|
||||||
void removeSnippet(int index, Snippet::Group group);
|
void removeSnippet(int index, const QString &groupId);
|
||||||
void restoreRemovedSnippets(Snippet::Group group);
|
void restoreRemovedSnippets(const QString &groupId);
|
||||||
|
|
||||||
void setSnippetContent(int index, Snippet::Group group, const QString &content);
|
void setSnippetContent(int index, const QString &groupId, const QString &content);
|
||||||
|
|
||||||
const Snippet &snippet(int index, Snippet::Group group) const;
|
const Snippet &snippet(int index, const QString &groupId) const;
|
||||||
Snippet revertedSnippet(int index, Snippet::Group group) const;
|
Snippet revertedSnippet(int index, const QString &groupId) const;
|
||||||
|
|
||||||
void reset(Snippet::Group group);
|
void reset(const QString &groupId);
|
||||||
|
|
||||||
int totalActiveSnippets(Snippet::Group group) const;
|
int totalActiveSnippets(const QString &groupId) const;
|
||||||
int totalSnippets(Snippet::Group group) const;
|
int totalSnippets(const QString &groupId) const;
|
||||||
|
|
||||||
|
QList<QString> groupIds() const;
|
||||||
|
|
||||||
void reload();
|
void reload();
|
||||||
void synchronize();
|
void synchronize();
|
||||||
|
|
||||||
private:
|
private slots:
|
||||||
void clear();
|
void identifyGroups();
|
||||||
void clear(Snippet::Group group);
|
|
||||||
void updateActiveSnippetsEnd(Snippet::Group group);
|
|
||||||
|
|
||||||
static QList<Snippet> readXML(const QString &fileName, const QString &snippetId = QString());
|
private:
|
||||||
static void writeSnippetXML(const Snippet &snippet, QXmlStreamWriter *writer);
|
int groupIndex(const QString &groupId) const;
|
||||||
|
|
||||||
|
void clearSnippets();
|
||||||
|
void clearSnippets(int groupIndex);
|
||||||
|
|
||||||
|
void updateActiveSnippetsEnd(int groupIndex);
|
||||||
|
|
||||||
|
QList<Snippet> readXML(const QString &fileName, const QString &snippetId = QString()) const;
|
||||||
|
void writeSnippetXML(const Snippet &snippet, QXmlStreamWriter *writer) const;
|
||||||
|
|
||||||
static const QLatin1String kSnippet;
|
static const QLatin1String kSnippet;
|
||||||
static const QLatin1String kSnippets;
|
static const QLatin1String kSnippets;
|
||||||
@@ -108,11 +119,7 @@ private:
|
|||||||
static const QLatin1String kRemoved;
|
static const QLatin1String kRemoved;
|
||||||
static const QLatin1String kModified;
|
static const QLatin1String kModified;
|
||||||
|
|
||||||
// Snippets for each group are kept in a list. However, not all of them are necessarily
|
bool isGroupKnown(const QString &groupId) const;
|
||||||
// active. Specifically, removed built-in snippets are kept as the last ones (for each
|
|
||||||
// group there is a iterator that marks the logical end).
|
|
||||||
QVector<QList<Snippet> > m_snippets;
|
|
||||||
QVector<QList<Snippet>::iterator> m_activeSnippetsEnd;
|
|
||||||
|
|
||||||
// Built-in snippets are specified in an XML embedded as a resource. Snippets created/
|
// Built-in snippets are specified in an XML embedded as a resource. Snippets created/
|
||||||
// modified/removed by the user are stored in another XML created dynamically in the
|
// modified/removed by the user are stored in another XML created dynamically in the
|
||||||
@@ -120,6 +127,14 @@ private:
|
|||||||
QString m_builtInSnippetsPath;
|
QString m_builtInSnippetsPath;
|
||||||
QString m_userSnippetsPath;
|
QString m_userSnippetsPath;
|
||||||
QString m_snippetsFileName;
|
QString m_snippetsFileName;
|
||||||
|
|
||||||
|
// Snippets for each group are kept in a list. However, not all of them are necessarily
|
||||||
|
// active. Specifically, removed built-in snippets are kept as the last ones (for each
|
||||||
|
// group there is a iterator that marks the logical end).
|
||||||
|
QVector<QList<Snippet> > m_snippets;
|
||||||
|
QVector<QList<Snippet>::iterator> m_activeSnippetsEnd;
|
||||||
|
|
||||||
|
QHash<QString, int> m_groupIndexById;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // Internal
|
} // Internal
|
||||||
|
|||||||
@@ -33,6 +33,9 @@
|
|||||||
#include <QtCore/QSharedPointer>
|
#include <QtCore/QSharedPointer>
|
||||||
|
|
||||||
namespace TextEditor {
|
namespace TextEditor {
|
||||||
|
|
||||||
|
class ISnippetProvider;
|
||||||
|
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
class SnippetsCollection;
|
class SnippetsCollection;
|
||||||
|
|||||||
@@ -57,8 +57,7 @@ void SnippetsSettings::fromSettings(const QString &category, QSettings *s)
|
|||||||
{
|
{
|
||||||
const QString &group = category + kGroupPostfix;
|
const QString &group = category + kGroupPostfix;
|
||||||
s->beginGroup(group);
|
s->beginGroup(group);
|
||||||
m_lastUsedSnippetGroup =
|
m_lastUsedSnippetGroup = s->value(kLastUsedSnippetGroup, QString()).toString();
|
||||||
s->value(kLastUsedSnippetGroup, fromSnippetGroup(Snippet::Cpp)).toString();
|
|
||||||
s->endGroup();
|
s->endGroup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,7 @@
|
|||||||
#include "snippetssettingspage.h"
|
#include "snippetssettingspage.h"
|
||||||
#include "snippetsmanager.h"
|
#include "snippetsmanager.h"
|
||||||
#include "snippeteditor.h"
|
#include "snippeteditor.h"
|
||||||
#include "isnippeteditordecorator.h"
|
#include "isnippetprovider.h"
|
||||||
#include "snippet.h"
|
#include "snippet.h"
|
||||||
#include "snippetscollection.h"
|
#include "snippetscollection.h"
|
||||||
#include "snippetssettings.h"
|
#include "snippetssettings.h"
|
||||||
@@ -46,6 +46,7 @@
|
|||||||
#include <QtCore/QList>
|
#include <QtCore/QList>
|
||||||
#include <QtCore/QSettings>
|
#include <QtCore/QSettings>
|
||||||
#include <QtCore/QTextStream>
|
#include <QtCore/QTextStream>
|
||||||
|
#include <QtCore/QHash>
|
||||||
#include <QtGui/QMessageBox>
|
#include <QtGui/QMessageBox>
|
||||||
|
|
||||||
namespace TextEditor {
|
namespace TextEditor {
|
||||||
@@ -68,7 +69,8 @@ public:
|
|||||||
virtual QVariant headerData(int section, Qt::Orientation orientation,
|
virtual QVariant headerData(int section, Qt::Orientation orientation,
|
||||||
int role = Qt::DisplayRole) const;
|
int role = Qt::DisplayRole) const;
|
||||||
|
|
||||||
void load(Snippet::Group group);
|
QList<QString> groupIds() const;
|
||||||
|
void load(const QString &groupId);
|
||||||
|
|
||||||
QModelIndex createSnippet();
|
QModelIndex createSnippet();
|
||||||
QModelIndex insertSnippet(const Snippet &snippet);
|
QModelIndex insertSnippet(const Snippet &snippet);
|
||||||
@@ -83,13 +85,12 @@ private:
|
|||||||
void replaceSnippet(const Snippet &snippet, const QModelIndex &modelIndex);
|
void replaceSnippet(const Snippet &snippet, const QModelIndex &modelIndex);
|
||||||
static bool isValidTrigger(const QString &s);
|
static bool isValidTrigger(const QString &s);
|
||||||
|
|
||||||
Snippet::Group m_activeGroup;
|
|
||||||
QSharedPointer<SnippetsCollection> m_collection;
|
QSharedPointer<SnippetsCollection> m_collection;
|
||||||
|
QString m_activeGroupId;
|
||||||
};
|
};
|
||||||
|
|
||||||
SnippetsTableModel::SnippetsTableModel(QObject *parent) :
|
SnippetsTableModel::SnippetsTableModel(QObject *parent) :
|
||||||
QAbstractTableModel(parent),
|
QAbstractTableModel(parent),
|
||||||
m_activeGroup(Snippet::Cpp),
|
|
||||||
m_collection(SnippetsManager::instance()->snippetsCollection())
|
m_collection(SnippetsManager::instance()->snippetsCollection())
|
||||||
{}
|
{}
|
||||||
|
|
||||||
@@ -97,7 +98,7 @@ int SnippetsTableModel::rowCount(const QModelIndex &) const
|
|||||||
{
|
{
|
||||||
if (m_collection.isNull())
|
if (m_collection.isNull())
|
||||||
return 0;
|
return 0;
|
||||||
return m_collection->totalActiveSnippets(m_activeGroup);
|
return m_collection->totalActiveSnippets(m_activeGroupId);
|
||||||
}
|
}
|
||||||
|
|
||||||
int SnippetsTableModel::columnCount(const QModelIndex &) const
|
int SnippetsTableModel::columnCount(const QModelIndex &) const
|
||||||
@@ -121,7 +122,7 @@ QVariant SnippetsTableModel::data(const QModelIndex &modelIndex, int role) const
|
|||||||
return QVariant();
|
return QVariant();
|
||||||
|
|
||||||
if (role == Qt::DisplayRole || role == Qt::EditRole) {
|
if (role == Qt::DisplayRole || role == Qt::EditRole) {
|
||||||
const Snippet &snippet = m_collection->snippet(modelIndex.row(), m_activeGroup);
|
const Snippet &snippet = m_collection->snippet(modelIndex.row(), m_activeGroupId);
|
||||||
if (modelIndex.column() == 0)
|
if (modelIndex.column() == 0)
|
||||||
return snippet.trigger();
|
return snippet.trigger();
|
||||||
else
|
else
|
||||||
@@ -134,7 +135,7 @@ QVariant SnippetsTableModel::data(const QModelIndex &modelIndex, int role) const
|
|||||||
bool SnippetsTableModel::setData(const QModelIndex &modelIndex, const QVariant &value, int role)
|
bool SnippetsTableModel::setData(const QModelIndex &modelIndex, const QVariant &value, int role)
|
||||||
{
|
{
|
||||||
if (modelIndex.isValid() && role == Qt::EditRole) {
|
if (modelIndex.isValid() && role == Qt::EditRole) {
|
||||||
Snippet snippet(m_collection->snippet(modelIndex.row(), m_activeGroup));
|
Snippet snippet(m_collection->snippet(modelIndex.row(), m_activeGroupId));
|
||||||
if (modelIndex.column() == 0) {
|
if (modelIndex.column() == 0) {
|
||||||
const QString &s = value.toString();
|
const QString &s = value.toString();
|
||||||
if (!isValidTrigger(s)) {
|
if (!isValidTrigger(s)) {
|
||||||
@@ -165,25 +166,28 @@ QVariant SnippetsTableModel::headerData(int section, Qt::Orientation orientation
|
|||||||
return tr("Complement");
|
return tr("Complement");
|
||||||
}
|
}
|
||||||
|
|
||||||
void SnippetsTableModel::load(Snippet::Group group)
|
void SnippetsTableModel::load(const QString &groupId)
|
||||||
{
|
{
|
||||||
m_activeGroup = group;
|
m_activeGroupId = groupId;
|
||||||
reset();
|
reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList<QString> SnippetsTableModel::groupIds() const
|
||||||
|
{
|
||||||
|
return m_collection->groupIds();
|
||||||
|
}
|
||||||
|
|
||||||
QModelIndex SnippetsTableModel::createSnippet()
|
QModelIndex SnippetsTableModel::createSnippet()
|
||||||
{
|
{
|
||||||
Snippet snippet;
|
Snippet snippet(m_activeGroupId);
|
||||||
snippet.setGroup(m_activeGroup);
|
|
||||||
return insertSnippet(snippet);
|
return insertSnippet(snippet);
|
||||||
}
|
}
|
||||||
|
|
||||||
QModelIndex SnippetsTableModel::insertSnippet(const Snippet &snippet)
|
QModelIndex SnippetsTableModel::insertSnippet(const Snippet &snippet)
|
||||||
{
|
{
|
||||||
const SnippetsCollection::Hint &hint =
|
const SnippetsCollection::Hint &hint = m_collection->computeInsertionHint(snippet);
|
||||||
m_collection->computeInsertionHint(snippet, m_activeGroup);
|
|
||||||
beginInsertRows(QModelIndex(), hint.index(), hint.index());
|
beginInsertRows(QModelIndex(), hint.index(), hint.index());
|
||||||
m_collection->insertSnippet(snippet, m_activeGroup, hint);
|
m_collection->insertSnippet(snippet, hint);
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
|
|
||||||
return index(hint.index(), 0);
|
return index(hint.index(), 0);
|
||||||
@@ -192,23 +196,23 @@ QModelIndex SnippetsTableModel::insertSnippet(const Snippet &snippet)
|
|||||||
void SnippetsTableModel::removeSnippet(const QModelIndex &modelIndex)
|
void SnippetsTableModel::removeSnippet(const QModelIndex &modelIndex)
|
||||||
{
|
{
|
||||||
beginRemoveRows(QModelIndex(), modelIndex.row(), modelIndex.row());
|
beginRemoveRows(QModelIndex(), modelIndex.row(), modelIndex.row());
|
||||||
m_collection->removeSnippet(modelIndex.row(), m_activeGroup);
|
m_collection->removeSnippet(modelIndex.row(), m_activeGroupId);
|
||||||
endRemoveRows();
|
endRemoveRows();
|
||||||
}
|
}
|
||||||
|
|
||||||
const Snippet &SnippetsTableModel::snippetAt(const QModelIndex &modelIndex) const
|
const Snippet &SnippetsTableModel::snippetAt(const QModelIndex &modelIndex) const
|
||||||
{
|
{
|
||||||
return m_collection->snippet(modelIndex.row(), m_activeGroup);
|
return m_collection->snippet(modelIndex.row(), m_activeGroupId);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SnippetsTableModel::setSnippetContent(const QModelIndex &modelIndex, const QString &content)
|
void SnippetsTableModel::setSnippetContent(const QModelIndex &modelIndex, const QString &content)
|
||||||
{
|
{
|
||||||
m_collection->setSnippetContent(modelIndex.row(), m_activeGroup, content);
|
m_collection->setSnippetContent(modelIndex.row(), m_activeGroupId, content);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SnippetsTableModel::revertBuitInSnippet(const QModelIndex &modelIndex)
|
void SnippetsTableModel::revertBuitInSnippet(const QModelIndex &modelIndex)
|
||||||
{
|
{
|
||||||
const Snippet &snippet = m_collection->revertedSnippet(modelIndex.row(), m_activeGroup);
|
const Snippet &snippet = m_collection->revertedSnippet(modelIndex.row(), m_activeGroupId);
|
||||||
if (snippet.id().isEmpty()) {
|
if (snippet.id().isEmpty()) {
|
||||||
QMessageBox::critical(0, tr("Error"), tr("Error reverting snippet."));
|
QMessageBox::critical(0, tr("Error"), tr("Error reverting snippet."));
|
||||||
return;
|
return;
|
||||||
@@ -218,13 +222,13 @@ void SnippetsTableModel::revertBuitInSnippet(const QModelIndex &modelIndex)
|
|||||||
|
|
||||||
void SnippetsTableModel::restoreRemovedBuiltInSnippets()
|
void SnippetsTableModel::restoreRemovedBuiltInSnippets()
|
||||||
{
|
{
|
||||||
m_collection->restoreRemovedSnippets(m_activeGroup);
|
m_collection->restoreRemovedSnippets(m_activeGroupId);
|
||||||
reset();
|
reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SnippetsTableModel::resetSnippets()
|
void SnippetsTableModel::resetSnippets()
|
||||||
{
|
{
|
||||||
m_collection->reset(m_activeGroup);
|
m_collection->reset(m_activeGroupId);
|
||||||
reset();
|
reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -232,9 +236,9 @@ void SnippetsTableModel::replaceSnippet(const Snippet &snippet, const QModelInde
|
|||||||
{
|
{
|
||||||
const int row = modelIndex.row();
|
const int row = modelIndex.row();
|
||||||
const SnippetsCollection::Hint &hint =
|
const SnippetsCollection::Hint &hint =
|
||||||
m_collection->computeReplacementHint(row, snippet, m_activeGroup);
|
m_collection->computeReplacementHint(row, snippet);
|
||||||
if (modelIndex.row() == hint.index()) {
|
if (modelIndex.row() == hint.index()) {
|
||||||
m_collection->replaceSnippet(row, snippet, m_activeGroup, hint);
|
m_collection->replaceSnippet(row, snippet, hint);
|
||||||
emit dataChanged(modelIndex, modelIndex);
|
emit dataChanged(modelIndex, modelIndex);
|
||||||
} else {
|
} else {
|
||||||
if (row < hint.index())
|
if (row < hint.index())
|
||||||
@@ -242,7 +246,7 @@ void SnippetsTableModel::replaceSnippet(const Snippet &snippet, const QModelInde
|
|||||||
beginMoveRows(QModelIndex(), row, row, QModelIndex(), hint.index() + 1);
|
beginMoveRows(QModelIndex(), row, row, QModelIndex(), hint.index() + 1);
|
||||||
else
|
else
|
||||||
beginMoveRows(QModelIndex(), row, row, QModelIndex(), hint.index());
|
beginMoveRows(QModelIndex(), row, row, QModelIndex(), hint.index());
|
||||||
m_collection->replaceSnippet(row, snippet, m_activeGroup, hint);
|
m_collection->replaceSnippet(row, snippet, hint);
|
||||||
endMoveRows();
|
endMoveRows();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -290,8 +294,6 @@ private:
|
|||||||
SnippetEditor *currentEditor() const;
|
SnippetEditor *currentEditor() const;
|
||||||
SnippetEditor *editorAt(int i) const;
|
SnippetEditor *editorAt(int i) const;
|
||||||
|
|
||||||
static void decorateEditor(SnippetEditor *editor, Snippet::Group group);
|
|
||||||
|
|
||||||
void loadSettings();
|
void loadSettings();
|
||||||
bool settingsChanged() const;
|
bool settingsChanged() const;
|
||||||
void writeSettings();
|
void writeSettings();
|
||||||
@@ -328,9 +330,15 @@ void SnippetsSettingsPagePrivate::configureUi(QWidget *w)
|
|||||||
{
|
{
|
||||||
m_ui.setupUi(w);
|
m_ui.setupUi(w);
|
||||||
|
|
||||||
m_ui.groupCombo->insertItem(Snippet::Cpp, fromSnippetGroup(Snippet::Cpp));
|
const QList<ISnippetProvider *> &providers =
|
||||||
m_ui.groupCombo->insertItem(Snippet::Qml, fromSnippetGroup(Snippet::Qml));
|
ExtensionSystem::PluginManager::instance()->getObjects<ISnippetProvider>();
|
||||||
m_ui.groupCombo->insertItem(Snippet::PlainText, fromSnippetGroup(Snippet::PlainText));
|
foreach (ISnippetProvider *provider, providers) {
|
||||||
|
m_ui.groupCombo->addItem(provider->displayName(), provider->groupId());
|
||||||
|
SnippetEditor *snippetEditor = new SnippetEditor(w);
|
||||||
|
provider->decorateEditor(snippetEditor);
|
||||||
|
m_ui.snippetsEditorStack->insertWidget(m_ui.groupCombo->count() - 1, snippetEditor);
|
||||||
|
connect(snippetEditor, SIGNAL(snippetContentChanged()), this, SLOT(setSnippetContent()));
|
||||||
|
}
|
||||||
|
|
||||||
m_ui.snippetsTable->setSelectionBehavior(QAbstractItemView::SelectRows);
|
m_ui.snippetsTable->setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||||
m_ui.snippetsTable->setSelectionMode(QAbstractItemView::SingleSelection);
|
m_ui.snippetsTable->setSelectionMode(QAbstractItemView::SingleSelection);
|
||||||
@@ -340,13 +348,6 @@ void SnippetsSettingsPagePrivate::configureUi(QWidget *w)
|
|||||||
m_ui.snippetsTable->verticalHeader()->setDefaultSectionSize(20);
|
m_ui.snippetsTable->verticalHeader()->setDefaultSectionSize(20);
|
||||||
m_ui.snippetsTable->setModel(m_model);
|
m_ui.snippetsTable->setModel(m_model);
|
||||||
|
|
||||||
m_ui.snippetsEditorStack->insertWidget(Snippet::Cpp, new SnippetEditor(w));
|
|
||||||
m_ui.snippetsEditorStack->insertWidget(Snippet::Qml, new SnippetEditor(w));
|
|
||||||
m_ui.snippetsEditorStack->insertWidget(Snippet::PlainText, new SnippetEditor(w));
|
|
||||||
decorateEditor(editorAt(Snippet::Cpp), Snippet::Cpp);
|
|
||||||
decorateEditor(editorAt(Snippet::Qml), Snippet::Qml);
|
|
||||||
decorateEditor(editorAt(Snippet::PlainText), Snippet::PlainText);
|
|
||||||
|
|
||||||
m_ui.revertButton->setEnabled(false);
|
m_ui.revertButton->setEnabled(false);
|
||||||
|
|
||||||
QTextStream(&m_keywords) << m_displayName;
|
QTextStream(&m_keywords) << m_displayName;
|
||||||
@@ -354,13 +355,6 @@ void SnippetsSettingsPagePrivate::configureUi(QWidget *w)
|
|||||||
loadSettings();
|
loadSettings();
|
||||||
loadSnippetGroup(m_ui.groupCombo->currentIndex());
|
loadSnippetGroup(m_ui.groupCombo->currentIndex());
|
||||||
|
|
||||||
connect(editorAt(Snippet::Cpp), SIGNAL(snippetContentChanged()),
|
|
||||||
this, SLOT(setSnippetContent()));
|
|
||||||
connect(editorAt(Snippet::Qml), SIGNAL(snippetContentChanged()),
|
|
||||||
this, SLOT(setSnippetContent()));
|
|
||||||
connect(editorAt(Snippet::PlainText), SIGNAL(snippetContentChanged()),
|
|
||||||
this, SLOT(setSnippetContent()));
|
|
||||||
|
|
||||||
connect(m_model, SIGNAL(rowsInserted(QModelIndex, int, int)),
|
connect(m_model, SIGNAL(rowsInserted(QModelIndex, int, int)),
|
||||||
this, SLOT(selectSnippet(QModelIndex,int)));
|
this, SLOT(selectSnippet(QModelIndex,int)));
|
||||||
connect(m_model, SIGNAL(rowsInserted(QModelIndex, int, int)),
|
connect(m_model, SIGNAL(rowsInserted(QModelIndex, int, int)),
|
||||||
@@ -387,15 +381,6 @@ void SnippetsSettingsPagePrivate::configureUi(QWidget *w)
|
|||||||
this, SLOT(updateCurrentSnippetDependent(QModelIndex)));
|
this, SLOT(updateCurrentSnippetDependent(QModelIndex)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void SnippetsSettingsPagePrivate::decorateEditor(SnippetEditor *editor, Snippet::Group group)
|
|
||||||
{
|
|
||||||
const QList<ISnippetEditorDecorator *> &decorators =
|
|
||||||
ExtensionSystem::PluginManager::instance()->getObjects<ISnippetEditorDecorator>();
|
|
||||||
foreach (ISnippetEditorDecorator *decorator, decorators)
|
|
||||||
if (decorator->supports(group))
|
|
||||||
decorator->apply(editor);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SnippetsSettingsPagePrivate::apply()
|
void SnippetsSettingsPagePrivate::apply()
|
||||||
{
|
{
|
||||||
if (settingsChanged())
|
if (settingsChanged())
|
||||||
@@ -417,14 +402,25 @@ void SnippetsSettingsPagePrivate::finish()
|
|||||||
|
|
||||||
void SnippetsSettingsPagePrivate::loadSettings()
|
void SnippetsSettingsPagePrivate::loadSettings()
|
||||||
{
|
{
|
||||||
|
if (m_ui.groupCombo->count() == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
if (QSettings *s = Core::ICore::instance()->settings()) {
|
if (QSettings *s = Core::ICore::instance()->settings()) {
|
||||||
m_settings.fromSettings(m_settingsPrefix, s);
|
m_settings.fromSettings(m_settingsPrefix, s);
|
||||||
m_ui.groupCombo->setCurrentIndex(toSnippetGroup(m_settings.lastUsedSnippetGroup()));
|
const QString &lastGroupName = m_settings.lastUsedSnippetGroup();
|
||||||
|
const int index = m_ui.groupCombo->findText(lastGroupName);
|
||||||
|
if (index != -1)
|
||||||
|
m_ui.groupCombo->setCurrentIndex(index);
|
||||||
|
else
|
||||||
|
m_ui.groupCombo->setCurrentIndex(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SnippetsSettingsPagePrivate::writeSettings()
|
void SnippetsSettingsPagePrivate::writeSettings()
|
||||||
{
|
{
|
||||||
|
if (m_ui.groupCombo->count() == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
if (QSettings *s = Core::ICore::instance()->settings()) {
|
if (QSettings *s = Core::ICore::instance()->settings()) {
|
||||||
m_settings.setLastUsedSnippetGroup(m_ui.groupCombo->currentText());
|
m_settings.setLastUsedSnippetGroup(m_ui.groupCombo->currentText());
|
||||||
m_settings.toSettings(m_settingsPrefix, s);
|
m_settings.toSettings(m_settingsPrefix, s);
|
||||||
@@ -440,9 +436,12 @@ bool SnippetsSettingsPagePrivate::settingsChanged() const
|
|||||||
|
|
||||||
void SnippetsSettingsPagePrivate::loadSnippetGroup(int index)
|
void SnippetsSettingsPagePrivate::loadSnippetGroup(int index)
|
||||||
{
|
{
|
||||||
|
if (index == -1)
|
||||||
|
return;
|
||||||
|
|
||||||
m_ui.snippetsEditorStack->setCurrentIndex(index);
|
m_ui.snippetsEditorStack->setCurrentIndex(index);
|
||||||
currentEditor()->clear();
|
currentEditor()->clear();
|
||||||
m_model->load(Snippet::Group(index));
|
m_model->load(m_ui.groupCombo->itemData(index).toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
void SnippetsSettingsPagePrivate::markSnippetsCollection()
|
void SnippetsSettingsPagePrivate::markSnippetsCollection()
|
||||||
|
|||||||
@@ -77,10 +77,11 @@ SOURCES += texteditorplugin.cpp \
|
|||||||
snippets/snippet.cpp \
|
snippets/snippet.cpp \
|
||||||
snippets/snippetsmanager.cpp \
|
snippets/snippetsmanager.cpp \
|
||||||
snippets/snippeteditor.cpp \
|
snippets/snippeteditor.cpp \
|
||||||
snippets/isnippeteditordecorator.cpp \
|
|
||||||
snippets/snippetscollection.cpp \
|
snippets/snippetscollection.cpp \
|
||||||
snippets/snippetssettings.cpp \
|
snippets/snippetssettings.cpp \
|
||||||
snippets/snippetprovider.cpp
|
snippets/isnippetprovider.cpp \
|
||||||
|
snippets/snippetcollector.cpp \
|
||||||
|
snippets/plaintextsnippetprovider.cpp
|
||||||
|
|
||||||
HEADERS += texteditorplugin.h \
|
HEADERS += texteditorplugin.h \
|
||||||
textfilewizard.h \
|
textfilewizard.h \
|
||||||
@@ -159,11 +160,12 @@ HEADERS += texteditorplugin.h \
|
|||||||
snippets/snippet.h \
|
snippets/snippet.h \
|
||||||
snippets/snippetsmanager.h \
|
snippets/snippetsmanager.h \
|
||||||
snippets/snippeteditor.h \
|
snippets/snippeteditor.h \
|
||||||
snippets/isnippeteditordecorator.h \
|
|
||||||
snippets/snippetscollection.h \
|
snippets/snippetscollection.h \
|
||||||
snippets/reuse.h \
|
snippets/reuse.h \
|
||||||
snippets/snippetssettings.h \
|
snippets/snippetssettings.h \
|
||||||
snippets/snippetprovider.h
|
snippets/isnippetprovider.h \
|
||||||
|
snippets/snippetcollector.h \
|
||||||
|
snippets/plaintextsnippetprovider.h
|
||||||
|
|
||||||
FORMS += behaviorsettingspage.ui \
|
FORMS += behaviorsettingspage.ui \
|
||||||
displaysettingspage.ui \
|
displaysettingspage.ui \
|
||||||
|
|||||||
@@ -143,6 +143,7 @@ const char * const TEXT_EDITOR_HIGHLIGHTER_SETTINGS = "E.HighlighterSettings";
|
|||||||
const char * const TEXT_EDITOR_SNIPPETS_SETTINGS = "F.SnippetsSettings";
|
const char * const TEXT_EDITOR_SNIPPETS_SETTINGS = "F.SnippetsSettings";
|
||||||
|
|
||||||
const char * const SNIPPET_EDITOR_ID = "TextEditor.SnippetEditor";
|
const char * const SNIPPET_EDITOR_ID = "TextEditor.SnippetEditor";
|
||||||
|
const char * const TEXT_SNIPPET_GROUP_ID = "Text";
|
||||||
|
|
||||||
} // namespace Constants
|
} // namespace Constants
|
||||||
} // namespace TextEditor
|
} // namespace TextEditor
|
||||||
|
|||||||
@@ -41,6 +41,7 @@
|
|||||||
#include "storagesettings.h"
|
#include "storagesettings.h"
|
||||||
#include "manager.h"
|
#include "manager.h"
|
||||||
#include "outlinefactory.h"
|
#include "outlinefactory.h"
|
||||||
|
#include "snippets/plaintextsnippetprovider.h"
|
||||||
|
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
#include <coreplugin/coreconstants.h>
|
#include <coreplugin/coreconstants.h>
|
||||||
@@ -144,6 +145,9 @@ bool TextEditorPlugin::initialize(const QStringList &arguments, QString *errorMe
|
|||||||
connect(Core::ICore::instance(), SIGNAL(coreOpened()),
|
connect(Core::ICore::instance(), SIGNAL(coreOpened()),
|
||||||
Manager::instance(), SLOT(registerMimeTypes()));
|
Manager::instance(), SLOT(registerMimeTypes()));
|
||||||
|
|
||||||
|
// Add text snippet provider.
|
||||||
|
addAutoReleasedObject(new PlainTextSnippetProvider);
|
||||||
|
|
||||||
m_outlineFactory = new OutlineFactory;
|
m_outlineFactory = new OutlineFactory;
|
||||||
addAutoReleasedObject(m_outlineFactory);
|
addAutoReleasedObject(m_outlineFactory);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user