[gtksourceview/wip/chergert/snippets] view: add GtkSourceView:enable-snippets property
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/wip/chergert/snippets] view: add GtkSourceView:enable-snippets property
- Date: Wed, 29 Jan 2020 04:53:05 +0000 (UTC)
commit 759d6aa67b9eabecbf6fbf0b7b9f0658ca28e0a1
Author: Christian Hergert <chergert redhat com>
Date: Tue Jan 28 20:52:38 2020 -0800
view: add GtkSourceView:enable-snippets property
gtksourceview/gtksourceview-snippets.c | 5 ++
gtksourceview/gtksourceview.c | 88 ++++++++++++++++++++++++++++++++++
gtksourceview/gtksourceview.h | 5 ++
3 files changed, 98 insertions(+)
---
diff --git a/gtksourceview/gtksourceview-snippets.c b/gtksourceview/gtksourceview-snippets.c
index 899eba61..f09a2fcd 100644
--- a/gtksourceview/gtksourceview-snippets.c
+++ b/gtksourceview/gtksourceview-snippets.c
@@ -409,6 +409,11 @@ _gtk_source_view_snippets_key_pressed (GtkSourceViewSnippets *snippets,
return FALSE;
}
+ if (!gtk_source_view_get_enable_snippets (snippets->view))
+ {
+ return FALSE;
+ }
+
/* Be careful when testing for modifier state equality:
* caps lock, num lock,etc need to be taken into account */
modifiers = gtk_accelerator_get_default_mod_mask ();
diff --git a/gtksourceview/gtksourceview.c b/gtksourceview/gtksourceview.c
index 4fc67886..2f4ede8b 100644
--- a/gtksourceview/gtksourceview.c
+++ b/gtksourceview/gtksourceview.c
@@ -183,6 +183,7 @@ enum
PROP_BACKGROUND_PATTERN,
PROP_SMART_BACKSPACE,
PROP_SPACE_DRAWER,
+ PROP_ENABLE_SNIPPETS,
N_PROPS
};
@@ -233,6 +234,7 @@ typedef struct
guint indent_on_tab : 1;
guint show_right_margin : 1;
guint smart_backspace : 1;
+ guint enable_snippets : 1;
} GtkSourceViewPrivate;
typedef struct
@@ -728,6 +730,28 @@ gtk_source_view_class_init (GtkSourceViewClass *klass)
(G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
+ /**
+ * GtkSourceView:enable-snippets:
+ *
+ * The "enable-snippets" property denotes if snippets should be
+ * expanded when the user presses Tab after having typed a word
+ * matching the snippets found in #GtkSourceSnippetManager.
+ *
+ * The user may tab through focus-positions of the snippet if any
+ * are available by pressing Tab repeatedly until the desired focus
+ * position is selected.
+ *
+ * Since: 5.0
+ */
+ properties [PROP_ENABLE_SNIPPETS] =
+ g_param_spec_boolean ("enable-snippets",
+ "Enable Snippets",
+ "Whether to enable snippet expansion",
+ FALSE,
+ (G_PARAM_READWRITE |
+ G_PARAM_EXPLICIT_NOTIFY |
+ G_PARAM_STATIC_STRINGS));
+
g_object_class_install_properties (object_class, N_PROPS, properties);
/**
@@ -1225,6 +1249,10 @@ gtk_source_view_set_property (GObject *object,
gtk_source_view_set_smart_backspace (view, g_value_get_boolean (value));
break;
+ case PROP_ENABLE_SNIPPETS:
+ gtk_source_view_set_enable_snippets (view, g_value_get_boolean (value));
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -1305,6 +1333,10 @@ gtk_source_view_get_property (GObject *object,
g_value_set_object (value, gtk_source_view_get_space_drawer (view));
break;
+ case PROP_ENABLE_SNIPPETS:
+ g_value_set_boolean (value, gtk_source_view_get_enable_snippets (view));
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -5089,3 +5121,59 @@ gtk_source_view_push_snippet (GtkSourceView *view,
g_signal_emit (view, signals [PUSH_SNIPPET], 0, snippet, location);
}
+
+/**
+ * gtk_source_view_get_enable_snippets:
+ * @self: a #GtkSourceView
+ *
+ * Gets the #GtkSourceView:enable-snippets property.
+ *
+ * If %TRUE, matching snippets found in the #GtkSourceSnippetManager
+ * may be expanded when the user presses Tab after a word in the
+ * #GtkSourceView.
+ *
+ * Returns: %TRUE if enabled
+ *
+ * Since: 5.0
+ */
+gboolean
+gtk_source_view_get_enable_snippets (GtkSourceView *view)
+{
+ GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
+
+ g_return_val_if_fail (GTK_SOURCE_IS_VIEW (view), FALSE);
+
+ return priv->enable_snippets;
+}
+
+/**
+ * gtk_source_view_set_enable_snippets:
+ * @self: a #GtkSourceView
+ * @enable_snippets: if snippets should be enabled
+ *
+ * Sets the #GtkSourceView:enable-snippets property.
+ *
+ * If @enable_snippets is %TRUE, matching snippets found in the
+ * #GtkSourceSnippetManager may be expanded when the user presses
+ * Tab after a word in the #GtkSourceView.
+ *
+ * Since: 5.0
+ */
+void
+gtk_source_view_set_enable_snippets (GtkSourceView *view,
+ gboolean enable_snippets)
+{
+ GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
+
+ g_return_if_fail (GTK_SOURCE_IS_VIEW (view));
+
+ enable_snippets = !!enable_snippets;
+
+ if (enable_snippets != priv->enable_snippets)
+ {
+ priv->enable_snippets = enable_snippets;
+ _gtk_source_view_snippets_pop_all (&priv->snippets);
+ g_object_notify_by_pspec (G_OBJECT (view),
+ properties [PROP_ENABLE_SNIPPETS]);
+ }
+}
diff --git a/gtksourceview/gtksourceview.h b/gtksourceview/gtksourceview.h
index 367e8b2c..4b448722 100644
--- a/gtksourceview/gtksourceview.h
+++ b/gtksourceview/gtksourceview.h
@@ -186,6 +186,11 @@ void gtk_source_view_set_smart_home_end
GTK_SOURCE_AVAILABLE_IN_ALL
GtkSourceSmartHomeEndType gtk_source_view_get_smart_home_end (GtkSourceView
*view);
GTK_SOURCE_AVAILABLE_IN_ALL
+void gtk_source_view_set_enable_snippets (GtkSourceView
*view,
+ gboolean
enable_snippets);
+GTK_SOURCE_AVAILABLE_IN_ALL
+gboolean gtk_source_view_get_enable_snippets (GtkSourceView
*view);
+GTK_SOURCE_AVAILABLE_IN_ALL
guint gtk_source_view_get_visual_column (GtkSourceView
*view,
const GtkTextIter
*iter);
GTK_SOURCE_AVAILABLE_IN_ALL
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]