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 "snippetcollector.h"
|
||||||
#include "snippetsmanager.h"
|
|
||||||
#include "snippetscollection.h"
|
#include "snippetscollection.h"
|
||||||
|
|
||||||
#include <texteditor/texteditorconstants.h>
|
#include <texteditor/texteditorconstants.h>
|
||||||
@@ -44,8 +43,7 @@ void appendSnippets(ICompletionCollector *collector,
|
|||||||
const QIcon &icon,
|
const QIcon &icon,
|
||||||
int order)
|
int order)
|
||||||
{
|
{
|
||||||
QSharedPointer<SnippetsCollection> collection =
|
SnippetsCollection *collection = SnippetsCollection::instance();
|
||||||
SnippetsManager::instance()->snippetsCollection();
|
|
||||||
const int size = collection->totalActiveSnippets(groupId);
|
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, groupId);
|
const Snippet &snippet = collection->snippet(i, groupId);
|
||||||
|
|||||||
@@ -98,6 +98,12 @@ int SnippetsCollection::Hint::index() const
|
|||||||
return m_index;
|
return m_index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SnippetsCollection *SnippetsCollection::instance()
|
||||||
|
{
|
||||||
|
static SnippetsCollection collection;
|
||||||
|
return &collection;
|
||||||
|
}
|
||||||
|
|
||||||
// SnippetsCollection
|
// SnippetsCollection
|
||||||
SnippetsCollection::SnippetsCollection() :
|
SnippetsCollection::SnippetsCollection() :
|
||||||
m_userSnippetsPath(Core::ICore::instance()->userResourcePath() + QLatin1String("/snippets/")),
|
m_userSnippetsPath(Core::ICore::instance()->userResourcePath() + QLatin1String("/snippets/")),
|
||||||
|
|||||||
@@ -54,8 +54,9 @@ class SnippetsCollection : public QObject
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
SnippetsCollection();
|
virtual ~SnippetsCollection();
|
||||||
~SnippetsCollection();
|
|
||||||
|
static SnippetsCollection *instance();
|
||||||
|
|
||||||
class Hint
|
class Hint
|
||||||
{
|
{
|
||||||
@@ -100,6 +101,9 @@ private slots:
|
|||||||
void identifyGroups();
|
void identifyGroups();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
SnippetsCollection();
|
||||||
|
Q_DISABLE_COPY(SnippetsCollection)
|
||||||
|
|
||||||
int groupIndex(const QString &groupId) const;
|
int groupIndex(const QString &groupId) const;
|
||||||
bool isGroupKnown(const QString &groupId) const;
|
bool isGroupKnown(const QString &groupId) const;
|
||||||
|
|
||||||
@@ -123,7 +127,8 @@ private:
|
|||||||
static const QLatin1String kModified;
|
static const QLatin1String kModified;
|
||||||
|
|
||||||
// Built-in snippets are specified in XMLs distributed in a system's folder. Snippets
|
// 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_userSnippetsPath;
|
||||||
QString m_userSnippetsFile;
|
QString m_userSnippetsFile;
|
||||||
QStringList m_builtInSnippetsFiles;
|
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 "snippetssettingspage.h"
|
||||||
#include "snippetsmanager.h"
|
|
||||||
#include "snippeteditor.h"
|
#include "snippeteditor.h"
|
||||||
#include "isnippetprovider.h"
|
#include "isnippetprovider.h"
|
||||||
#include "snippet.h"
|
#include "snippet.h"
|
||||||
@@ -40,7 +39,6 @@
|
|||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
#include <extensionsystem/pluginmanager.h>
|
#include <extensionsystem/pluginmanager.h>
|
||||||
|
|
||||||
#include <QtCore/QSharedPointer>
|
|
||||||
#include <QtCore/QModelIndex>
|
#include <QtCore/QModelIndex>
|
||||||
#include <QtCore/QAbstractTableModel>
|
#include <QtCore/QAbstractTableModel>
|
||||||
#include <QtCore/QList>
|
#include <QtCore/QList>
|
||||||
@@ -85,26 +83,22 @@ 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);
|
||||||
|
|
||||||
QSharedPointer<SnippetsCollection> m_collection;
|
SnippetsCollection* m_collection;
|
||||||
QString m_activeGroupId;
|
QString m_activeGroupId;
|
||||||
};
|
};
|
||||||
|
|
||||||
SnippetsTableModel::SnippetsTableModel(QObject *parent) :
|
SnippetsTableModel::SnippetsTableModel(QObject *parent) :
|
||||||
QAbstractTableModel(parent),
|
QAbstractTableModel(parent),
|
||||||
m_collection(SnippetsManager::instance()->snippetsCollection())
|
m_collection(SnippetsCollection::instance())
|
||||||
{}
|
{}
|
||||||
|
|
||||||
int SnippetsTableModel::rowCount(const QModelIndex &) const
|
int SnippetsTableModel::rowCount(const QModelIndex &) const
|
||||||
{
|
{
|
||||||
if (m_collection.isNull())
|
|
||||||
return 0;
|
|
||||||
return m_collection->totalActiveSnippets(m_activeGroupId);
|
return m_collection->totalActiveSnippets(m_activeGroupId);
|
||||||
}
|
}
|
||||||
|
|
||||||
int SnippetsTableModel::columnCount(const QModelIndex &) const
|
int SnippetsTableModel::columnCount(const QModelIndex &) const
|
||||||
{
|
{
|
||||||
if (m_collection.isNull())
|
|
||||||
return 0;
|
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -390,7 +384,7 @@ void SnippetsSettingsPagePrivate::apply()
|
|||||||
writeSettings();
|
writeSettings();
|
||||||
|
|
||||||
if (m_snippetsCollectionChanged) {
|
if (m_snippetsCollectionChanged) {
|
||||||
SnippetsManager::instance()->snippetsCollection()->synchronize();
|
SnippetsCollection::instance()->synchronize();
|
||||||
m_snippetsCollectionChanged = false;
|
m_snippetsCollectionChanged = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -398,7 +392,7 @@ void SnippetsSettingsPagePrivate::apply()
|
|||||||
void SnippetsSettingsPagePrivate::finish()
|
void SnippetsSettingsPagePrivate::finish()
|
||||||
{
|
{
|
||||||
if (m_snippetsCollectionChanged) {
|
if (m_snippetsCollectionChanged) {
|
||||||
SnippetsManager::instance()->snippetsCollection()->reload();
|
SnippetsCollection::instance()->reload();
|
||||||
m_snippetsCollectionChanged = false;
|
m_snippetsCollectionChanged = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,7 +75,6 @@ SOURCES += texteditorplugin.cpp \
|
|||||||
autocompleter.cpp \
|
autocompleter.cpp \
|
||||||
snippets/snippetssettingspage.cpp \
|
snippets/snippetssettingspage.cpp \
|
||||||
snippets/snippet.cpp \
|
snippets/snippet.cpp \
|
||||||
snippets/snippetsmanager.cpp \
|
|
||||||
snippets/snippeteditor.cpp \
|
snippets/snippeteditor.cpp \
|
||||||
snippets/snippetscollection.cpp \
|
snippets/snippetscollection.cpp \
|
||||||
snippets/snippetssettings.cpp \
|
snippets/snippetssettings.cpp \
|
||||||
@@ -158,7 +157,6 @@ HEADERS += texteditorplugin.h \
|
|||||||
autocompleter.h \
|
autocompleter.h \
|
||||||
snippets/snippetssettingspage.h \
|
snippets/snippetssettingspage.h \
|
||||||
snippets/snippet.h \
|
snippets/snippet.h \
|
||||||
snippets/snippetsmanager.h \
|
|
||||||
snippets/snippeteditor.h \
|
snippets/snippeteditor.h \
|
||||||
snippets/snippetscollection.h \
|
snippets/snippetscollection.h \
|
||||||
snippets/reuse.h \
|
snippets/reuse.h \
|
||||||
|
|||||||
Reference in New Issue
Block a user