[gnome-builder] snippets: ensure GbSourceSnippet knows about tab_width.
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] snippets: ensure GbSourceSnippet knows about tab_width.
- Date: Mon, 8 Sep 2014 01:51:04 +0000 (UTC)
commit 2725118cde1fa85cde936ed4653ab52ea71cef1e
Author: Christian Hergert <christian hergert me>
Date: Sun Sep 7 18:50:56 2014 -0700
snippets: ensure GbSourceSnippet knows about tab_width.
src/editor/gb-source-snippet.c | 43 ++++++++++++++++++++++++++++++++++++++++
src/editor/gb-source-snippet.h | 3 ++
src/editor/gb-source-view.c | 4 +++
3 files changed, 50 insertions(+), 0 deletions(-)
---
diff --git a/src/editor/gb-source-snippet.c b/src/editor/gb-source-snippet.c
index 1cd3aaf..18bd009 100644
--- a/src/editor/gb-source-snippet.c
+++ b/src/editor/gb-source-snippet.c
@@ -38,6 +38,7 @@ struct _GbSourceSnippetPrivate
gint tab_stop;
gint max_tab_stop;
gint current_chunk;
+ guint tab_width;
guint inserted : 1;
guint insert_spaces_instead_of_tabs : 1;
};
@@ -49,6 +50,7 @@ enum {
PROP_MARK_BEGIN,
PROP_MARK_END,
PROP_TAB_STOP,
+ PROP_TAB_WIDTH,
PROP_TRIGGER,
LAST_PROP
};
@@ -102,6 +104,26 @@ gb_source_snippet_copy (GbSourceSnippet *snippet)
RETURN (ret);
}
+guint
+gb_source_snippet_get_tab_width (GbSourceSnippet *snippet)
+{
+ g_return_val_if_fail (GB_IS_SOURCE_SNIPPET (snippet), 0);
+
+ return snippet->priv->tab_width;
+}
+
+void
+gb_source_snippet_set_tab_width (GbSourceSnippet *snippet,
+ guint tab_width)
+{
+ g_return_if_fail (GB_IS_SOURCE_SNIPPET (snippet));
+ g_return_if_fail (tab_width > 0);
+ g_return_if_fail (tab_width <= 32);
+
+ snippet->priv->tab_width = tab_width;
+ g_object_notify_by_pspec (G_OBJECT (snippet), gParamSpecs [PROP_TAB_WIDTH]);
+}
+
gboolean
gb_source_snippet_get_insert_spaces_instead_of_tabs (GbSourceSnippet *snippet)
{
@@ -939,6 +961,10 @@ gb_source_snippet_get_property (GObject *object,
g_value_set_uint (value, snippet->priv->tab_stop);
break;
+ case PROP_TAB_WIDTH:
+ g_value_set_uint (value, snippet->priv->tab_width);
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
@@ -959,6 +985,10 @@ gb_source_snippet_set_property (GObject *object,
g_value_get_boolean (value));
break;
+ case PROP_TAB_WIDTH:
+ gb_source_snippet_set_tab_width (snippet, g_value_get_uint (value));
+ break;
+
case PROP_TRIGGER:
gb_source_snippet_set_trigger (snippet, g_value_get_string (value));
break;
@@ -1037,6 +1067,17 @@ gb_source_snippet_class_init (GbSourceSnippetClass *klass)
g_object_class_install_property (object_class, PROP_TAB_STOP,
gParamSpecs[PROP_TAB_STOP]);
+ gParamSpecs [PROP_TAB_WIDTH] =
+ g_param_spec_uint ("tab-width",
+ _("Tab Width"),
+ _("Tab Width in Spaces"),
+ 1,
+ 32,
+ 2,
+ (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property (object_class, PROP_TAB_WIDTH,
+ gParamSpecs [PROP_TAB_WIDTH]);
+
EXIT;
}
@@ -1047,6 +1088,8 @@ gb_source_snippet_init (GbSourceSnippet *snippet)
snippet->priv = gb_source_snippet_get_instance_private (snippet);
+ snippet->priv->insert_spaces_instead_of_tabs = FALSE;
+ snippet->priv->tab_width = 2;
snippet->priv->tab_stop = 0;
snippet->priv->max_tab_stop = -1;
snippet->priv->chunks = g_ptr_array_new_with_free_func (g_object_unref);
diff --git a/src/editor/gb-source-snippet.h b/src/editor/gb-source-snippet.h
index c4588e9..adb8c2a 100644
--- a/src/editor/gb-source-snippet.h
+++ b/src/editor/gb-source-snippet.h
@@ -73,6 +73,9 @@ GbSourceSnippetContext *gb_source_snippet_get_context (GbSourceSnippet
void gb_source_snippet_set_insert_spaces_instead_of_tabs
(GbSourceSnippet *snippet,
gboolean
insert_spaces_instead_of_tabs);
+guint gb_source_snippet_get_tab_width (GbSourceSnippet *snippet);
+void gb_source_snippet_set_tab_width (GbSourceSnippet *snippet,
+ guint tab_width);
G_END_DECLS
diff --git a/src/editor/gb-source-view.c b/src/editor/gb-source-view.c
index bc0680a..349ebe8 100644
--- a/src/editor/gb-source-view.c
+++ b/src/editor/gb-source-view.c
@@ -369,6 +369,7 @@ gb_source_view_push_snippet (GbSourceView *view,
gboolean has_more_tab_stops;
gboolean insert_spaces;
gchar *name;
+ guint tab_width;
g_return_if_fail (GB_IS_SOURCE_VIEW (view));
g_return_if_fail (GB_IS_SOURCE_SNIPPET (snippet));
@@ -389,6 +390,9 @@ gb_source_view_push_snippet (GbSourceView *view,
insert_spaces = gtk_source_view_get_insert_spaces_instead_of_tabs (GTK_SOURCE_VIEW (view));
gb_source_snippet_set_insert_spaces_instead_of_tabs (snippet, insert_spaces);
+ tab_width = gtk_source_view_get_tab_width (GTK_SOURCE_VIEW (view));
+ gb_source_snippet_set_tab_width (snippet, tab_width);
+
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
mark = gtk_text_buffer_get_insert (buffer);
gtk_text_buffer_get_iter_at_mark (buffer, &iter, mark);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]