diff --git a/src/plugins/texteditor/snippets/snippetcollector.cpp b/src/plugins/texteditor/snippets/snippetcollector.cpp index 0a875ca4f47844f117e36b79550089d00b0e2e9f..cfe08cd5d48c62e2e04958270477186e37ed675f 100644 --- a/src/plugins/texteditor/snippets/snippetcollector.cpp +++ b/src/plugins/texteditor/snippets/snippetcollector.cpp @@ -28,7 +28,6 @@ **************************************************************************/ #include "snippetcollector.h" -#include "snippetsmanager.h" #include "snippetscollection.h" #include <texteditor/texteditorconstants.h> @@ -44,8 +43,7 @@ void appendSnippets(ICompletionCollector *collector, const QIcon &icon, int order) { - QSharedPointer<SnippetsCollection> collection = - SnippetsManager::instance()->snippetsCollection(); + SnippetsCollection *collection = SnippetsCollection::instance(); const int size = collection->totalActiveSnippets(groupId); for (int i = 0; i < size; ++i) { const Snippet &snippet = collection->snippet(i, groupId); diff --git a/src/plugins/texteditor/snippets/snippetscollection.cpp b/src/plugins/texteditor/snippets/snippetscollection.cpp index 72fa6086efd830ae6d08f78475c9d360a61a8001..fcdb098e11bebcdaf7f0d5d28220c0878531378b 100644 --- a/src/plugins/texteditor/snippets/snippetscollection.cpp +++ b/src/plugins/texteditor/snippets/snippetscollection.cpp @@ -98,6 +98,12 @@ int SnippetsCollection::Hint::index() const return m_index; } +SnippetsCollection *SnippetsCollection::instance() +{ + static SnippetsCollection collection; + return &collection; +} + // SnippetsCollection SnippetsCollection::SnippetsCollection() : m_userSnippetsPath(Core::ICore::instance()->userResourcePath() + QLatin1String("/snippets/")), diff --git a/src/plugins/texteditor/snippets/snippetscollection.h b/src/plugins/texteditor/snippets/snippetscollection.h index 97a122dc646da8146abf00842014c01df663557b..309ce8a2fbdb84a736b30140f621d4bf5aa711f1 100644 --- a/src/plugins/texteditor/snippets/snippetscollection.h +++ b/src/plugins/texteditor/snippets/snippetscollection.h @@ -54,8 +54,9 @@ class SnippetsCollection : public QObject { Q_OBJECT public: - SnippetsCollection(); - ~SnippetsCollection(); + virtual ~SnippetsCollection(); + + static SnippetsCollection *instance(); class Hint { @@ -100,6 +101,9 @@ private slots: void identifyGroups(); private: + SnippetsCollection(); + Q_DISABLE_COPY(SnippetsCollection) + int groupIndex(const QString &groupId) const; bool isGroupKnown(const QString &groupId) const; @@ -123,7 +127,8 @@ private: static const QLatin1String kModified; // Built-in snippets are specified in XMLs distributed in a system's folder. Snippets - // created or modified/removed (if they are built-ins) by the user are stored in another + // created or modified/removed (if they are built-ins) by the user are stored in user's + // folder. QString m_userSnippetsPath; QString m_userSnippetsFile; QStringList m_builtInSnippetsFiles; diff --git a/src/plugins/texteditor/snippets/snippetsmanager.cpp b/src/plugins/texteditor/snippets/snippetsmanager.cpp deleted file mode 100644 index 9494335e3a34281258bed48f331d63213ca43358..0000000000000000000000000000000000000000 --- a/src/plugins/texteditor/snippets/snippetsmanager.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/************************************************************************** -** -** 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 "snippetsmanager.h" -#include "snippetscollection.h" - -using namespace TextEditor; -using namespace Internal; - -SnippetsManager::SnippetsManager() : - m_collection(new SnippetsCollection) -{ - m_collection->reload(); -} - -SnippetsManager::~SnippetsManager() -{} - -SnippetsManager *SnippetsManager::instance() -{ - static SnippetsManager manager; - return &manager; -} - -QSharedPointer<SnippetsCollection> SnippetsManager::snippetsCollection() const -{ - return m_collection; -} diff --git a/src/plugins/texteditor/snippets/snippetsmanager.h b/src/plugins/texteditor/snippets/snippetsmanager.h deleted file mode 100644 index 131377948f2d80ce33497a8a8fa16f2654cf9f7a..0000000000000000000000000000000000000000 --- a/src/plugins/texteditor/snippets/snippetsmanager.h +++ /dev/null @@ -1,63 +0,0 @@ -/************************************************************************** -** -** 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 SNIPPETSMANAGER_H -#define SNIPPETSMANAGER_H - -#include <QtCore/QSharedPointer> - -namespace TextEditor { - -class ISnippetProvider; - -namespace Internal { - -class SnippetsCollection; - -class SnippetsManager -{ -private: - SnippetsManager(); - Q_DISABLE_COPY(SnippetsManager) - -public: - ~SnippetsManager(); - - static SnippetsManager *instance(); - - QSharedPointer<SnippetsCollection> snippetsCollection() const; - -private: - QSharedPointer<SnippetsCollection> m_collection; -}; - -} // Internal -} // TextEditor - -#endif // SNIPPETSMANAGER_H diff --git a/src/plugins/texteditor/snippets/snippetssettingspage.cpp b/src/plugins/texteditor/snippets/snippetssettingspage.cpp index 1e51b61ce4f3e2c9e4e2275403fe6bbc02322403..ddb151464c0e93a73042646a44997ffce2fbcea0 100644 --- a/src/plugins/texteditor/snippets/snippetssettingspage.cpp +++ b/src/plugins/texteditor/snippets/snippetssettingspage.cpp @@ -28,7 +28,6 @@ **************************************************************************/ #include "snippetssettingspage.h" -#include "snippetsmanager.h" #include "snippeteditor.h" #include "isnippetprovider.h" #include "snippet.h" @@ -40,7 +39,6 @@ #include <coreplugin/icore.h> #include <extensionsystem/pluginmanager.h> -#include <QtCore/QSharedPointer> #include <QtCore/QModelIndex> #include <QtCore/QAbstractTableModel> #include <QtCore/QList> @@ -85,26 +83,22 @@ private: void replaceSnippet(const Snippet &snippet, const QModelIndex &modelIndex); static bool isValidTrigger(const QString &s); - QSharedPointer<SnippetsCollection> m_collection; + SnippetsCollection* m_collection; QString m_activeGroupId; }; SnippetsTableModel::SnippetsTableModel(QObject *parent) : QAbstractTableModel(parent), - m_collection(SnippetsManager::instance()->snippetsCollection()) + m_collection(SnippetsCollection::instance()) {} int SnippetsTableModel::rowCount(const QModelIndex &) const { - if (m_collection.isNull()) - return 0; return m_collection->totalActiveSnippets(m_activeGroupId); } int SnippetsTableModel::columnCount(const QModelIndex &) const { - if (m_collection.isNull()) - return 0; return 2; } @@ -390,7 +384,7 @@ void SnippetsSettingsPagePrivate::apply() writeSettings(); if (m_snippetsCollectionChanged) { - SnippetsManager::instance()->snippetsCollection()->synchronize(); + SnippetsCollection::instance()->synchronize(); m_snippetsCollectionChanged = false; } } @@ -398,7 +392,7 @@ void SnippetsSettingsPagePrivate::apply() void SnippetsSettingsPagePrivate::finish() { if (m_snippetsCollectionChanged) { - SnippetsManager::instance()->snippetsCollection()->reload(); + SnippetsCollection::instance()->reload(); m_snippetsCollectionChanged = false; } } diff --git a/src/plugins/texteditor/texteditor.pro b/src/plugins/texteditor/texteditor.pro index bbf384a767e55a028dc04de8f07524f62d00d6dc..70b93fc195a8d5d4ec1f0272f0c333a1a3a76f5a 100644 --- a/src/plugins/texteditor/texteditor.pro +++ b/src/plugins/texteditor/texteditor.pro @@ -75,7 +75,6 @@ SOURCES += texteditorplugin.cpp \ autocompleter.cpp \ snippets/snippetssettingspage.cpp \ snippets/snippet.cpp \ - snippets/snippetsmanager.cpp \ snippets/snippeteditor.cpp \ snippets/snippetscollection.cpp \ snippets/snippetssettings.cpp \ @@ -158,7 +157,6 @@ HEADERS += texteditorplugin.h \ autocompleter.h \ snippets/snippetssettingspage.h \ snippets/snippet.h \ - snippets/snippetsmanager.h \ snippets/snippeteditor.h \ snippets/snippetscollection.h \ snippets/reuse.h \