[gnome-builder] snippets: add snippet's description support
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] snippets: add snippet's description support
- Date: Sun, 11 Jan 2015 08:11:16 +0000 (UTC)
commit 24679e955f19057af53a058aaec1a5d1c2465920
Author: Roberto Majadas <roberto majadas openshine com>
Date: Sun Jan 11 01:52:38 2015 +0100
snippets: add snippet's description support
src/snippets/gb-source-snippet-completion-item.c | 11 +++++-
src/snippets/gb-source-snippet-parser.c | 36 ++++++++++++++++++-
src/snippets/gb-source-snippet.c | 42 ++++++++++++++++++++++
src/snippets/gb-source-snippet.h | 3 ++
4 files changed, 89 insertions(+), 3 deletions(-)
---
diff --git a/src/snippets/gb-source-snippet-completion-item.c
b/src/snippets/gb-source-snippet-completion-item.c
index 7b03fb5..45a4a75 100644
--- a/src/snippets/gb-source-snippet-completion-item.c
+++ b/src/snippets/gb-source-snippet-completion-item.c
@@ -150,11 +150,18 @@ get_label (GtkSourceCompletionProposal *p)
{
GbSourceSnippetCompletionItem *item = GB_SOURCE_SNIPPET_COMPLETION_ITEM (p);
const gchar *trigger = NULL;
+ const gchar *description = NULL;
if (item->priv->snippet)
- trigger = gb_source_snippet_get_trigger (item->priv->snippet);
+ {
+ trigger = gb_source_snippet_get_trigger (item->priv->snippet);
+ description = gb_source_snippet_get_description (item->priv->snippet);
+ }
- return g_strdup (trigger);
+ if (description)
+ return g_strdup_printf ("%s: %s", trigger, description);
+ else
+ return g_strdup(trigger);
}
static GdkPixbuf *
diff --git a/src/snippets/gb-source-snippet-parser.c b/src/snippets/gb-source-snippet-parser.c
index a47ad29..f82417e 100644
--- a/src/snippets/gb-source-snippet-parser.c
+++ b/src/snippets/gb-source-snippet-parser.c
@@ -35,6 +35,7 @@ struct _GbSourceSnippetParserPrivate
GList *chunks;
GList *scope;
gchar *cur_name;
+ gchar *cur_desc;
GString *cur_text;
};
@@ -72,6 +73,8 @@ gb_source_snippet_parser_store (GbSourceSnippetParser *parser)
{
snippet = gb_source_snippet_new (priv->cur_name,
g_strdup(scope_iter->data));
+ gb_source_snippet_set_description(snippet, priv->cur_desc);
+
for (chunck_iter = priv->chunks; chunck_iter; chunck_iter = chunck_iter->next)
{
#if 0
@@ -108,6 +111,9 @@ gb_source_snippet_parser_finish (GbSourceSnippetParser *parser)
g_list_free_full(priv->scope, g_free);
priv->scope = NULL;
+
+ g_free(priv->cur_desc);
+ priv->cur_desc = NULL;
}
static void
@@ -396,6 +402,21 @@ gb_source_snippet_parser_do_snippet_scope (GbSourceSnippetParser *parser,
}
static void
+gb_source_snippet_parser_do_snippet_description (GbSourceSnippetParser *parser,
+ const gchar *line)
+{
+ GbSourceSnippetParserPrivate *priv = parser->priv;
+
+ if (priv->cur_desc)
+ {
+ g_free(priv->cur_desc);
+ priv->cur_desc = NULL;
+ }
+
+ priv->cur_desc = g_strstrip (g_strdup (&line[7]));
+}
+
+static void
gb_source_snippet_parser_feed_line (GbSourceSnippetParser *parser,
gchar *basename,
const gchar *line)
@@ -471,6 +492,12 @@ gb_source_snippet_parser_feed_line (GbSourceSnippetParser *parser,
break;
}
+ if (g_str_has_prefix(line, "- desc"))
+ {
+ gb_source_snippet_parser_do_snippet_description (parser, line);
+ break;
+ }
+
/* Fall through */
default:
g_warning (_("Invalid snippet at line %d: %s"), priv->lineno, line);
@@ -558,6 +585,12 @@ gb_source_snippet_parser_finalize (GObject *object)
g_free (priv->cur_name);
priv->cur_name = NULL;
+ if (priv->cur_desc)
+ {
+ g_free (priv->cur_desc);
+ priv->cur_desc = NULL;
+ }
+
G_OBJECT_CLASS (gb_source_snippet_parser_parent_class)->finalize (object);
}
@@ -581,4 +614,5 @@ gb_source_snippet_parser_init (GbSourceSnippetParser *parser)
parser->priv->lineno = -1;
parser->priv->cur_text = g_string_new (NULL);
parser->priv->scope = NULL;
-}
+ parser->priv->cur_desc = NULL;
+}
\ No newline at end of file
diff --git a/src/snippets/gb-source-snippet.c b/src/snippets/gb-source-snippet.c
index 6870c7a..2f66c4f 100644
--- a/src/snippets/gb-source-snippet.c
+++ b/src/snippets/gb-source-snippet.c
@@ -36,6 +36,7 @@ struct _GbSourceSnippetPrivate
GtkTextMark *mark_end;
gchar *trigger;
gchar *language;
+ gchar *description;
gint tab_stop;
gint max_tab_stop;
gint current_chunk;
@@ -50,6 +51,7 @@ enum {
PROP_TAB_STOP,
PROP_TRIGGER,
PROP_LANGUAGE,
+ PROP_DESCRIPTION,
LAST_PROP
};
@@ -87,6 +89,7 @@ gb_source_snippet_copy (GbSourceSnippet *snippet)
ret = g_object_new (GB_TYPE_SOURCE_SNIPPET,
"trigger", snippet->priv->trigger,
"language", snippet->priv->language,
+ "description", snippet->priv->description,
NULL);
for (i = 0; i < priv->chunks->len; i++)
@@ -163,6 +166,24 @@ gb_source_snippet_set_language (GbSourceSnippet *snippet,
snippet->priv->language = g_strdup (language);
}
+const gchar *
+gb_source_snippet_get_description (GbSourceSnippet *snippet)
+{
+ g_return_val_if_fail (GB_IS_SOURCE_SNIPPET (snippet), NULL);
+
+ return snippet->priv->description;
+}
+
+void
+gb_source_snippet_set_description (GbSourceSnippet *snippet,
+ const gchar *description)
+{
+ g_return_if_fail (GB_IS_SOURCE_SNIPPET (snippet));
+
+ g_free (snippet->priv->description);
+ snippet->priv->description = g_strdup (description);
+}
+
static gint
gb_source_snippet_get_offset (GbSourceSnippet *snippet,
GtkTextIter *iter)
@@ -903,6 +924,9 @@ gb_source_snippet_dispose (GObject *object)
g_clear_object (&priv->buffer);
g_clear_object (&priv->context);
+
+ g_free(priv->language);
+ g_free(priv->description);
}
static void
@@ -941,6 +965,10 @@ gb_source_snippet_get_property (GObject *object,
g_value_set_string (value, snippet->priv->language);
break;
+ case PROP_DESCRIPTION:
+ g_value_set_string (value, snippet->priv->description);
+ break;
+
case PROP_TAB_STOP:
g_value_set_uint (value, snippet->priv->tab_stop);
break;
@@ -968,6 +996,10 @@ gb_source_snippet_set_property (GObject *object,
gb_source_snippet_set_language (snippet, g_value_get_string (value));
break;
+ case PROP_DESCRIPTION:
+ gb_source_snippet_set_description (snippet, g_value_get_string (value));
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
@@ -1031,6 +1063,15 @@ gb_source_snippet_class_init (GbSourceSnippetClass *klass)
g_object_class_install_property (object_class, PROP_LANGUAGE,
gParamSpecs[PROP_LANGUAGE]);
+ gParamSpecs[PROP_DESCRIPTION] =
+ g_param_spec_string ("description",
+ _("Description"),
+ _("The description for the snippet."),
+ NULL,
+ (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property (object_class, PROP_DESCRIPTION,
+ gParamSpecs[PROP_DESCRIPTION]);
+
gParamSpecs[PROP_TAB_STOP] =
g_param_spec_int ("tab-stop",
_("Tab Stop"),
@@ -1054,4 +1095,5 @@ gb_source_snippet_init (GbSourceSnippet *snippet)
snippet->priv->max_tab_stop = -1;
snippet->priv->chunks = g_ptr_array_new_with_free_func (g_object_unref);
snippet->priv->runs = g_array_new (FALSE, FALSE, sizeof (gint));
+ snippet->priv->description = NULL;
}
diff --git a/src/snippets/gb-source-snippet.h b/src/snippets/gb-source-snippet.h
index 8b023ae..d70a5c1 100644
--- a/src/snippets/gb-source-snippet.h
+++ b/src/snippets/gb-source-snippet.h
@@ -61,6 +61,9 @@ void gb_source_snippet_set_trigger (GbSourceSnippet
const gchar *gb_source_snippet_get_language (GbSourceSnippet *snippet);
void gb_source_snippet_set_language (GbSourceSnippet *snippet,
const gchar *language);
+const gchar *gb_source_snippet_get_description (GbSourceSnippet *snippet);
+void gb_source_snippet_set_description (GbSourceSnippet *snippet,
+ const gchar *description);
void gb_source_snippet_add_chunk (GbSourceSnippet *snippet,
GbSourceSnippetChunk *chunk);
guint gb_source_snippet_get_n_chunks (GbSourceSnippet *snippet);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]