summaryrefslogtreecommitdiff
path: root/pluma/pluma-view.c
diff options
context:
space:
mode:
authorGoffredo Baroncelli <[email protected]>2019-06-15 17:52:01 +0200
committerVictor Kareh <[email protected]>2019-06-28 08:38:58 -0400
commitc264b0d7b6782a596c6502edc158f754ed968835 (patch)
tree76d0b874925f026f26c55883b0bed38d4cd60a3c /pluma/pluma-view.c
parentdee5500dd7d1ca8b6b9ef2c25af658bb9c839262 (diff)
downloadpluma-c264b0d7b6782a596c6502edc158f754ed968835.tar.bz2
pluma-c264b0d7b6782a596c6502edc158f754ed968835.tar.xz
Draw spaces, tabs, newlines and nbsp.
Via gsettings it is possible to enable the drawing of: - newline (enable-space-drawer-newline) - spaces (enable-space-drawer-space) - tab (enable-space-drawer-tab) - not blank space (enable-space-drawer-nbsp) The first setting is a boolean ones, so the only allowable values are true (show the symbol) or false (don't show the symbol). Instead for the last three settings, the allowed values are: 'draw-none' -> show nothing 'draw-all' -> show all spaces/tabs 'draw-trailing' -> show only the trailing spaces/tabs (only if GTK >= 3.24)
Diffstat (limited to 'pluma/pluma-view.c')
-rw-r--r--pluma/pluma-view.c83
1 files changed, 83 insertions, 0 deletions
diff --git a/pluma/pluma-view.c b/pluma/pluma-view.c
index 891abb59..ed146b21 100644
--- a/pluma/pluma-view.c
+++ b/pluma/pluma-view.c
@@ -372,6 +372,87 @@ on_notify_buffer_cb (PlumaView *view,
view);
}
+#ifdef GTK_SOURCE_VERSION_3_24
+void
+pluma_set_source_space_drawer_by_level (GtkSourceView *view,
+ gint level,
+ GtkSourceSpaceTypeFlags type)
+{
+ GtkSourceSpaceLocationFlags locs[] = {GTK_SOURCE_SPACE_LOCATION_LEADING,
+ GTK_SOURCE_SPACE_LOCATION_INSIDE_TEXT,
+ GTK_SOURCE_SPACE_LOCATION_TRAILING};
+ /* this array links the level to the location */
+ GtkSourceSpaceLocationFlags levels[] = {
+ 0,
+ GTK_SOURCE_SPACE_LOCATION_TRAILING,
+ GTK_SOURCE_SPACE_LOCATION_INSIDE_TEXT |
+ GTK_SOURCE_SPACE_LOCATION_TRAILING |
+ GTK_SOURCE_SPACE_LOCATION_LEADING
+ };
+
+ gint i;
+
+ GtkSourceSpaceDrawer *drawer = gtk_source_view_get_space_drawer (view);
+
+ if (level >= G_N_ELEMENTS(levels) || level < 0)
+ level = 0;
+
+ for (i = 0 ; i < G_N_ELEMENTS(locs) ; i++ ) {
+ GtkSourceSpaceTypeFlags f;
+ f = gtk_source_space_drawer_get_types_for_locations (drawer,
+ locs[i]);
+ if (locs[i] & levels[level])
+ f |= type;
+ else
+ f &= ~type;
+ gtk_source_space_drawer_set_types_for_locations (drawer, locs[i], f);
+ }
+}
+#endif
+
+#ifdef GTK_SOURCE_VERSION_3_24
+static void
+pluma_set_source_space_drawer (GtkSourceView *view)
+{
+ pluma_set_source_space_drawer_by_level (view,
+ pluma_prefs_manager_get_draw_spaces (),
+ GTK_SOURCE_SPACE_TYPE_SPACE);
+ pluma_set_source_space_drawer_by_level (view,
+ pluma_prefs_manager_get_draw_tabs (),
+ GTK_SOURCE_SPACE_TYPE_TAB);
+ pluma_set_source_space_drawer_by_level (view,
+ pluma_prefs_manager_get_draw_newlines () ? 2 : 0,
+ GTK_SOURCE_SPACE_TYPE_NEWLINE);
+ pluma_set_source_space_drawer_by_level (view,
+ pluma_prefs_manager_get_draw_nbsp (),
+ GTK_SOURCE_SPACE_TYPE_NBSP);
+ gtk_source_space_drawer_set_enable_matrix (gtk_source_view_get_space_drawer (view),
+ TRUE);
+
+}
+#else
+static void
+pluma_set_source_space_drawer (GtkSourceView *view)
+{
+ GtkSourceSpaceTypeFlags flags = 0;
+
+ if (pluma_prefs_manager_get_draw_spaces () > 0)
+ flags |= GTK_SOURCE_DRAW_SPACES_SPACE;
+ if (pluma_prefs_manager_get_draw_tabs () > 0)
+ flags |= GTK_SOURCE_DRAW_SPACES_TAB;
+ if (pluma_prefs_manager_get_draw_newlines ())
+ flags |= GTK_SOURCE_DRAW_SPACES_NEWLINE;
+ if (pluma_prefs_manager_get_draw_nbsp () > 0)
+ flags |= GTK_SOURCE_DRAW_SPACES_NBSP;
+
+ flags |= GTK_SOURCE_DRAW_SPACES_TRAILING |
+ GTK_SOURCE_DRAW_SPACES_TEXT |
+ GTK_SOURCE_DRAW_SPACES_LEADING;
+
+ gtk_source_view_set_draw_spaces (view, flags);
+}
+#endif
+
static void
pluma_view_init (PlumaView *view)
{
@@ -413,6 +494,8 @@ pluma_view_init (PlumaView *view)
"indent_on_tab", TRUE,
NULL);
+ pluma_set_source_space_drawer(GTK_SOURCE_VIEW (view));
+
view->priv->typeselect_flush_timeout = 0;
view->priv->wrap_around = TRUE;