1
/* This file is part of the Kate project.
2
* Based on the snippet plugin from KDevelop 4.
4
* Copyright (C) 2007 Robert Gruber <rgruber@users.sourceforge.net>
5
* Copyright (C) 2010 Milian Wolff <mail@milianw.de>
6
* Copyright (C) 2012 Christoph Cullmann <cullmann@kde.org>
8
* This library is free software; you can redistribute it and/or
9
* modify it under the terms of the GNU Library General Public
10
* License as published by the Free Software Foundation; either
11
* version 2 of the License, or (at your option) any later version.
13
* This library is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
* Library General Public License for more details.
18
* You should have received a copy of the GNU Library General Public License
19
* along with this library; see the file COPYING.LIB. If not, write to
20
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21
* Boston, MA 02110-1301, USA.
24
#ifndef __SNIPPETREPOSITORY_H__
25
#define __SNIPPETREPOSITORY_H__
28
#include <QStandardItem>
29
#include <QStringList>
39
* Each object of this type represents a repository of snippets. Each repository
40
* has a name and will be saved to an XML file that includes all items of this repository.
42
* To access the snippets in this repo, iterate over it's children and dynamic_cast as required.
43
* To add a snippet, @p appendRow() it.
44
* To access the name of the repository, use @p text() and @p setText().
46
* NOTE: Unchecked repositores are considered "disabled" in the sense that their snippets
47
* won't show up during code completion.
49
* @author Robert Gruber <rgruber@users.sourceforge.net>
50
* @author Milian Wolff <mail@milianw.de>
52
class SnippetRepository : public QObject, public QStandardItem
58
* Creates a new SnippetRepository. When @p file exists it will be parsed (XML).
60
* @param file Location of the snippet's repository file.
62
SnippetRepository(const QString& file);
66
* Creates a snippet repository for the given name and adds it to the SnippetStore.
68
static SnippetRepository* createRepoFromName(const QString& name);
71
* The license for the snippets contained in this repository.
73
QString license() const;
75
* Sets the license for the snippets contained in this repository.
77
void setLicense(const QString& license);
80
* The author(s) of the snippets contained in this repository.
82
QString authors() const;
84
* Sets the author(s) of the snippets contained in this repository.
86
void setAuthors(const QString& authors);
89
* The valid filetypes for the snippets contained in this repository.
90
* Empty list means no restriction on the modes.
91
* @see KTextEditor::Document::mode()
93
QStringList fileTypes() const;
95
* Sets the valid filetypes for the snippets contained in this repository.
96
* An empty list, or any list which contains an element "*" is treated as
97
* a no-restriction filter.
99
void setFileTypes(const QStringList& filetypes);
102
* The path to this repository's file.
104
const QString& file() const;
107
* The namespace associated with this repository.
108
* Used in CodeCompletion for filtering.
110
QString completionNamespace() const;
112
* Sets the code completion namespace for this repository.
114
void setCompletionNamespace(const QString& completionNamespace);
117
* The QtScript(s) associated with this repository.
121
QString script() const;
123
* The token identifying the script in this repository.
125
KTextEditor::TemplateScript* registeredScript() const;
127
* Sets the QtScript(s) associated with this repository.
131
void setScript(const QString& script);
134
* Remove this repository from the disk. Also deletes the item and all its children.
139
* Save this repository to disk.
143
virtual QVariant data(int role = Qt::UserRole + 1) const;
144
virtual void setData(const QVariant& value, int role = Qt::UserRole + 1);
147
/// parses the XML file and load the containing snippets.
148
void slotParseFile();
151
/// path to the repository file
153
/// license of the snippets in this repo
155
/// author(s) of the snippets in this repo
157
/// valid filetypes for the snippets in this repo
158
QStringList m_filetypes;
159
/// filtering namespace for code completion
161
/// QtScript with functions to be used in the snippet
163
/// registered script
164
KTextEditor::TemplateScript* m_registeredScript;