~ubuntu-branches/ubuntu/vivid/kate/vivid-updates

« back to all changes in this revision

Viewing changes to part/snippet/snippetrepository.h

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2014-12-04 16:49:41 UTC
  • mfrom: (1.6.6)
  • Revision ID: package-import@ubuntu.com-20141204164941-l3qbvsly83hhlw2v
Tags: 4:14.11.97-0ubuntu1
* New upstream release
* Update build-deps and use pkg-kde v3 for Qt 5 build
* kate-data now kate5-data for co-installability

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*  This file is part of the Kate project.
2
 
 *  Based on the snippet plugin from KDevelop 4.
3
 
 *
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>
7
 
 *
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.
12
 
 *
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.
17
 
 *
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.
22
 
 */
23
 
 
24
 
#ifndef __SNIPPETREPOSITORY_H__
25
 
#define __SNIPPETREPOSITORY_H__
26
 
 
27
 
#include <QObject>
28
 
#include <QStandardItem>
29
 
#include <QStringList>
30
 
 
31
 
class Snippet;
32
 
 
33
 
namespace KTextEditor
34
 
{
35
 
class TemplateScript;
36
 
}
37
 
 
38
 
/**
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.
41
 
 *
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().
45
 
 *
46
 
 * NOTE: Unchecked repositores are considered "disabled" in the sense that their snippets
47
 
 *       won't show up during code completion.
48
 
 *
49
 
 * @author Robert Gruber <rgruber@users.sourceforge.net>
50
 
 * @author Milian Wolff <mail@milianw.de>
51
 
 */
52
 
class SnippetRepository : public QObject, public QStandardItem
53
 
{
54
 
    Q_OBJECT
55
 
 
56
 
public:
57
 
    /**
58
 
     * Creates a new SnippetRepository. When @p file exists it will be parsed (XML).
59
 
     *
60
 
     * @param file Location of the snippet's repository file.
61
 
     */
62
 
    SnippetRepository(const QString& file);
63
 
    ~SnippetRepository();
64
 
 
65
 
    /**
66
 
     * Creates a snippet repository for the given name and adds it to the SnippetStore.
67
 
     */
68
 
    static SnippetRepository* createRepoFromName(const QString& name);
69
 
 
70
 
    /**
71
 
     * The license for the snippets contained in this repository.
72
 
     */
73
 
    QString license() const;
74
 
    /**
75
 
     * Sets the license for the snippets contained in this repository.
76
 
     */
77
 
    void setLicense(const QString& license);
78
 
 
79
 
    /**
80
 
     * The author(s) of the snippets contained in this repository.
81
 
     */
82
 
    QString authors() const;
83
 
    /**
84
 
     * Sets the author(s) of the snippets contained in this repository.
85
 
     */
86
 
    void setAuthors(const QString& authors);
87
 
 
88
 
    /**
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()
92
 
     */
93
 
    QStringList fileTypes() const;
94
 
    /**
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.
98
 
     */
99
 
    void setFileTypes(const QStringList& filetypes);
100
 
 
101
 
    /**
102
 
     * The path to this repository's file.
103
 
     */
104
 
    const QString& file() const;
105
 
 
106
 
    /**
107
 
     * The namespace associated with this repository.
108
 
     * Used in CodeCompletion for filtering.
109
 
     */
110
 
    QString completionNamespace() const;
111
 
    /**
112
 
     * Sets the code completion namespace for this repository.
113
 
     */
114
 
    void setCompletionNamespace(const QString& completionNamespace);
115
 
 
116
 
    /**
117
 
     * The QtScript(s) associated with this repository.
118
 
     *
119
 
     * @since KDE 4.5
120
 
     */
121
 
    QString script() const;
122
 
    /**
123
 
     * The token identifying the script in this repository.
124
 
     */
125
 
    KTextEditor::TemplateScript* registeredScript() const;
126
 
    /**
127
 
     * Sets the QtScript(s) associated with this repository.
128
 
     * 
129
 
     * @since KDE 4.5
130
 
     */
131
 
    void setScript(const QString& script);
132
 
 
133
 
    /**
134
 
     * Remove this repository from the disk. Also deletes the item and all its children.
135
 
     */
136
 
    void remove();
137
 
 
138
 
    /**
139
 
     * Save this repository to disk.
140
 
     */
141
 
    void save();
142
 
 
143
 
    virtual QVariant data(int role = Qt::UserRole + 1) const;
144
 
    virtual void setData(const QVariant& value, int role = Qt::UserRole + 1);
145
 
 
146
 
private Q_SLOTS:
147
 
    /// parses the XML file and load the containing snippets.
148
 
    void slotParseFile();
149
 
 
150
 
private:
151
 
    /// path to the repository file
152
 
    QString m_file;
153
 
    /// license of the snippets in this repo
154
 
    QString m_license;
155
 
    /// author(s) of the snippets in this repo
156
 
    QString m_authors;
157
 
    /// valid filetypes for the snippets in this repo
158
 
    QStringList m_filetypes;
159
 
    /// filtering namespace for code completion
160
 
    QString m_namespace;
161
 
    /// QtScript with functions to be used in the snippet
162
 
    QString m_script;
163
 
    /// registered script
164
 
    KTextEditor::TemplateScript* m_registeredScript;
165
 
};
166
 
 
167
 
#endif
168