~ubuntu-branches/debian/stretch/gnome-builder/stretch

« back to all changes in this revision

Viewing changes to data/snippets/gobject.snippets

  • Committer: Package Import Robot
  • Author(s): Andreas Henriksson
  • Date: 2015-10-11 12:38:45 UTC
  • Revision ID: package-import@ubuntu.com-20151011123845-a0hvkz01se0p1p5a
Tags: upstream-3.16.3
ImportĀ upstreamĀ versionĀ 3.16.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
snippet gobject
 
2
- scope c
 
3
- desc Create GObject
 
4
        #include "${1:$filename|stripsuffix}.h"
 
5
 
 
6
        typedef struct
 
7
        {
 
8
                $0
 
9
        } ${2:$1|camelize}Private;
 
10
 
 
11
        G_DEFINE_TYPE_WITH_PRIVATE ($2, ${3:$1|functify}, ${4:G_TYPE_OBJECT})
 
12
 
 
13
        enum {
 
14
                PROP_0,
 
15
                LAST_PROP
 
16
        };
 
17
 
 
18
        static GParamSpec *gParamSpecs [LAST_PROP];
 
19
 
 
20
        $2 *
 
21
        $3_new (void)
 
22
        {
 
23
                return g_object_new (${$1|namespace|functify|upper}_TYPE_${$1|class|functify|upper}, NULL);
 
24
        }
 
25
 
 
26
        static void
 
27
        $3_finalize (GObject *object)
 
28
        {
 
29
                $2 *self = ($2 *)object;
 
30
                $2Private *priv = $3_get_instance_private (self);
 
31
 
 
32
                G_OBJECT_CLASS ($3_parent_class)->finalize (object);
 
33
        }
 
34
 
 
35
        static void
 
36
        $3_get_property (GObject    *object,
 
37
        ${$3|space}               guint       prop_id,
 
38
        ${$3|space}               GValue     *value,
 
39
        ${$3|space}               GParamSpec *pspec)
 
40
        {
 
41
                $2 *self = ${$3|upper} (object);
 
42
 
 
43
                switch (prop_id)
 
44
                  {
 
45
                  default:
 
46
                    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 
47
                  }
 
48
        }
 
49
 
 
50
        static void
 
51
        $3_set_property (GObject      *object,
 
52
        ${$3|space}               guint         prop_id,
 
53
        ${$3|space}               const GValue *value,
 
54
        ${$3|space}               GParamSpec   *pspec)
 
55
        {
 
56
                $2 *self = ${$3|upper} (object);
 
57
 
 
58
                switch (prop_id)
 
59
                  {
 
60
                  default:
 
61
                    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 
62
                  }
 
63
        }
 
64
 
 
65
        static void
 
66
        $3_class_init ($2Class *klass)
 
67
        {
 
68
                GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
69
 
 
70
                object_class->finalize = $3_finalize;
 
71
                object_class->get_property = $3_get_property;
 
72
                object_class->set_property = $3_set_property;
 
73
        }
 
74
 
 
75
        static void
 
76
        $3_init ($2 *self)
 
77
        {
 
78
        }
 
79
- scope chdr
 
80
- desc Create GObject header
 
81
        #ifndef ${$1|functify|upper}_H
 
82
        #define ${$1|functify|upper}_H
 
83
 
 
84
        #include ${3:<glib-object.h>}
 
85
 
 
86
        G_BEGIN_DECLS
 
87
 
 
88
        #define ${$1|functify|namespace|upper}_TYPE_${$1|class|functify|upper} (${$1|functify}_get_type())
 
89
 
 
90
        G_DECLARE_DERIVABLE_TYPE (${1:$filename|stripsuffix|camelize}, ${$1|functify}, ${$1|functify|namespace|upper}, ${$1|class|functify|upper}, ${2:GObject})
 
91
 
 
92
        struct _$1Class
 
93
        {
 
94
                $2Class parent;
 
95
        };
 
96
 
 
97
        $1 *${$1|functify}_new (void);
 
98
        $0
 
99
        G_END_DECLS
 
100
 
 
101
        #endif /* ${$1|functify|upper}_H */
 
102
snippet gobj_guard
 
103
- scope chdr
 
104
        #ifndef ${1:$filename|stripsuffix|functify|upper}_H
 
105
        #define $1_H
 
106
 
 
107
        #include <glib.h>
 
108
 
 
109
        G_BEGIN_DECLS
 
110
 
 
111
        $0
 
112
 
 
113
        G_END_DECLS
 
114
 
 
115
        #endif /* $1_H */
 
116
snippet gobj_interface
 
117
- scope c
 
118
- desc Create GObject Interface
 
119
        #include "${1:$filename|stripsuffix}.h"
 
120
 
 
121
        G_DEFINE_INTERFACE (${2:$1|camelize}, ${3:$1|functify}, ${4:G_TYPE_OBJECT})
 
122
 
 
123
        static void
 
124
        $3_default_init ($2Interface *iface)
 
125
        {
 
126
        }
 
127
- scope chdr
 
128
- desc Create GObject Interface header
 
129
        #ifndef ${$1|functify|upper}_H
 
130
        #define ${$1|functify|upper}_H
 
131
 
 
132
        #include <glib-object.h>
 
133
 
 
134
        G_BEGIN_DECLS
 
135
 
 
136
        #define ${$1|functify|namespace|upper}_TYPE_${$1|class|functify|upper}               (${$1|functify}_get_type ())
 
137
        #define ${$1|functify|namespace|upper}_${$1|class|functify|upper}(obj)               (G_TYPE_CHECK_INSTANCE_CAST ((obj), ${$1|functify|namespace|upper}_TYPE_${$1|class|functify|upper}, $1))
 
138
        #define ${$1|functify|namespace|upper}_IS_${$1|class|functify|upper}(obj)            (G_TYPE_CHECK_INSTANCE_TYPE ((obj), ${$1|functify|namespace|upper}_TYPE_${$1|class|functify|upper}))
 
139
        #define ${$1|functify|namespace|upper}_${$1|class|functify|upper}_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), ${$1|functify|namespace|upper}_TYPE_${$1|class|functify|upper}, $1Interface))
 
140
 
 
141
        typedef struct _$1      $1;
 
142
        typedef struct _$1Interface $1Interface;
 
143
 
 
144
        struct _${1:$filename|stripsuffix|functify|camelize}Interface
 
145
        {
 
146
                GTypeInterface parent;
 
147
        };
 
148
 
 
149
        GType ${$1|functify}_get_type (void);
 
150
 
 
151
        G_END_DECLS
 
152
 
 
153
        #endif /* ${$1|functify|upper}_H */
 
154
snippet gobj_ref
 
155
- scope c
 
156
- desc GObject ref
 
157
        g_object_ref (${1});$0
 
158
snippet gobj_unref
 
159
- scope c
 
160
- desc GObject unref
 
161
        g_object_unref (${1});$0
 
162
snippet gobj_clear
 
163
- scope c
 
164
- desc GObject clear
 
165
        g_clear_object (&${1});$0
 
166
snippet gproperty
 
167
- scope c
 
168
- desc Add GObject property
 
169
        gParamSpecs [PROP_${1:NAME}] =
 
170
                g_param_spec_${2:object} ("${3:$1|lower}",
 
171
                             ${$2|space}  _("${4:$3|camelize}"),
 
172
                             ${$2|space}  _("${5:$3|camelize}"),
 
173
                             ${$2|space}  ${6}
 
174
                             ${$2|space}  (G_PARAM_${7:READWRITE} |
 
175
                             ${$2|space}   G_PARAM_STATIC_STRINGS));
 
176
        g_object_class_install_property (object_class, PROP_$1,
 
177
                                         gParamSpecs [PROP_$1]);
 
178
snippet gsignal
 
179
- scope c
 
180
- desc Add GObject signal
 
181
        gSignals [${$1|functify|upper}] =
 
182
                g_signal_new ("${1:name}",
 
183
                              G_TYPE_FROM_CLASS (klass),
 
184
                              ${2:G_SIGNAL_RUN_LAST},
 
185
                              ${3:0},
 
186
                              ${4:NULL},
 
187
                              ${5:NULL},
 
188
                              ${6:g_cclosure_marshal_generic},
 
189
                              ${7:G_TYPE_NONE},
 
190
                              ${8:0});
 
191
snippet async
 
192
- scope c
 
193
        void
 
194
        ${$2|functify}_${1:do_something}_async (${2:$filename|stripsuffix|camelize} *self,
 
195
        ${$2|space} ${$1|space}          GCancellable *cancellable,
 
196
        ${$2|space} ${$1|space}          GAsyncReadyCallback callback,
 
197
        ${$2|space} ${$1|space}          gpointer user_data)
 
198
        {
 
199
                g_autoptr(GTask) task = NULL;
 
200
 
 
201
                g_return_if_fail (${$filename|stripsuffix|functify|namespace|upper}_IS_${$filename|stripsuffix|class|functify|upper} (self));
 
202
                g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
 
203
 
 
204
                task = g_task_new (self, cancellable, callback, user_data);
 
205
 
 
206
                $0
 
207
        }
 
208
snippet finish
 
209
- scope c
 
210
        gboolean
 
211
        ${$2|functify}_${1:do_something}_finish (${2:$filename|stripsuffix|camelize} *self,
 
212
        ${$2|space} ${$1|space}           GAsyncResult *result,
 
213
        ${$2|space} ${$1|space}           GError **error)
 
214
        {
 
215
                GTask *task = (GTask *)result;
 
216
 
 
217
                g_return_val_if_fail (${$filename|stripsuffix|functify|namespace|upper}_IS_${$filename|stripsuffix|class|functify|upper} (self), ${3:FALSE});
 
218
 
 
219
                return g_task_propagate_${4:boolean} (task, error);
 
220
        }