forked from qt-creator/qt-creator
Snippets: Remove the snippets manager
Let the collection itself be the singleton.
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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/")),
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user