Commit 416a65af authored by Christian Hergert's avatar Christian Hergert
Browse files

page: add support for drawing spaces

This does not currently have UI exposed, but the GSetting is there for
those that want to enable it that way.

You can do something like:

  gsettings set org.gnome.TextEditor draw-spaces "['tab','space']"

The flags you can enable:

  * space
  * tab (\t)
  * newline (\n)
  * nbsp (non-breaking space)
  * leading (leading text on line)
  * text (only within text)
  * trailing (trailing text in line)

Fixes #150
parent cb7bbfe5
Pipeline #338657 passed with stages
in 3 minutes and 43 seconds
<?xml version="1.0" encoding="UTF-8"?>
<schemalist gettext-domain="gnome-text-editor">
<flags id="org.gnome.TextEditor.DrawSpaces">
<value nick="space" value="1"/>
<value nick="tab" value="2"/>
<value nick="newline" value="4"/>
<value nick="nbsp" value="8"/>
<value nick="leading" value="16"/>
<value nick="text" value="32"/>
<value nick="trailing" value="64"/>
</flags>
<schema id="org.gnome.TextEditor" path="/org/gnome/TextEditor/">
<key name="auto-save-delay" type="u">
<range min="1" max="300"/>
......@@ -128,5 +137,10 @@
<summary>Last Save Directory</summary>
<description>The directory last used in a save or save-as dialog.</description>
</key>
<key name="draw-spaces" flags="org.gnome.TextEditor.DrawSpaces">
<default>[]</default>
<summary>Draw Spaces</summary>
<description>The various types of spaces to draw in the editor.</description>
</key>
</schema>
</schemalist>
......@@ -52,6 +52,65 @@ G_DEFINE_TYPE (EditorPage, editor_page, GTK_TYPE_WIDGET)
static GParamSpec *properties [N_PROPS];
static void
on_draw_spaces_changed (EditorPage *self,
const gchar *key,
GSettings *settings)
{
GtkSourceSpaceLocationFlags location_flags = GTK_SOURCE_SPACE_LOCATION_NONE;
GtkSourceSpaceTypeFlags type_flags = GTK_SOURCE_SPACE_TYPE_NONE;
GtkSourceView *source_view;
GtkSourceSpaceDrawer *drawer;
guint flags;
g_assert (EDITOR_IS_PAGE (self));
g_assert (g_strcmp0 (key, "draw-spaces") == 0);
g_assert (G_IS_SETTINGS (settings));
source_view = GTK_SOURCE_VIEW (self->view);
drawer = gtk_source_view_get_space_drawer (source_view);
flags = g_settings_get_flags (settings, "draw-spaces");
if (flags == 0)
{
gtk_source_space_drawer_set_enable_matrix (drawer, FALSE);
return;
}
/* Reset the matrix before setting it */
gtk_source_space_drawer_set_types_for_locations (drawer, GTK_SOURCE_SPACE_LOCATION_ALL, GTK_SOURCE_SPACE_TYPE_NONE);
if (flags & 1)
type_flags |= GTK_SOURCE_SPACE_TYPE_SPACE;
if (flags & 2)
type_flags |= GTK_SOURCE_SPACE_TYPE_TAB;
if (flags & 4)
{
gtk_source_space_drawer_set_types_for_locations (drawer, GTK_SOURCE_SPACE_LOCATION_ALL, GTK_SOURCE_SPACE_TYPE_NEWLINE);
type_flags |= GTK_SOURCE_SPACE_TYPE_NEWLINE;
}
if (flags & 8)
type_flags |= GTK_SOURCE_SPACE_TYPE_NBSP;
if (flags & 16)
location_flags |= GTK_SOURCE_SPACE_LOCATION_LEADING;
if (flags & 32)
location_flags |= GTK_SOURCE_SPACE_LOCATION_INSIDE_TEXT;
if (flags & 64)
location_flags |= GTK_SOURCE_SPACE_LOCATION_TRAILING;
if (type_flags > 0 && location_flags == 0)
location_flags |= GTK_SOURCE_SPACE_LOCATION_ALL;
gtk_source_space_drawer_set_enable_matrix (drawer, TRUE);
gtk_source_space_drawer_set_types_for_locations (drawer, location_flags, type_flags);
}
static void
editor_page_set_settings (EditorPage *self,
EditorPageSettings *settings)
......@@ -278,6 +337,7 @@ static void
editor_page_constructed (GObject *object)
{
EditorPage *self = (EditorPage *)object;
EditorApplication *app;
g_assert (EDITOR_IS_PAGE (self));
......@@ -347,6 +407,15 @@ editor_page_constructed (GObject *object)
editor_page_document_notify_busy_cb (self, NULL, self->document);
editor_page_document_notify_language_cb (self, NULL, self->document);
/* Setup spaces drawing */
app = EDITOR_APPLICATION (g_application_get_default ());
g_signal_connect_object (app->settings,
"changed::draw-spaces",
G_CALLBACK (on_draw_spaces_changed),
self,
G_CONNECT_SWAPPED);
on_draw_spaces_changed (self, "draw-spaces", app->settings);
_editor_page_vim_init (self);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment