[gnome-builder] snippets: Add language scope support to snippets
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] snippets: Add language scope support to snippets
- Date: Sun, 11 Jan 2015 08:11:01 +0000 (UTC)
commit a798c4212f0d01f6e6ab774b9c28374d643ba072
Author: Roberto Majadas <roberto majadas openshine com>
Date: Sat Jan 10 18:53:38 2015 +0100
snippets: Add language scope support to snippets
src/resources/gnome-builder.gresource.xml | 3 +
src/resources/snippets/c-sharp.snippets | 40 ------
src/resources/snippets/c.snippets | 166 +++-----------------------
src/resources/snippets/chdr.snippets | 78 ------------
src/resources/snippets/gobject.snippets | 186 +++++++++++++++++++++++++++++
src/resources/snippets/licenses.snippets | 116 ++++++++++++++++++
src/resources/snippets/main.snippets | 21 ++++
src/resources/snippets/python.snippets | 48 +-------
src/resources/snippets/rpmspec.snippets | 4 +
src/resources/snippets/vala.snippets | 38 ------
src/resources/snippets/xml.snippets | 1 +
src/snippets/gb-source-snippet-parser.c | 87 ++++++++++++--
src/snippets/gb-source-snippet.c | 41 ++++++-
src/snippets/gb-source-snippet.h | 6 +-
src/snippets/gb-source-snippets-manager.c | 90 ++++----------
src/snippets/gb-source-snippets-manager.h | 2 +
src/snippets/gb-source-snippets.c | 27 ----
src/snippets/gb-source-snippets.h | 3 -
18 files changed, 500 insertions(+), 457 deletions(-)
---
diff --git a/src/resources/gnome-builder.gresource.xml b/src/resources/gnome-builder.gresource.xml
index 5bbd5a9..98eb799 100644
--- a/src/resources/gnome-builder.gresource.xml
+++ b/src/resources/gnome-builder.gresource.xml
@@ -22,6 +22,9 @@
<file>snippets/c.snippets</file>
<file>snippets/chdr.snippets</file>
<file>snippets/c-sharp.snippets</file>
+ <file>snippets/gobject.snippets</file>
+ <file>snippets/licenses.snippets</file>
+ <file>snippets/main.snippets</file>
<file>snippets/python.snippets</file>
<file>snippets/rpmspec.snippets</file>
<file>snippets/vala.snippets</file>
diff --git a/src/resources/snippets/c-sharp.snippets b/src/resources/snippets/c-sharp.snippets
index 9ac5bf1..e69de29 100644
--- a/src/resources/snippets/c-sharp.snippets
+++ b/src/resources/snippets/c-sharp.snippets
@@ -1,40 +0,0 @@
-snippet gpl
- //
- // ${1:$filename}
- //
- // Copyright (C) $year ${2:$fullname} <${3:$email}>
- //
- // This program is free software: you can redistribute it and/or modify
- // it under the terms of the GNU General Public License as published by
- // the Free Software Foundation, either version 3 of the License, or
- // (at your option) any later version.
- //
- // This program is distributed in the hope that it will be useful,
- // but WITHOUT ANY WARRANTY; without even the implied warranty of
- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- // GNU General Public License for more details.
- //
- // You should have received a copy of the GNU General Public License
- // along with this program. If not, see <http://www.gnu.org/licenses/>.
- //
- $0
-snippet lgpl
- //
- // ${1:$filename}
- //
- // Copyright (C) $year ${2:$fullname} <${3:$email}>
- //
- // This file is free software; you can redistribute it and/or modify it
- // under the terms of the GNU Lesser General Public License as
- // published by the Free Software Foundation; either version 3 of the
- // License, or (at your option) any later version.
- //
- // This file is distributed in the hope that it will be useful, but
- // WITHOUT ANY WARRANTY; without even the implied warranty of
- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- // Lesser General Public License for more details.
- //
- // You should have received a copy of the GNU General Public License
- // along with this program. If not, see <http://www.gnu.org/licenses/>.
- //
- $0
diff --git a/src/resources/snippets/c.snippets b/src/resources/snippets/c.snippets
index ec1fb67..872618b 100644
--- a/src/resources/snippets/c.snippets
+++ b/src/resources/snippets/c.snippets
@@ -1,167 +1,41 @@
-snippet main
- #include <glib.h>
-
- gint
- main (gint argc,
- gchar *argv[])
- {
- g_set_prgname ("${1:my-program}");
- g_set_application_name ("${2:$1|capitalize}");
-
- $0
-
- return 0;
- }
snippet fail
+- scope c, chdr
g_return_if_fail
(${1:`$filename|stripsuffix|functify|namespace|upper`_IS_`$filename|stripsuffix|class|functify|upper`
(`$filename|stripsuffix|instance`)});$0
snippet vfail
+- scope c, chdr
g_return_val_if_fail
(${1:`$filename|stripsuffix|functify|namespace|upper`_IS_`$filename|stripsuffix|class|functify|upper`
(`$filename|stripsuffix|instance`)}, ${2:NULL});$0
-snippet gpl
- /* ${1:$filename}
- *
- * Copyright (C) $year ${2:$fullname} <${3:$email}>
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- $0
-snippet lgpl
- /* ${1:$filename}
- *
- * Copyright (C) $year ${2:$fullname} <${3:$email}>
- *
- * This file is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 3 of the
- * License, or (at your option) any later version.
- *
- * This file is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- $0
snippet W
+- scope c, chdr
GtkWidget *
snippet c
+- scope c, chdr
*${$filename|stripsuffix|instance}
snippet f
+- scope c, chdr
${$filename|stripsuffix|functify}_
snippet gp
+- scope c, chdr
gpointer
snippet gb
+- scope c, chdr
gboolean
snippet for
+- scope c, chdr
for (${1:i = 0}; ${2:i < }; ${3:i++})
{
$0
}
snippet inc
+- scope c, chdr
#include "${1}"$0
snippet Inc
+- scope c, chdr
#include <${1}>$0
-snippet gobject
- #include "${1:$filename|stripsuffix}.h"
-
- struct _${2:$1|camelize}Private
- {
- $0
- };
-
- G_DEFINE_TYPE_WITH_PRIVATE ($2, ${3:$1|functify}, ${4:G_TYPE_OBJECT})
-
- enum {
- PROP_0,
- LAST_PROP
- };
-
- static GParamSpec *gParamSpecs [LAST_PROP];
-
- $2 *
- $3_new (void)
- {
- return g_object_new (${$1|namespace|functify|upper}_TYPE_${$1|class|functify|upper}, NULL);
- }
-
- static void
- $3_finalize (GObject *object)
- {
- $2Private *priv = ${$3|upper} (object)->priv;
-
- G_OBJECT_CLASS ($3_parent_class)->finalize (object);
- }
-
- static void
- $3_get_property (GObject *object,
- ${$3|space} guint prop_id,
- ${$3|space} GValue *value,
- ${$3|space} GParamSpec *pspec)
- {
- $2 *self = ${$3|upper} (object);
-
- switch (prop_id)
- {
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- }
- }
-
- static void
- $3_set_property (GObject *object,
- ${$3|space} guint prop_id,
- ${$3|space} const GValue *value,
- ${$3|space} GParamSpec *pspec)
- {
- $2 *self = ${$3|upper} (object);
-
- switch (prop_id)
- {
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- }
- }
-
- static void
- $3_class_init ($2Class *klass)
- {
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->finalize = $3_finalize;
- object_class->get_property = $3_get_property;
- object_class->set_property = $3_set_property;
- }
-
- static void
- $3_init ($2 *self)
- {
- self->priv = $3_get_instance_private (self);
- }
snippet pr
+- scope c, chdr
${$filename|stripsuffix|functify|camelize}Private *priv;$0
-snippet prop
- gParamSpecs [PROP_${1:NAME}] =
- g_param_spec_${2:object} ("${3:name}",
- ${$2|space} _("${4:Name}"),
- ${$2|space} _("${5:Name}"),
- ${$2|space} ${6}
- ${$2|space} (G_PARAM_${7:READWRITE} |
- ${$2|space} G_PARAM_STATIC_STRINGS));
- g_object_class_install_property (object_class, PROP_$1,
- gParamSpecs [PROP_$1]);
snippet doc
+- scope c, chdr
/**
* ${$filename|stripsuffix|functify}_${1:func}:
*
@@ -170,25 +44,15 @@ snippet doc
* Returns: ${2}
*/$0
snippet C
+- scope c, chdr
${$filename|stripsuffix|functify|camelize} $0
snippet CC
+- scope c, chdr
${$filename|stripsuffix|functify|upper} (${1})$0
snippet comment
+- scope c, chdr
/*
* $0
*/
-snippet ref
- g_object_ref (${1});$0
-snippet unref
- g_object_unref (${1});$0
-snippet clear
- g_clear_object (&${1});$0
-snippet ginterface
- #include "${1:$filename|stripsuffix}.h"
- G_DEFINE_INTERFACE (${2:$1|camelize}, ${3:$1|functify}, ${4:G_TYPE_OBJECT})
- static void
- $3_default_init ($2Interface *iface)
- {
- }
diff --git a/src/resources/snippets/chdr.snippets b/src/resources/snippets/chdr.snippets
index 28deeb6..e69de29 100644
--- a/src/resources/snippets/chdr.snippets
+++ b/src/resources/snippets/chdr.snippets
@@ -1,78 +0,0 @@
-snippet gobject
- #ifndef ${$1|functify|upper}_H
- #define ${$1|functify|upper}_H
-
- #include ${3:<glib-object.h>}
-
- G_BEGIN_DECLS
-
- #define ${$1|functify|namespace|upper}_TYPE_${$1|class|functify|upper}
(${$1|functify}_get_type())
- #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))
- #define ${$1|functify|namespace|upper}_${$1|class|functify|upper}_CONST(obj)
(G_TYPE_CHECK_INSTANCE_CAST ((obj), ${$1|functify|namespace|upper}_TYPE_${$1|class|functify|upper}, $1 const))
- #define ${$1|functify|namespace|upper}_${$1|class|functify|upper}_CLASS(klass)
(G_TYPE_CHECK_CLASS_CAST ((klass), ${$1|functify|namespace|upper}_TYPE_${$1|class|functify|upper}, $1Class))
- #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}))
- #define ${$1|functify|namespace|upper}_IS_${$1|class|functify|upper}_CLASS(klass)
(G_TYPE_CHECK_CLASS_TYPE ((klass), ${$1|functify|namespace|upper}_TYPE_${$1|class|functify|upper}))
- #define ${$1|functify|namespace|upper}_${$1|class|functify|upper}_GET_CLASS(obj)
(G_TYPE_INSTANCE_GET_CLASS ((obj), ${$1|functify|namespace|upper}_TYPE_${$1|class|functify|upper}, $1Class))
-
- typedef struct _$1 $1;
- typedef struct _$1Class $1Class;
- typedef struct _$1Private $1Private;
-
- struct _${1:$filename|stripsuffix|functify|camelize}
- {
- ${2:GObject} parent;
-
- /*< private >*/
- $1Private *priv;
- };
-
- struct _$1Class
- {
- $2Class parent;
- };
-
- GType ${$1|space}${$1|functify}_get_type (void);
- $1 *${$1|functify}_new (void);
- $0
- G_END_DECLS
-
- #endif /* ${$1|functify|upper}_H */
-snippet guard
- #ifndef ${1:$filename|stripsuffix|functify|upper}_H
- #define $1_H
-
- #include <glib.h>
-
- G_BEGIN_DECLS
-
- $0
-
- G_END_DECLS
-
- #endif /* $1_H */
-snippet ginterface
- #ifndef ${$1|functify|upper}_H
- #define ${$1|functify|upper}_H
-
- #include <glib-object.h>
-
- G_BEGIN_DECLS
-
- #define ${$1|functify|namespace|upper}_TYPE_${$1|class|functify|upper}
(${$1|functify}_get_type ())
- #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))
- #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}))
- #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))
-
- typedef struct _$1 $1;
- typedef struct _$1Interface $1Interface;
-
- struct _${1:$filename|stripsuffix|functify|camelize}Interface
- {
- GTypeInterface parent;
- };
-
- GType ${$1|functify}_get_type (void);
-
- G_END_DECLS
-
- #endif /* ${$1|functify|upper}_H */
diff --git a/src/resources/snippets/gobject.snippets b/src/resources/snippets/gobject.snippets
new file mode 100644
index 0000000..58261da
--- /dev/null
+++ b/src/resources/snippets/gobject.snippets
@@ -0,0 +1,186 @@
+snippet gobject
+- scope c
+ #include "${1:$filename|stripsuffix}.h"
+
+ struct _${2:$1|camelize}Private
+ {
+ $0
+ };
+
+ G_DEFINE_TYPE_WITH_PRIVATE ($2, ${3:$1|functify}, ${4:G_TYPE_OBJECT})
+
+ enum {
+ PROP_0,
+ LAST_PROP
+ };
+
+ static GParamSpec *gParamSpecs [LAST_PROP];
+
+ $2 *
+ $3_new (void)
+ {
+ return g_object_new (${$1|namespace|functify|upper}_TYPE_${$1|class|functify|upper}, NULL);
+ }
+
+ static void
+ $3_finalize (GObject *object)
+ {
+ $2Private *priv = ${$3|upper} (object)->priv;
+
+ G_OBJECT_CLASS ($3_parent_class)->finalize (object);
+ }
+
+ static void
+ $3_get_property (GObject *object,
+ ${$3|space} guint prop_id,
+ ${$3|space} GValue *value,
+ ${$3|space} GParamSpec *pspec)
+ {
+ $2 *self = ${$3|upper} (object);
+
+ switch (prop_id)
+ {
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+ }
+
+ static void
+ $3_set_property (GObject *object,
+ ${$3|space} guint prop_id,
+ ${$3|space} const GValue *value,
+ ${$3|space} GParamSpec *pspec)
+ {
+ $2 *self = ${$3|upper} (object);
+
+ switch (prop_id)
+ {
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+ }
+
+ static void
+ $3_class_init ($2Class *klass)
+ {
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->finalize = $3_finalize;
+ object_class->get_property = $3_get_property;
+ object_class->set_property = $3_set_property;
+ }
+
+ static void
+ $3_init ($2 *self)
+ {
+ self->priv = $3_get_instance_private (self);
+ }
+- scope chdr
+ #ifndef ${$1|functify|upper}_H
+ #define ${$1|functify|upper}_H
+
+ #include ${3:<glib-object.h>}
+
+ G_BEGIN_DECLS
+
+ #define ${$1|functify|namespace|upper}_TYPE_${$1|class|functify|upper}
(${$1|functify}_get_type())
+ #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))
+ #define ${$1|functify|namespace|upper}_${$1|class|functify|upper}_CONST(obj)
(G_TYPE_CHECK_INSTANCE_CAST ((obj), ${$1|functify|namespace|upper}_TYPE_${$1|class|functify|upper}, $1 const))
+ #define ${$1|functify|namespace|upper}_${$1|class|functify|upper}_CLASS(klass)
(G_TYPE_CHECK_CLASS_CAST ((klass), ${$1|functify|namespace|upper}_TYPE_${$1|class|functify|upper}, $1Class))
+ #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}))
+ #define ${$1|functify|namespace|upper}_IS_${$1|class|functify|upper}_CLASS(klass)
(G_TYPE_CHECK_CLASS_TYPE ((klass), ${$1|functify|namespace|upper}_TYPE_${$1|class|functify|upper}))
+ #define ${$1|functify|namespace|upper}_${$1|class|functify|upper}_GET_CLASS(obj)
(G_TYPE_INSTANCE_GET_CLASS ((obj), ${$1|functify|namespace|upper}_TYPE_${$1|class|functify|upper}, $1Class))
+
+ typedef struct _$1 $1;
+ typedef struct _$1Class $1Class;
+ typedef struct _$1Private $1Private;
+
+ struct _${1:$filename|stripsuffix|functify|camelize}
+ {
+ ${2:GObject} parent;
+
+ /*< private >*/
+ $1Private *priv;
+ };
+
+ struct _$1Class
+ {
+ $2Class parent;
+ };
+
+ GType ${$1|space}${$1|functify}_get_type (void);
+ $1 *${$1|functify}_new (void);
+ $0
+ G_END_DECLS
+
+ #endif /* ${$1|functify|upper}_H */
+snippet gobj_guard
+- scope chdr
+ #ifndef ${1:$filename|stripsuffix|functify|upper}_H
+ #define $1_H
+
+ #include <glib.h>
+
+ G_BEGIN_DECLS
+
+ $0
+
+ G_END_DECLS
+
+ #endif /* $1_H */
+snippet gobj_interface
+- scope c
+ #include "${1:$filename|stripsuffix}.h"
+
+ G_DEFINE_INTERFACE (${2:$1|camelize}, ${3:$1|functify}, ${4:G_TYPE_OBJECT})
+
+ static void
+ $3_default_init ($2Interface *iface)
+ {
+ }
+- scope chdr
+ #ifndef ${$1|functify|upper}_H
+ #define ${$1|functify|upper}_H
+
+ #include <glib-object.h>
+
+ G_BEGIN_DECLS
+
+ #define ${$1|functify|namespace|upper}_TYPE_${$1|class|functify|upper}
(${$1|functify}_get_type ())
+ #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))
+ #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}))
+ #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))
+
+ typedef struct _$1 $1;
+ typedef struct _$1Interface $1Interface;
+
+ struct _${1:$filename|stripsuffix|functify|camelize}Interface
+ {
+ GTypeInterface parent;
+ };
+
+ GType ${$1|functify}_get_type (void);
+
+ G_END_DECLS
+
+ #endif /* ${$1|functify|upper}_H */
+snippet gobj_ref
+- scope c
+ g_object_ref (${1});$0
+snippet gobj_unref
+- scope c
+ g_object_unref (${1});$0
+snippet gobj_clear
+- scope c
+ g_clear_object (&${1});$0
+snippet gobj_prop
+- scope c
+ gParamSpecs [PROP_${1:NAME}] =
+ g_param_spec_${2:object} ("${3:name}",
+ ${$2|space} _("${4:Name}"),
+ ${$2|space} _("${5:Name}"),
+ ${$2|space} ${6}
+ ${$2|space} (G_PARAM_${7:READWRITE} |
+ ${$2|space} G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property (object_class, PROP_$1,
+ gParamSpecs [PROP_$1]);
\ No newline at end of file
diff --git a/src/resources/snippets/licenses.snippets b/src/resources/snippets/licenses.snippets
new file mode 100644
index 0000000..c554f1d
--- /dev/null
+++ b/src/resources/snippets/licenses.snippets
@@ -0,0 +1,116 @@
+snippet gpl
+- scope c, cpp, chdr, vala
+ /* ${1:$filename}
+ *
+ * Copyright (C) $year ${2:$fullname} <${3:$email}>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+ $0
+- scope python, python3
+ # ${1:$filename}
+ #
+ # Copyright (C) $year ${2:$fullname} <${3:$email}>
+ #
+ # This program is free software: you can redistribute it and/or modify
+ # it under the terms of the GNU General Public License as published by
+ # the Free Software Foundation, either version 3 of the License, or
+ # (at your option) any later version.
+ #
+ # This program is distributed in the hope that it will be useful,
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ # GNU General Public License for more details.
+ #
+ # You should have received a copy of the GNU General Public License
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
+ $0
+- scope c-sharp
+ //
+ // ${1:$filename}
+ //
+ // Copyright (C) $year ${2:$fullname} <${3:$email}>
+ //
+ // This program is free software: you can redistribute it and/or modify
+ // it under the terms of the GNU General Public License as published by
+ // the Free Software Foundation, either version 3 of the License, or
+ // (at your option) any later version.
+ //
+ // This program is distributed in the hope that it will be useful,
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ // GNU General Public License for more details.
+ //
+ // You should have received a copy of the GNU General Public License
+ // along with this program. If not, see <http://www.gnu.org/licenses/>.
+ //
+ $0
+snippet lgpl
+- scope c, cpp, chdr, vala
+ /* ${1:$filename}
+ *
+ * Copyright (C) $year ${2:$fullname} <${3:$email}>
+ *
+ * This file is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This file is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+ $0
+- scope python, python3
+ # ${1:$filename}
+ #
+ # Copyright (C) $year ${2:$fullname} <${3:$email}>
+ #
+ # This file is free software; you can redistribute it and/or modify it
+ # under the terms of the GNU Lesser General Public License as
+ # published by the Free Software Foundation; either version 3 of the
+ # License, or (at your option) any later version.
+ #
+ # This file is distributed in the hope that it will be useful, but
+ # WITHOUT ANY WARRANTY; without even the implied warranty of
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ # Lesser General Public License for more details.
+ #
+ # You should have received a copy of the GNU General Public License
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
+ $0
+- scope c-sharp
+ //
+ // ${1:$filename}
+ //
+ // Copyright (C) $year ${2:$fullname} <${3:$email}>
+ //
+ // This file is free software; you can redistribute it and/or modify it
+ // under the terms of the GNU Lesser General Public License as
+ // published by the Free Software Foundation; either version 3 of the
+ // License, or (at your option) any later version.
+ //
+ // This file is distributed in the hope that it will be useful, but
+ // WITHOUT ANY WARRANTY; without even the implied warranty of
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ // Lesser General Public License for more details.
+ //
+ // You should have received a copy of the GNU General Public License
+ // along with this program. If not, see <http://www.gnu.org/licenses/>.
+ //
+ $0
\ No newline at end of file
diff --git a/src/resources/snippets/main.snippets b/src/resources/snippets/main.snippets
new file mode 100644
index 0000000..d8e5984
--- /dev/null
+++ b/src/resources/snippets/main.snippets
@@ -0,0 +1,21 @@
+snippet main
+- scope c, cpp
+ #include <glib.h>
+
+ gint
+ main (gint argc,
+ gchar *argv[])
+ {
+ g_set_prgname ("${1:my-program}");
+ g_set_application_name ("${2:$1|capitalize}");
+
+ $0
+
+ return 0;
+ }
+- scope python, python3
+ def main():
+ $0
+
+ if __name__ == "__main__":
+ main()
diff --git a/src/resources/snippets/python.snippets b/src/resources/snippets/python.snippets
index 7fee1dd..3ad5ccb 100644
--- a/src/resources/snippets/python.snippets
+++ b/src/resources/snippets/python.snippets
@@ -1,56 +1,20 @@
snippet python
+- scope python, python3
#!/usr/bin/env python
$0
-snippet gpl
- # ${1:$filename}
- #
- # Copyright (C) $year ${2:$fullname} <${3:$email}>
- #
- # This program is free software: you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation, either version 3 of the License, or
- # (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
- $0
-snippet lgpl
- # ${1:$filename}
- #
- # Copyright (C) $year ${2:$fullname} <${3:$email}>
- #
- # This file is free software; you can redistribute it and/or modify it
- # under the terms of the GNU Lesser General Public License as
- # published by the Free Software Foundation; either version 3 of the
- # License, or (at your option) any later version.
- #
- # This file is distributed in the hope that it will be useful, but
- # WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- # Lesser General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
- $0
snippet import
+- scope python, python3
import $0
snippet from
+- scope python, python3
from ${1} import $0
snippet def
+- scope python, python3
def ${1:function}(${2}):
$0
snippet class
+- scope python, python3
class ${1:Foo}(${2:object}):
def __init__(self${3}):
$0
-snippet main
- def main():
- $0
-
- if __name__ == "__main__":
- main()
+
diff --git a/src/resources/snippets/rpmspec.snippets b/src/resources/snippets/rpmspec.snippets
index b8dc6fe..9eef6c6 100644
--- a/src/resources/snippets/rpmspec.snippets
+++ b/src/resources/snippets/rpmspec.snippets
@@ -1,4 +1,5 @@
snippet minimal
+- scope rpmspec
Name: ${1:$filename|stripsuffix}
Version: ${2:1.0}
Release: ${3:1}%{?dist}
@@ -32,6 +33,7 @@ snippet minimal
* $shortweekday $shortmonth $day $year ${13:$fullname} <${14:$email}> - $2-$3
- Initial package$0
snippet library
+- scope rpmspec
Name: ${1:$filename|stripsuffix}
Version: ${2:1.0}
Release: ${3:1}%{?dist}
@@ -84,6 +86,7 @@ snippet library
* $shortweekday $shortmonth $day $year ${18:$fullname} <${19:$email}> - $2-$3
- Initial package$0
snippet python-arch
+- scope rpmspec
%{!?python_sitelib: %global python_sitelib %(%{__python} -c "from distutils.sysconfig import
get_python_lib; print(get_python_lib())")}
%{!?python_sitearch: %global python_sitearch %(%{__python} -c "from distutils.sysconfig import
get_python_lib; print(get_python_lib(1))")}
Name: ${1:$filename|stripsuffix}
@@ -120,6 +123,7 @@ snippet python-arch
* $shortweekday $shortmonth $day $year ${16:$fullname} <${17:$email}> - $2-$3
- Initial package$0
snippet python-noarch
+- scope rpmspec
Name: ${1:$filename|stripsuffix}
Version: ${2:1.0}
Release: ${3:1}%{?dist}
diff --git a/src/resources/snippets/vala.snippets b/src/resources/snippets/vala.snippets
index 33d80da..e69de29 100644
--- a/src/resources/snippets/vala.snippets
+++ b/src/resources/snippets/vala.snippets
@@ -1,38 +0,0 @@
-snippet gpl
- /* ${1:$filename}
- *
- * Copyright (C) $year ${2:$fullname} <${3:$email}>
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- $0
-snippet lgpl
- /* ${1:$filename}
- *
- * Copyright (C) $year ${2:$fullname} <${3:$email}>
- *
- * This file is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 3 of the
- * License, or (at your option) any later version.
- *
- * This file is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- $0
diff --git a/src/resources/snippets/xml.snippets b/src/resources/snippets/xml.snippets
index f69a216..0b5a08c 100644
--- a/src/resources/snippets/xml.snippets
+++ b/src/resources/snippets/xml.snippets
@@ -1,3 +1,4 @@
snippet xml
+- scope xml
<?xml version="1.0"?>
$0
diff --git a/src/snippets/gb-source-snippet-parser.c b/src/snippets/gb-source-snippet-parser.c
index 333164e..6953f2c 100644
--- a/src/snippets/gb-source-snippet-parser.c
+++ b/src/snippets/gb-source-snippet-parser.c
@@ -33,6 +33,7 @@ struct _GbSourceSnippetParserPrivate
gint lineno;
GList *chunks;
+ GList *scope;
gchar *cur_name;
GString *cur_text;
};
@@ -59,29 +60,43 @@ gb_source_snippet_parser_flush_chunk (GbSourceSnippetParser *parser)
}
static void
-gb_source_snippet_parser_finish (GbSourceSnippetParser *parser)
+gb_source_snippet_parser_store (GbSourceSnippetParser *parser)
{
GbSourceSnippetParserPrivate *priv = parser->priv;
GbSourceSnippet *snippet;
- GList *iter;
+ GList *scope_iter;
+ GList *chunck_iter;
- if (priv->cur_name)
+ gb_source_snippet_parser_flush_chunk (parser);
+ for (scope_iter = priv->scope; scope_iter; scope_iter = scope_iter->next)
{
- gb_source_snippet_parser_flush_chunk (parser);
- snippet = gb_source_snippet_new (priv->cur_name);
- for (iter = priv->chunks; iter; iter = iter->next)
+ snippet = gb_source_snippet_new (priv->cur_name,
+ g_strdup(scope_iter->data));
+ for (chunck_iter = priv->chunks; chunck_iter; chunck_iter = chunck_iter->next)
{
-#if 0
+ #if 0
g_printerr ("%s: Tab: %02d Link: %02d Text: %s\n",
parser->priv->cur_name,
- gb_source_snippet_chunk_get_tab_stop (iter->data),
- gb_source_snippet_chunk_get_linked_chunk (iter->data),
- gb_source_snippet_chunk_get_text (iter->data));
-#endif
- gb_source_snippet_add_chunk (snippet, iter->data);
+ gb_source_snippet_chunk_get_tab_stop (chunck_iter->data),
+ gb_source_snippet_chunk_get_linked_chunk (chunck_iter->data),
+ gb_source_snippet_chunk_get_text (chunck_iter->data));
+ #endif
+ gb_source_snippet_add_chunk (snippet, chunck_iter->data);
}
+
priv->snippets = g_list_append (priv->snippets, snippet);
}
+}
+
+static void
+gb_source_snippet_parser_finish (GbSourceSnippetParser *parser)
+{
+ GbSourceSnippetParserPrivate *priv = parser->priv;
+
+ if (priv->cur_name)
+ {
+ gb_source_snippet_parser_store(parser);
+ }
g_clear_pointer (&priv->cur_name, g_free);
@@ -90,6 +105,9 @@ gb_source_snippet_parser_finish (GbSourceSnippetParser *parser)
g_list_foreach (priv->chunks, (GFunc) g_object_unref, NULL);
g_list_free (priv->chunks);
priv->chunks = NULL;
+
+ g_list_free_full(priv->scope, g_free);
+ priv->scope = NULL;
}
static void
@@ -348,6 +366,24 @@ gb_source_snippet_parser_do_snippet (GbSourceSnippetParser *parser,
}
static void
+gb_source_snippet_parser_do_snippet_scope (GbSourceSnippetParser *parser,
+ const gchar *line)
+{
+ gchar **scope_list;
+ gint i;
+
+ scope_list = g_strsplit (&line[8], ",", -1);
+
+ for (i = 0; scope_list[i]; i++)
+ {
+ parser->priv->scope = g_list_append(parser->priv->scope,
+ g_strstrip (g_strdup (scope_list[i])));
+ }
+
+ g_strfreev(scope_list);
+}
+
+static void
gb_source_snippet_parser_feed_line (GbSourceSnippetParser *parser,
const gchar *line)
{
@@ -385,6 +421,29 @@ gb_source_snippet_parser_feed_line (GbSourceSnippetParser *parser,
break;
}
+ case '-':
+ if (priv->cur_text->len || priv->chunks)
+ {
+ gb_source_snippet_parser_store(parser);
+
+ g_string_truncate (priv->cur_text, 0);
+
+ g_list_foreach (priv->chunks, (GFunc) g_object_unref, NULL);
+ g_list_free (priv->chunks);
+ priv->chunks = NULL;
+ }
+
+ if (g_str_has_prefix(line, "- scope"))
+ {
+ if (priv->scope)
+ {
+ g_list_free_full(priv->scope, g_free);
+ priv->scope = NULL;
+ }
+ gb_source_snippet_parser_do_snippet_scope (parser, line);
+ break;
+ }
+
/* Fall through */
default:
g_warning (_("Invalid snippet at line %d: %s"), priv->lineno, line);
@@ -453,6 +512,9 @@ gb_source_snippet_parser_finalize (GObject *object)
g_list_free (priv->chunks);
priv->chunks = NULL;
+ g_list_free_full(priv->scope, g_free);
+ priv->scope = NULL;
+
if (priv->cur_text)
g_string_free (priv->cur_text, TRUE);
@@ -481,4 +543,5 @@ gb_source_snippet_parser_init (GbSourceSnippetParser *parser)
GbSourceSnippetParserPrivate);
parser->priv->lineno = -1;
parser->priv->cur_text = g_string_new (NULL);
+ parser->priv->scope = NULL;
}
diff --git a/src/snippets/gb-source-snippet.c b/src/snippets/gb-source-snippet.c
index 9f7a262..6870c7a 100644
--- a/src/snippets/gb-source-snippet.c
+++ b/src/snippets/gb-source-snippet.c
@@ -35,6 +35,7 @@ struct _GbSourceSnippetPrivate
GtkTextMark *mark_begin;
GtkTextMark *mark_end;
gchar *trigger;
+ gchar *language;
gint tab_stop;
gint max_tab_stop;
gint current_chunk;
@@ -48,6 +49,7 @@ enum {
PROP_MARK_END,
PROP_TAB_STOP,
PROP_TRIGGER,
+ PROP_LANGUAGE,
LAST_PROP
};
@@ -56,12 +58,13 @@ G_DEFINE_TYPE_WITH_PRIVATE (GbSourceSnippet, gb_source_snippet, G_TYPE_OBJECT)
static GParamSpec * gParamSpecs[LAST_PROP];
GbSourceSnippet *
-gb_source_snippet_new (const gchar *trigger)
+gb_source_snippet_new (const gchar *trigger, const gchar *language)
{
GbSourceSnippet *ret;
ret = g_object_new (GB_TYPE_SOURCE_SNIPPET,
"trigger", trigger,
+ "language", language,
NULL);
return ret;
@@ -83,6 +86,7 @@ gb_source_snippet_copy (GbSourceSnippet *snippet)
ret = g_object_new (GB_TYPE_SOURCE_SNIPPET,
"trigger", snippet->priv->trigger,
+ "language", snippet->priv->language,
NULL);
for (i = 0; i < priv->chunks->len; i++)
@@ -141,6 +145,24 @@ gb_source_snippet_set_trigger (GbSourceSnippet *snippet,
snippet->priv->trigger = g_strdup (trigger);
}
+const gchar *
+gb_source_snippet_get_language (GbSourceSnippet *snippet)
+{
+ g_return_val_if_fail (GB_IS_SOURCE_SNIPPET (snippet), NULL);
+
+ return snippet->priv->language;
+}
+
+void
+gb_source_snippet_set_language (GbSourceSnippet *snippet,
+ const gchar *language)
+{
+ g_return_if_fail (GB_IS_SOURCE_SNIPPET (snippet));
+
+ g_free (snippet->priv->language);
+ snippet->priv->language = g_strdup (language);
+}
+
static gint
gb_source_snippet_get_offset (GbSourceSnippet *snippet,
GtkTextIter *iter)
@@ -915,6 +937,10 @@ gb_source_snippet_get_property (GObject *object,
g_value_set_string (value, snippet->priv->trigger);
break;
+ case PROP_LANGUAGE:
+ g_value_set_string (value, snippet->priv->language);
+ break;
+
case PROP_TAB_STOP:
g_value_set_uint (value, snippet->priv->tab_stop);
break;
@@ -938,6 +964,10 @@ gb_source_snippet_set_property (GObject *object,
gb_source_snippet_set_trigger (snippet, g_value_get_string (value));
break;
+ case PROP_LANGUAGE:
+ gb_source_snippet_set_language (snippet, g_value_get_string (value));
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
@@ -992,6 +1022,15 @@ gb_source_snippet_class_init (GbSourceSnippetClass *klass)
g_object_class_install_property (object_class, PROP_TRIGGER,
gParamSpecs[PROP_TRIGGER]);
+ gParamSpecs[PROP_LANGUAGE] =
+ g_param_spec_string ("language",
+ _("Language"),
+ _("The language for the snippet."),
+ NULL,
+ (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property (object_class, PROP_LANGUAGE,
+ gParamSpecs[PROP_LANGUAGE]);
+
gParamSpecs[PROP_TAB_STOP] =
g_param_spec_int ("tab-stop",
_("Tab Stop"),
diff --git a/src/snippets/gb-source-snippet.h b/src/snippets/gb-source-snippet.h
index 1e6112a..8b023ae 100644
--- a/src/snippets/gb-source-snippet.h
+++ b/src/snippets/gb-source-snippet.h
@@ -51,12 +51,16 @@ struct _GbSourceSnippetClass
GObjectClass parent_class;
};
-GbSourceSnippet *gb_source_snippet_new (const gchar *trigger);
+GbSourceSnippet *gb_source_snippet_new (const gchar *trigger,
+ const gchar *language);
GbSourceSnippet *gb_source_snippet_copy (GbSourceSnippet *snippet);
GType gb_source_snippet_get_type (void);
const gchar *gb_source_snippet_get_trigger (GbSourceSnippet *snippet);
void gb_source_snippet_set_trigger (GbSourceSnippet *snippet,
const gchar *trigger);
+const gchar *gb_source_snippet_get_language (GbSourceSnippet *snippet);
+void gb_source_snippet_set_language (GbSourceSnippet *snippet,
+ const gchar *language);
void gb_source_snippet_add_chunk (GbSourceSnippet *snippet,
GbSourceSnippetChunk *chunk);
guint gb_source_snippet_get_n_chunks (GbSourceSnippet *snippet);
diff --git a/src/snippets/gb-source-snippets-manager.c b/src/snippets/gb-source-snippets-manager.c
index 778836e..6ea34c5 100644
--- a/src/snippets/gb-source-snippets-manager.c
+++ b/src/snippets/gb-source-snippets-manager.c
@@ -36,48 +36,42 @@ G_DEFINE_TYPE_WITH_PRIVATE (GbSourceSnippetsManager,
static gboolean
gb_source_snippets_manager_load_file (GbSourceSnippetsManager *manager,
GFile *file,
- const gchar *force_lang,
GError **error)
{
GbSourceSnippets *snippets;
- gchar *base = NULL;
-
+ GbSourceSnippetParser *parser;
+ GbSourceSnippet *snippet;
+ GList *iter;
+
g_return_val_if_fail (GB_IS_SOURCE_SNIPPETS_MANAGER (manager), FALSE);
g_return_val_if_fail (G_IS_FILE (file), FALSE);
- if (!force_lang)
+ parser = gb_source_snippet_parser_new ();
+ if (!gb_source_snippet_parser_load_from_file (parser, file, error))
{
- base = g_file_get_basename (file);
-
- if (!base)
- {
- g_set_error (error,
- G_IO_ERROR,
- G_IO_ERROR_INVAL,
- _("The file is invalid."));
- return FALSE;
- }
-
- if (strstr (base, "."))
- *strstr (base, ".") = '\0';
-
- force_lang = base;
+ g_object_unref (parser);
+ return FALSE;
}
- snippets = g_hash_table_lookup (manager->priv->by_language_id, force_lang);
-
- if (!snippets)
+ iter = gb_source_snippet_parser_get_snippets (parser);
+ for (; iter; iter = iter->next)
{
- snippets = gb_source_snippets_new ();
- g_hash_table_insert (manager->priv->by_language_id,
- g_strdup (force_lang),
- snippets);
- }
+ const gchar *language;
+ snippet = iter->data;
+ language = gb_source_snippet_get_language(snippet);
+ snippets = g_hash_table_lookup (manager->priv->by_language_id, language);
- g_free (base);
+ if (!snippets)
+ {
+ snippets = gb_source_snippets_new ();
+ g_hash_table_insert (manager->priv->by_language_id,
+ g_strdup (language),
+ snippets);
+ }
+ gb_source_snippets_add (snippets, snippet);
+ }
- if (!gb_source_snippets_load_from_file (snippets, file, error))
- return FALSE;
+ g_object_unref (parser);
return TRUE;
}
@@ -108,7 +102,7 @@ gb_source_snippets_manager_load_directory (GbSourceSnippetsManager *manager,
filename = g_build_filename (path, name, NULL);
file = g_file_new_for_path (filename);
if (!gb_source_snippets_manager_load_file (manager, file,
- NULL, &error))
+ &error))
{
g_warning (_("Failed to load file: %s: %s"),
filename, error->message);
@@ -161,35 +155,10 @@ gb_source_snippets_manager_get_for_language (GbSourceSnippetsManager *manager,
language_id = gtk_source_language_get_id (language);
snippets = g_hash_table_lookup (priv->by_language_id, language_id);
- if (!snippets && g_str_equal (language_id, "chdr"))
- snippets = g_hash_table_lookup (priv->by_language_id, "c");
-
return snippets;
}
static void
-gb_source_snippets_manager_preload_c (GbSourceSnippetsManager *manager)
-{
- GFile *file;
- gchar *path;
-
- g_return_if_fail (GB_IS_SOURCE_SNIPPETS_MANAGER (manager));
-
- file = g_file_new_for_uri ("resource://"SNIPPETS_DIRECTORY"c.snippets");
- if (g_file_query_exists (file, NULL))
- gb_source_snippets_manager_load_file (manager, file, "chdr", NULL);
- g_clear_object (&file);
-
- path = g_build_filename (g_get_user_config_dir (), "gnome-builder",
- "snippets", "c.snippets", NULL);
- file = g_file_new_for_path (path);
- if (g_file_query_exists (file, NULL))
- gb_source_snippets_manager_load_file (manager, file, "chdr", NULL);
- g_clear_object (&file);
- g_free (path);
-}
-
-static void
gb_source_snippets_manager_constructed (GObject *object)
{
GbSourceSnippetsManager *manager = (GbSourceSnippetsManager *)object;
@@ -201,13 +170,6 @@ gb_source_snippets_manager_constructed (GObject *object)
g_assert (GB_IS_SOURCE_SNIPPETS_MANAGER (manager));
- /*
- * We need to preload chdr so that it is the combination of the "c"
- * snippets and the chdr snippets on top of that. This way, you don't
- * need to write all of your snippets twice, for both "c" and "chdr".
- */
- gb_source_snippets_manager_preload_c (manager);
-
names = g_resources_enumerate_children (SNIPPETS_DIRECTORY,
G_RESOURCE_LOOKUP_FLAGS_NONE,
&error);
@@ -223,7 +185,7 @@ gb_source_snippets_manager_constructed (GObject *object)
{
path = g_strdup_printf ("resource://"SNIPPETS_DIRECTORY"%s", names[i]);
file = g_file_new_for_uri (path);
- if (!gb_source_snippets_manager_load_file (manager, file, NULL, &error))
+ if (!gb_source_snippets_manager_load_file (manager, file, &error))
{
g_message ("%s", error->message);
g_clear_error (&error);
diff --git a/src/snippets/gb-source-snippets-manager.h b/src/snippets/gb-source-snippets-manager.h
index ae083e7..ef9f191 100644
--- a/src/snippets/gb-source-snippets-manager.h
+++ b/src/snippets/gb-source-snippets-manager.h
@@ -22,6 +22,8 @@
#include <gtksourceview/gtksourcelanguage.h>
#include "gb-source-snippets.h"
+#include "gb-source-snippet.h"
+#include "gb-source-snippet-parser.h"
G_BEGIN_DECLS
diff --git a/src/snippets/gb-source-snippets.c b/src/snippets/gb-source-snippets.c
index 2c413ea..afd23c8 100644
--- a/src/snippets/gb-source-snippets.c
+++ b/src/snippets/gb-source-snippets.c
@@ -86,33 +86,6 @@ gb_source_snippets_merge (GbSourceSnippets *snippets,
snippets->priv->snippets);
}
-gboolean
-gb_source_snippets_load_from_file (GbSourceSnippets *snippets,
- GFile *file,
- GError **error)
-{
- GbSourceSnippetParser *parser;
- GList *iter;
-
- g_return_val_if_fail (GB_IS_SOURCE_SNIPPETS (snippets), FALSE);
- g_return_val_if_fail (G_IS_FILE (file), FALSE);
-
- parser = gb_source_snippet_parser_new ();
- if (!gb_source_snippet_parser_load_from_file (parser, file, error))
- {
- g_object_unref (parser);
- return FALSE;
- }
-
- iter = gb_source_snippet_parser_get_snippets (parser);
- for (; iter; iter = iter->next)
- gb_source_snippets_add (snippets, iter->data);
-
- g_object_unref (parser);
-
- return TRUE;
-}
-
void
gb_source_snippets_add (GbSourceSnippets *snippets,
GbSourceSnippet *snippet)
diff --git a/src/snippets/gb-source-snippets.h b/src/snippets/gb-source-snippets.h
index c3aef93..f52580a 100644
--- a/src/snippets/gb-source-snippets.h
+++ b/src/snippets/gb-source-snippets.h
@@ -57,9 +57,6 @@ void gb_source_snippets_merge (GbSourceSnippets *snippets,
GbSourceSnippets *other);
GbSourceSnippets *gb_source_snippets_new (void);
GType gb_source_snippets_get_type (void);
-gboolean gb_source_snippets_load_from_file (GbSourceSnippets *snippets,
- GFile *file,
- GError **error);
void gb_source_snippets_foreach (GbSourceSnippets *snippets,
const gchar *prefix,
GFunc foreach_func,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]