Commit 9443f710 authored by Eike Ziller's avatar Eike Ziller

Remove the need to create ISnippetProvider subclasses

Change-Id: I1810aaa945136d9726a66dad41377429a6adc8e1
Reviewed-by: David Schulz's avatarDavid Schulz <david.schulz@qt.io>
parent 46b77013
......@@ -20,7 +20,6 @@ HEADERS = builddirmanager.h \
cmaketool.h \
cmakeparser.h \
cmakesettingspage.h \
cmakesnippetprovider.h \
cmaketoolmanager.h \
cmake_global.h \
cmakekitinformation.h \
......@@ -53,7 +52,6 @@ SOURCES = builddirmanager.cpp \
cmaketool.cpp \
cmakeparser.cpp \
cmakesettingspage.cpp \
cmakesnippetprovider.cpp \
cmaketoolmanager.cpp \
cmakekitinformation.cpp \
cmakekitconfigwidget.cpp \
......
......@@ -66,8 +66,6 @@ QtcPlugin {
"cmaketoolmanager.h",
"cmakesettingspage.h",
"cmakesettingspage.cpp",
"cmakesnippetprovider.cpp",
"cmakesnippetprovider.h",
"cmakeindenter.h",
"cmakeindenter.cpp",
"cmakeautocompleter.h",
......
......@@ -33,7 +33,6 @@
#include "cmakeprojectnodes.h"
#include "cmakebuildconfiguration.h"
#include "cmakerunconfiguration.h"
#include "cmakesnippetprovider.h"
#include "cmakeprojectconstants.h"
#include "cmakelocatorfilter.h"
#include "cmakesettingspage.h"
......@@ -48,6 +47,8 @@
#include <projectexplorer/projectmanager.h>
#include <projectexplorer/projecttree.h>
#include <texteditor/snippets/snippetprovider.h>
#include <utils/parameteraction.h>
using namespace CMakeProjectManager::Internal;
......@@ -62,7 +63,8 @@ bool CMakeProjectPlugin::initialize(const QStringList & /*arguments*/, QString *
Core::FileIconProvider::registerIconOverlayForSuffix(Constants::FILEOVERLAY_CMAKE, "cmake");
Core::FileIconProvider::registerIconOverlayForFilename(Constants::FILEOVERLAY_CMAKE, "CMakeLists.txt");
addAutoReleasedObject(new Internal::CMakeSnippetProvider);
TextEditor::SnippetProvider::registerGroup(Constants::CMAKE_SNIPPETS_GROUP_ID,
tr("CMake", "SnippetProvider"));
addAutoReleasedObject(new CMakeSettingsPage);
addAutoReleasedObject(new CMakeManager);
......
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#include "cmakesnippetprovider.h"
#include "cmakeprojectconstants.h"
#include "cmakeeditor.h"
#include <texteditor/snippets/snippeteditor.h>
namespace CMakeProjectManager {
namespace Internal {
CMakeSnippetProvider::~CMakeSnippetProvider() = default;
QString CMakeSnippetProvider::groupId() const
{
return QLatin1String(Constants::CMAKE_SNIPPETS_GROUP_ID);
}
QString CMakeSnippetProvider::displayName() const
{
return tr("CMake");
}
void CMakeSnippetProvider::decorateEditor(TextEditor::SnippetEditorWidget *editor) const
{
Q_UNUSED(editor);
// What needs to go here?
}
} // namespace Internal
} // namespace CMakeProjectManager
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#pragma once
#include <texteditor/snippets/isnippetprovider.h>
namespace CMakeProjectManager {
namespace Internal {
class CMakeSnippetProvider : public TextEditor::ISnippetProvider
{
Q_OBJECT
public:
~CMakeSnippetProvider() final;
QString groupId() const final;
QString displayName() const final;
void decorateEditor(TextEditor::SnippetEditorWidget *editor) const final;
};
} // namespace Internal
} // namespace CMakeProjectManager
......@@ -52,6 +52,7 @@
#include <cpptools/cppcompletionassistprovider.h>
#include <cpptools/cppeditoroutline.h>
#include <cpptools/cppmodelmanager.h>
#include <cpptools/cppqtstyleindenter.h>
#include <cpptools/cppselectionchanger.h>
#include <cpptools/cppsemanticinfo.h>
#include <cpptools/cpptoolsconstants.h>
......@@ -107,6 +108,13 @@ CppEditor::CppEditor()
addContext(ProjectExplorer::Constants::CXX_LANGUAGE_ID);
}
void CppEditor::decorateEditor(TextEditorWidget *editor)
{
editor->textDocument()->setSyntaxHighlighter(new CppHighlighter);
editor->textDocument()->setIndenter(new CppTools::CppQtStyleIndenter);
editor->setAutoCompleter(new CppAutoCompleter);
}
class CppEditorWidgetPrivate
{
public:
......
......@@ -53,6 +53,9 @@ class CppEditor : public TextEditor::BaseTextEditor
public:
CppEditor();
static void decorateEditor(TextEditor::TextEditorWidget *editor);
};
class CppEditorWidget : public TextEditor::TextEditorWidget
......
......@@ -27,7 +27,6 @@ HEADERS += \
cppquickfix.h \
cppquickfixassistant.h \
cppquickfixes.h \
cppsnippetprovider.h \
cpptypehierarchy.h \
cppuseselectionsupdater.h \
cppvirtualfunctionassistprovider.h \
......@@ -57,7 +56,6 @@ SOURCES += \
cppquickfix.cpp \
cppquickfixassistant.cpp \
cppquickfixes.cpp \
cppsnippetprovider.cpp \
cpptypehierarchy.cpp \
cppuseselectionsupdater.cpp \
cppvirtualfunctionassistprovider.cpp \
......
......@@ -70,8 +70,6 @@ QtcPlugin {
"cppquickfixassistant.h",
"cppquickfixes.cpp",
"cppquickfixes.h",
"cppsnippetprovider.cpp",
"cppsnippetprovider.h",
"cpptypehierarchy.cpp",
"cpptypehierarchy.h",
"cppuseselectionsupdater.cpp",
......
......@@ -36,7 +36,6 @@
#include "cppoutline.h"
#include "cppquickfixassistant.h"
#include "cppquickfixes.h"
#include "cppsnippetprovider.h"
#include "cpptypehierarchy.h"
#include "resourcepreviewhoverhandler.h"
......@@ -58,6 +57,7 @@
#include <texteditor/texteditoractionhandler.h>
#include <texteditor/texteditorconstants.h>
#include <texteditor/colorpreviewhoverhandler.h>
#include <texteditor/snippets/snippetprovider.h>
#include <utils/hostosinfo.h>
#include <utils/mimetypes/mimedatabase.h>
......@@ -149,7 +149,8 @@ bool CppEditorPlugin::initialize(const QStringList & /*arguments*/, QString *err
addAutoReleasedObject(new CppOutlineWidgetFactory);
addAutoReleasedObject(new CppTypeHierarchyFactory);
addAutoReleasedObject(new CppIncludeHierarchyFactory);
addAutoReleasedObject(new CppSnippetProvider);
SnippetProvider::registerGroup(Constants::CPP_SNIPPETS_GROUP_ID, tr("C++", "SnippetProvider"),
&CppEditor::decorateEditor);
m_quickFixProvider = new CppQuickFixAssistProvider(this);
registerQuickFixes(this);
......
......@@ -26,8 +26,8 @@
#include "cpppreprocessordialog.h"
#include "ui_cpppreprocessordialog.h"
#include "cppeditor.h"
#include "cppeditorconstants.h"
#include "cppsnippetprovider.h"
#include <projectexplorer/session.h>
......@@ -44,7 +44,7 @@ CppPreProcessorDialog::CppPreProcessorDialog(const QString &filePath, QWidget *p
m_ui->editorLabel->setText(m_ui->editorLabel->text().arg(Utils::FileName::fromString(m_filePath).fileName()));
m_ui->editWidget->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
CppSnippetProvider().decorateEditor(m_ui->editWidget);
CppEditor::decorateEditor(m_ui->editWidget);
const QString key = Constants::EXTRA_PREPROCESSOR_DIRECTIVES + m_filePath;
const QString directives = ProjectExplorer::SessionManager::value(key).toString();
......
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#include "cppsnippetprovider.h"
#include "cpphighlighter.h"
#include "cppautocompleter.h"
#include "cppeditorconstants.h"
#include <cpptools/cppqtstyleindenter.h>
#include <texteditor/snippets/snippeteditor.h>
#include <texteditor/textdocument.h>
#include <QLatin1String>
#include <QCoreApplication>
using namespace CppEditor;
using namespace CppEditor::Internal;
QString CppSnippetProvider::groupId() const
{
return QLatin1String(Constants::CPP_SNIPPETS_GROUP_ID);
}
QString CppSnippetProvider::displayName() const
{
return QCoreApplication::translate("CppEditor::Internal::CppSnippetProvider", "C++");
}
void CppSnippetProvider::decorateEditor(TextEditor::SnippetEditorWidget *editor) const
{
editor->textDocument()->setSyntaxHighlighter(new CppHighlighter);
editor->textDocument()->setIndenter(new CppTools::CppQtStyleIndenter);
editor->setAutoCompleter(new CppAutoCompleter);
}
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#pragma once
#include <texteditor/snippets/isnippetprovider.h>
namespace CppEditor {
namespace Internal {
class CppSnippetProvider : public TextEditor::ISnippetProvider
{
Q_OBJECT
public:
~CppSnippetProvider() final = default;
QString groupId() const final;
QString displayName() const final;
void decorateEditor(TextEditor::SnippetEditorWidget *editor) const final;
};
} // Internal
} // CppEditor
......@@ -31,7 +31,7 @@
#include "cppqtstyleindenter.h"
#include <cppeditor/cppeditorconstants.h>
#include <texteditor/snippets/isnippetprovider.h>
#include <texteditor/snippets/snippetprovider.h>
#include <extensionsystem/pluginmanager.h>
......@@ -121,10 +121,10 @@ TextEditor::Indenter *CppCodeStylePreferencesFactory::createIndenter() const
return new CppQtStyleIndenter();
}
TextEditor::ISnippetProvider *CppCodeStylePreferencesFactory::snippetProvider() const
TextEditor::SnippetProvider *CppCodeStylePreferencesFactory::snippetProvider() const
{
return ExtensionSystem::PluginManager::getObject<TextEditor::ISnippetProvider>(
[](TextEditor::ISnippetProvider *provider) {
return ExtensionSystem::PluginManager::getObject<TextEditor::SnippetProvider>(
[](TextEditor::SnippetProvider *provider) {
return provider->groupId() == QLatin1String(CppEditor::Constants::CPP_SNIPPETS_GROUP_ID);
});
}
......
......@@ -40,7 +40,7 @@ public:
QWidget *createEditor(TextEditor::ICodeStylePreferences *settings,
QWidget *parent) const;
TextEditor::Indenter *createIndenter() const;
TextEditor::ISnippetProvider *snippetProvider() const;
TextEditor::SnippetProvider *snippetProvider() const;
QString previewText() const;
};
......
......@@ -37,7 +37,7 @@
#include <texteditor/codestyleeditor.h>
#include <texteditor/textdocument.h>
#include <texteditor/displaysettings.h>
#include <texteditor/snippets/isnippetprovider.h>
#include <texteditor/snippets/snippetprovider.h>
#include <texteditor/texteditorsettings.h>
#include <cplusplus/Overview.h>
......@@ -493,8 +493,8 @@ void CppCodeStylePreferencesWidget::updatePreview()
void CppCodeStylePreferencesWidget::decorateEditors(const FontSettings &fontSettings)
{
const ISnippetProvider *provider = ExtensionSystem::PluginManager::getObject<ISnippetProvider>(
[](ISnippetProvider *current) {
const SnippetProvider *provider = ExtensionSystem::PluginManager::getObject<SnippetProvider>(
[](SnippetProvider *current) {
return current->groupId() == QLatin1String(CppEditor::Constants::CPP_SNIPPETS_GROUP_ID);
});
......
......@@ -77,4 +77,10 @@ Core::IEditor *NimEditorFactory::createEditor()
return TextEditorFactory::createEditor();
}
void NimEditorFactory::decorateEditor(TextEditorWidget *editor)
{
editor->textDocument()->setSyntaxHighlighter(new NimHighlighter());
editor->textDocument()->setIndenter(new NimIndenter());
}
}
......@@ -37,6 +37,7 @@ public:
NimEditorFactory();
Core::IEditor *createEditor() override;
static void decorateEditor(TextEditor::TextEditorWidget *editor);
};
}
......@@ -34,7 +34,6 @@ HEADERS += \
settings/nimcodestylesettingspage.h \
settings/nimcodestylepreferencesfactory.h \
settings/nimsettings.h \
settings/nimsnippetprovider.h \
settings/nimcodestylepreferenceswidget.h \
project/nimtoolchain.h \
project/nimtoolchainfactory.h
......@@ -63,7 +62,6 @@ SOURCES += \
settings/nimcodestylesettingspage.cpp \
settings/nimcodestylepreferencesfactory.cpp \
settings/nimsettings.cpp \
settings/nimsnippetprovider.cpp \
settings/nimcodestylepreferenceswidget.cpp \
project/nimtoolchain.cpp \
project/nimtoolchainfactory.cpp
......
......@@ -63,7 +63,6 @@ QtcPlugin {
"nimcodestylepreferenceswidget.h", "nimcodestylepreferenceswidget.cpp", "nimcodestylepreferenceswidget.ui",
"nimcodestylesettingspage.h", "nimcodestylesettingspage.cpp",
"nimsettings.h", "nimsettings.cpp",
"nimsnippetprovider.h", "nimsnippetprovider.cpp",
]
}
......
......@@ -90,7 +90,6 @@ const char C_NIMCODESTYLESETTINGSPAGE_CATEGORY_DISPLAY[] = QT_TRANSLATE_NOOP("Ni
const char C_NIMLANGUAGE_NAME[] = QT_TRANSLATE_NOOP("NimCodeStylePreferencesFactory", "Nim");
const char C_NIMGLOBALCODESTYLE_ID[] = "NimGlobal";
const QString C_NIMSNIPPETSGROUP_ID = QStringLiteral("Nim.NimSnippetsGroup");
const char C_NIMSNIPPETPROVIDER_DISPLAY[] = QT_TRANSLATE_NOOP("NimSnippetProvider", "Nim");
const char C_NIMCODESTYLEPREVIEWSNIPPET[] =
"import os\n"
......
......@@ -38,11 +38,11 @@
#include "settings/nimcodestylepreferencesfactory.h"
#include "settings/nimcodestylesettingspage.h"
#include "settings/nimsettings.h"
#include "settings/nimsnippetprovider.h"
#include <coreplugin/fileiconprovider.h>
#include <projectexplorer/projectmanager.h>
#include <projectexplorer/toolchainmanager.h>
#include <texteditor/snippets/snippetprovider.h>
#include <QtPlugin>
......@@ -70,7 +70,6 @@ bool NimPlugin::initialize(const QStringList &arguments, QString *errorMessage)
ProjectExplorer::ToolChainManager::registerLanguage(Constants::C_NIMLANGUAGE_ID, Constants::C_NIMLANGUAGE_NAME);
addAutoReleasedObject(new NimSettings);
addAutoReleasedObject(new NimSnippetProvider);
addAutoReleasedObject(new NimEditorFactory);
addAutoReleasedObject(new NimBuildConfigurationFactory);
addAutoReleasedObject(new NimRunConfigurationFactory);
......@@ -80,6 +79,9 @@ bool NimPlugin::initialize(const QStringList &arguments, QString *errorMessage)
addAutoReleasedObject(new NimCodeStyleSettingsPage);
addAutoReleasedObject(new NimCodeStylePreferencesFactory);
addAutoReleasedObject(new NimToolChainFactory);
TextEditor::SnippetProvider::registerGroup(Constants::C_NIMSNIPPETSGROUP_ID,
tr("Nim", "SnippetProvider"),
&NimEditorFactory::decorateEditor);
ProjectExplorer::ProjectManager::registerProjectType<NimProject>(Constants::C_NIM_PROJECT_MIMETYPE);
......
......@@ -31,7 +31,7 @@
#include <coreplugin/id.h>
#include <texteditor/simplecodestylepreferences.h>
#include <texteditor/snippets/isnippetprovider.h>
#include <texteditor/snippets/snippetprovider.h>
#include <extensionsystem/pluginmanager.h>
#include <QWidget>
......@@ -71,10 +71,10 @@ TextEditor::Indenter *NimCodeStylePreferencesFactory::createIndenter() const
return new NimIndenter();
}
TextEditor::ISnippetProvider *NimCodeStylePreferencesFactory::snippetProvider() const
TextEditor::SnippetProvider *NimCodeStylePreferencesFactory::snippetProvider() const
{
return ExtensionSystem::PluginManager::getObject<TextEditor::ISnippetProvider>(
[](TextEditor::ISnippetProvider *provider) {
return ExtensionSystem::PluginManager::getObject<TextEditor::SnippetProvider>(
[](TextEditor::SnippetProvider *provider) {
return provider->groupId() == Nim::Constants::C_NIMSNIPPETSGROUP_ID;
});
}
......
......@@ -42,7 +42,7 @@ public:
QWidget *createEditor(TextEditor::ICodeStylePreferences *settings,
QWidget *parent) const;
TextEditor::Indenter *createIndenter() const;
TextEditor::ISnippetProvider *snippetProvider() const;
TextEditor::SnippetProvider *snippetProvider() const;
QString previewText() const;
};
......
......@@ -27,6 +27,7 @@
#include "ui_nimcodestylepreferenceswidget.h"
#include "../nimconstants.h"
#include "../editor/nimeditorfactory.h"
#include <extensionsystem/pluginmanager.h>
#include <texteditor/displaysettings.h>
......@@ -36,7 +37,7 @@
#include <texteditor/tabsettings.h>
#include <texteditor/textdocument.h>
#include <texteditor/texteditorsettings.h>
#include <texteditor/snippets/isnippetprovider.h>
#include <texteditor/snippets/snippetprovider.h>
using namespace TextEditor;
......@@ -51,14 +52,6 @@ NimCodeStylePreferencesWidget::NimCodeStylePreferencesWidget(ICodeStylePreferenc
m_ui->tabPreferencesWidget->setPreferences(preferences);
m_ui->previewTextEdit->setPlainText(Nim::Constants::C_NIMCODESTYLEPREVIEWSNIPPET);
ISnippetProvider *provider = ExtensionSystem::PluginManager::getObject<ISnippetProvider>(
[](ISnippetProvider *provider) {
return provider->groupId() == Nim::Constants::C_NIMSNIPPETSGROUP_ID;
});
if (provider)
provider->decorateEditor(m_ui->previewTextEdit);
decorateEditor(TextEditorSettings::fontSettings());
connect(TextEditorSettings::instance(), &TextEditorSettings::fontSettingsChanged,
this, &NimCodeStylePreferencesWidget::decorateEditor);
......@@ -79,14 +72,8 @@ NimCodeStylePreferencesWidget::~NimCodeStylePreferencesWidget()
void NimCodeStylePreferencesWidget::decorateEditor(const FontSettings &fontSettings)
{
const ISnippetProvider *provider = ExtensionSystem::PluginManager::getObject<ISnippetProvider>(
[](ISnippetProvider *current) {
return current->groupId() == Nim::Constants::C_NIMSNIPPETSGROUP_ID;
});
m_ui->previewTextEdit->textDocument()->setFontSettings(fontSettings);
if (provider)
provider->decorateEditor(m_ui->previewTextEdit);
NimEditorFactory::decorateEditor(m_ui->previewTextEdit);
}
void NimCodeStylePreferencesWidget::setVisualizeWhitespace(bool on)
......
/****************************************************************************
**
** Copyright (C) Filippo Cucchetto <filippocucchetto@gmail.com>
** Contact: http://www.qt.io/licensing
**
** This file is part of Qt Creator.
**