forked from qt-creator/qt-creator
Snippets: Feature enhancement start...
Provide an interface so users can create/edit/remove snippets.
This commit is contained in:
@@ -487,7 +487,7 @@ CodeCompletion::CodeCompletion(ModelManagerInterface *modelManager, QObject *par
|
||||
m_editor(0),
|
||||
m_startPosition(0),
|
||||
m_restartCompletion(false),
|
||||
m_snippetsParser(Core::ICore::instance()->resourcePath() + QLatin1String("/snippets/qml.xml"))
|
||||
m_snippetProvider(TextEditor::Snippet::Qml, iconForColor(Qt::red), SnippetOrder)
|
||||
{
|
||||
Q_ASSERT(modelManager);
|
||||
}
|
||||
@@ -952,7 +952,7 @@ int CodeCompletion::startCompletion(TextEditor::ITextEditable *editor)
|
||||
}
|
||||
|
||||
if (isQmlFile && (completionOperator.isNull() || completionOperator.isSpace() || isDelimiter(completionOperator))) {
|
||||
m_completions.append(m_snippetsParser.execute(this, iconForColor(Qt::red), SnippetOrder));
|
||||
m_completions.append(m_snippetProvider.getSnippets(this));
|
||||
}
|
||||
|
||||
if (! m_completions.isEmpty())
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
|
||||
#include <qmljs/qmljsdocument.h>
|
||||
#include <texteditor/icompletioncollector.h>
|
||||
#include <texteditor/snippetsparser.h>
|
||||
#include <texteditor/snippets/snippetprovider.h>
|
||||
#include <QtCore/QDateTime>
|
||||
#include <QtCore/QPointer>
|
||||
|
||||
@@ -97,7 +97,7 @@ private:
|
||||
TextEditor::ITextEditable *m_editor;
|
||||
int m_startPosition;
|
||||
bool m_restartCompletion;
|
||||
TextEditor::SnippetsParser m_snippetsParser;
|
||||
TextEditor::SnippetProvider m_snippetProvider;
|
||||
QList<TextEditor::CompletionItem> m_completions;
|
||||
QPointer<FunctionArgumentWidget> m_functionArgumentWidget;
|
||||
};
|
||||
|
||||
@@ -1187,27 +1187,7 @@ void QmlJSTextEditor::setFontSettings(const TextEditor::FontSettings &fs)
|
||||
if (!highlighter)
|
||||
return;
|
||||
|
||||
/*
|
||||
NumberFormat,
|
||||
StringFormat,
|
||||
TypeFormat,
|
||||
KeywordFormat,
|
||||
LabelFormat,
|
||||
CommentFormat,
|
||||
VisualWhitespace,
|
||||
*/
|
||||
static QVector<QString> categories;
|
||||
if (categories.isEmpty()) {
|
||||
categories << QLatin1String(TextEditor::Constants::C_NUMBER)
|
||||
<< QLatin1String(TextEditor::Constants::C_STRING)
|
||||
<< QLatin1String(TextEditor::Constants::C_TYPE)
|
||||
<< QLatin1String(TextEditor::Constants::C_KEYWORD)
|
||||
<< QLatin1String(TextEditor::Constants::C_FIELD)
|
||||
<< QLatin1String(TextEditor::Constants::C_COMMENT)
|
||||
<< QLatin1String(TextEditor::Constants::C_VISUAL_WHITESPACE);
|
||||
}
|
||||
|
||||
highlighter->setFormats(fs.toTextCharFormats(categories));
|
||||
highlighter->setFormats(fs.toTextCharFormats(highlighterFormatCategories()));
|
||||
highlighter->rehighlight();
|
||||
|
||||
m_occurrencesFormat = fs.toTextCharFormat(QLatin1String(TextEditor::Constants::C_OCCURRENCES));
|
||||
@@ -1571,6 +1551,30 @@ bool QmlJSTextEditor::hideContextPane()
|
||||
return b;
|
||||
}
|
||||
|
||||
QVector<QString> QmlJSTextEditor::highlighterFormatCategories()
|
||||
{
|
||||
/*
|
||||
NumberFormat,
|
||||
StringFormat,
|
||||
TypeFormat,
|
||||
KeywordFormat,
|
||||
LabelFormat,
|
||||
CommentFormat,
|
||||
VisualWhitespace,
|
||||
*/
|
||||
static QVector<QString> categories;
|
||||
if (categories.isEmpty()) {
|
||||
categories << QLatin1String(TextEditor::Constants::C_NUMBER)
|
||||
<< QLatin1String(TextEditor::Constants::C_STRING)
|
||||
<< QLatin1String(TextEditor::Constants::C_TYPE)
|
||||
<< QLatin1String(TextEditor::Constants::C_KEYWORD)
|
||||
<< QLatin1String(TextEditor::Constants::C_FIELD)
|
||||
<< QLatin1String(TextEditor::Constants::C_COMMENT)
|
||||
<< QLatin1String(TextEditor::Constants::C_VISUAL_WHITESPACE);
|
||||
}
|
||||
return categories;
|
||||
}
|
||||
|
||||
SemanticHighlighterSource QmlJSTextEditor::currentSource(bool force)
|
||||
{
|
||||
int line = 0, column = 0;
|
||||
|
||||
@@ -155,6 +155,8 @@ public:
|
||||
|
||||
void renameId(const QString &oldId, const QString &newId);
|
||||
|
||||
static QVector<QString> highlighterFormatCategories();
|
||||
|
||||
public slots:
|
||||
void followSymbolUnderCursor();
|
||||
void findUsages();
|
||||
|
||||
@@ -34,7 +34,8 @@ HEADERS += \
|
||||
qmljssemantichighlighter.h \
|
||||
qmljsindenter.h \
|
||||
qmljsautocompleter.h \
|
||||
jsfilewizard.h
|
||||
jsfilewizard.h \
|
||||
qmljssnippeteditordecorator.h
|
||||
|
||||
SOURCES += \
|
||||
qmljscodecompletion.cpp \
|
||||
@@ -62,7 +63,8 @@ SOURCES += \
|
||||
qmljssemantichighlighter.cpp \
|
||||
qmljsindenter.cpp \
|
||||
qmljsautocompleter.cpp \
|
||||
jsfilewizard.cpp
|
||||
jsfilewizard.cpp \
|
||||
qmljssnippeteditordecorator.cpp
|
||||
|
||||
RESOURCES += qmljseditor.qrc
|
||||
OTHER_FILES += QmlJSEditor.mimetypes.xml
|
||||
|
||||
@@ -39,6 +39,7 @@
|
||||
#include "qmljsoutline.h"
|
||||
#include "qmljspreviewrunner.h"
|
||||
#include "qmljsquickfix.h"
|
||||
#include "qmljssnippeteditordecorator.h"
|
||||
#include "qmltaskmanager.h"
|
||||
#include "quicktoolbar.h"
|
||||
#include "quicktoolbarsettingspage.h"
|
||||
@@ -128,6 +129,7 @@ bool QmlJSEditorPlugin::initialize(const QStringList & /*arguments*/, QString *e
|
||||
return false;
|
||||
|
||||
m_modelManager = QmlJS::ModelManagerInterface::instance();
|
||||
addAutoReleasedObject(new QmlJSSnippetEditorDecorator);
|
||||
|
||||
Core::Context context(QmlJSEditor::Constants::C_QMLJSEDITOR_ID);
|
||||
|
||||
|
||||
62
src/plugins/qmljseditor/qmljssnippeteditordecorator.cpp
Normal file
62
src/plugins/qmljseditor/qmljssnippeteditordecorator.cpp
Normal file
@@ -0,0 +1,62 @@
|
||||
/**************************************************************************
|
||||
**
|
||||
** 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 "qmljssnippeteditordecorator.h"
|
||||
#include "qmljshighlighter.h"
|
||||
#include "qmljseditor.h"
|
||||
|
||||
#include <texteditor/texteditorsettings.h>
|
||||
#include <texteditor/fontsettings.h>
|
||||
#include <texteditor/texteditorconstants.h>
|
||||
#include <texteditor/snippets/snippeteditor.h>
|
||||
|
||||
using namespace QmlJSEditor;
|
||||
using namespace Internal;
|
||||
|
||||
QmlJSSnippetEditorDecorator::QmlJSSnippetEditorDecorator() :
|
||||
TextEditor::ISnippetEditorDecorator()
|
||||
{}
|
||||
|
||||
QmlJSSnippetEditorDecorator::~QmlJSSnippetEditorDecorator()
|
||||
{}
|
||||
|
||||
bool QmlJSSnippetEditorDecorator::supports(TextEditor::Snippet::Group group) const
|
||||
{
|
||||
if (group == TextEditor::Snippet::Qml)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
void QmlJSSnippetEditorDecorator::apply(TextEditor::SnippetEditor *editor) const
|
||||
{
|
||||
Highlighter *highlighter = new Highlighter;
|
||||
const TextEditor::FontSettings &fs = TextEditor::TextEditorSettings::instance()->fontSettings();
|
||||
highlighter->setFormats(fs.toTextCharFormats(QmlJSTextEditor::highlighterFormatCategories()));
|
||||
editor->installSyntaxHighlighter(highlighter);
|
||||
}
|
||||
52
src/plugins/qmljseditor/qmljssnippeteditordecorator.h
Normal file
52
src/plugins/qmljseditor/qmljssnippeteditordecorator.h
Normal file
@@ -0,0 +1,52 @@
|
||||
/**************************************************************************
|
||||
**
|
||||
** 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 QMLJSSNIPPETEDITORDECORATOR_H
|
||||
#define QMLJSSNIPPETEDITORDECORATOR_H
|
||||
|
||||
#include <texteditor/snippets/isnippeteditordecorator.h>
|
||||
|
||||
namespace QmlJSEditor {
|
||||
namespace Internal {
|
||||
|
||||
class QmlJSSnippetEditorDecorator : public TextEditor::ISnippetEditorDecorator
|
||||
{
|
||||
public:
|
||||
QmlJSSnippetEditorDecorator();
|
||||
virtual ~QmlJSSnippetEditorDecorator();
|
||||
|
||||
public:
|
||||
virtual bool supports(TextEditor::Snippet::Group group) const;
|
||||
virtual void apply(TextEditor::SnippetEditor *editor) const;
|
||||
};
|
||||
|
||||
} // Internal
|
||||
} // QmlJSEditor
|
||||
|
||||
#endif // QMLJSSNIPPETEDITORDECORATOR_H
|
||||
Reference in New Issue
Block a user