diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..0c33e84
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,13 @@
+# Specify filepatterns you want git to ignore.
+debian/tmp/
+debian/build/
+debian/.debhelper/
+debian/xed/
+debian/xed-common/
+debian/xed-dbg/
+debian/xed-dev/
+debian/xed-doc/
+debian/files
+debian/*.log
+debian/*.substvars
+build
diff --git a/README b/README
index 8c1bd70..ebae1ce 100644
--- a/README
+++ b/README
@@ -35,7 +35,9 @@ Installation
Simple install procedure:
- % meson . build # run the `configure' script
- % ninja -v -C build # build xed
+ % meson --prefix=/usr/local build # run the `configure' script
+ % ninja -v -C build # build xed
[ Become root if necessary ]
- % ninja install -v -C build # install xed
+ % sudo ninja install -v -C build # install xed
+
+ see linuxmint/xed#265 if you see GLib-GIO-ERROR
diff --git a/data/org.x.editor.gschema.xml.in b/data/org.x.editor.gschema.xml.in
index ebaf070..c435b64 100644
--- a/data/org.x.editor.gschema.xml.in
+++ b/data/org.x.editor.gschema.xml.in
@@ -167,6 +167,36 @@
Whether xed will ensure that documents always end with a trailing newline.
+
+ false
+ Draw whitespace
+ Whether xed should render whitespace
+
+
+
+ false
+ Draw leading whitespace
+ Whether xed should render leading whitespace
+
+
+
+ false
+ Draw whitespace within text
+ Whether xed should render whitespace between words and characters
+
+
+
+ false
+ Draw trailing whitespace
+ Whether xed should render trailing whitespace
+
+
+
+ false
+ Draw newline characters
+ Whether xed should render newline characters
+
+
diff --git a/debian/changelog b/debian/changelog
index 04bbc6a..39968da 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
+xed (2.4.3) tricia; urgency=medium
+
+ [ okaestne ] [backported by wolfpackmars2]
+ * Implement #225: Options to render whitespace
+ * backported from xed-3
+
xed (2.4.2) tricia; urgency=medium
* l10n: Update translations
diff --git a/meson.build b/meson.build
index b06f0d0..29d097f 100644
--- a/meson.build
+++ b/meson.build
@@ -1,4 +1,4 @@
-project('xed', 'c', version : '2.4.2')
+project('xed', 'c', version : '2.4.3')
gnome = import('gnome')
i18n = import('i18n')
diff --git a/xed/resources/ui/xed-preferences-dialog.ui b/xed/resources/ui/xed-preferences-dialog.ui
index 53c1f53..71e5afe 100755
--- a/xed/resources/ui/xed-preferences-dialog.ui
+++ b/xed/resources/ui/xed-preferences-dialog.ui
@@ -1,5 +1,5 @@
-
+
@@ -309,6 +309,210 @@
3
+
+
+
+ False
+ True
+ 5
+
+
+
+
+ True
+ False
+ 175
+
+
+ True
+ False
+ 16
+ vertical
+
+
+ True
+ False
+ 6
+
+
+ True
+ False
+ Leading whitespace
+ 0
+
+
+ False
+ True
+ 0
+
+
+
+
+ True
+ True
+
+
+ False
+ True
+ end
+ 1
+
+
+
+
+ False
+ True
+ 0
+
+
+
+
+ True
+ False
+ 6
+
+
+ True
+ False
+ Trailing whitespace
+ 0
+
+
+ False
+ True
+ 0
+
+
+
+
+ True
+ True
+
+
+ False
+ True
+ end
+ 1
+
+
+
+
+ False
+ True
+ 1
+
+
+
+
+ True
+ False
+ 6
+
+
+ True
+ False
+ Whitespace inside of text
+ 0
+
+
+ False
+ True
+ 0
+
+
+
+
+ True
+ True
+
+
+ False
+ True
+ end
+ 1
+
+
+
+
+ False
+ True
+ 2
+
+
+
+
+ True
+ False
+ 6
+
+
+ True
+ False
+ Newline character
+ 0
+
+
+ False
+ True
+ 0
+
+
+
+
+ True
+ True
+
+
+ False
+ True
+ end
+ 1
+
+
+
+
+ False
+ True
+ 3
+
+
+
+
+
+
+ False
+ True
+ 6
+
+
False
diff --git a/xed/xed-preferences-dialog.c b/xed/xed-preferences-dialog.c
index e85b46d..b456817 100755
--- a/xed/xed-preferences-dialog.c
+++ b/xed/xed-preferences-dialog.c
@@ -98,6 +98,14 @@ struct _XedPreferencesDialog
GtkWidget *right_margin_spin;
GtkWidget *right_margin_revealer;
+ /* Draw whitespace */
+ GtkWidget *draw_whitespace_switch;
+ GtkWidget *draw_whitespace_revealer;
+ GtkWidget *draw_whitespace_leading_switch;
+ GtkWidget *draw_whitespace_trailing_switch;
+ GtkWidget *draw_whitespace_inside_switch;
+ GtkWidget *draw_whitespace_newline_switch;
+
/* Highlight current line */
GtkWidget *highlight_current_line_switch;
@@ -168,6 +176,12 @@ xed_preferences_dialog_class_init (XedPreferencesDialogClass *klass)
gtk_widget_class_bind_template_child (widget_class, XedPreferencesDialog, display_right_margin_switch);
gtk_widget_class_bind_template_child (widget_class, XedPreferencesDialog, right_margin_spin);
gtk_widget_class_bind_template_child (widget_class, XedPreferencesDialog, right_margin_revealer);
+ gtk_widget_class_bind_template_child (widget_class, XedPreferencesDialog, draw_whitespace_switch);
+ gtk_widget_class_bind_template_child (widget_class, XedPreferencesDialog, draw_whitespace_revealer);
+ gtk_widget_class_bind_template_child (widget_class, XedPreferencesDialog, draw_whitespace_leading_switch);
+ gtk_widget_class_bind_template_child (widget_class, XedPreferencesDialog, draw_whitespace_trailing_switch);
+ gtk_widget_class_bind_template_child (widget_class, XedPreferencesDialog, draw_whitespace_inside_switch);
+ gtk_widget_class_bind_template_child (widget_class, XedPreferencesDialog, draw_whitespace_newline_switch);
gtk_widget_class_bind_template_child (widget_class, XedPreferencesDialog, highlight_current_line_switch);
gtk_widget_class_bind_template_child (widget_class, XedPreferencesDialog, highlight_matching_bracket_switch);
gtk_widget_class_bind_template_child (widget_class, XedPreferencesDialog, tab_width_spin);
@@ -315,6 +329,43 @@ setup_editor_page (XedPreferencesDialog *dlg)
"value",
G_SETTINGS_BIND_GET | G_SETTINGS_BIND_SET);
+ /* whitespace */
+ g_settings_bind (dlg->editor_settings,
+ XED_SETTINGS_DRAW_WHITESPACE,
+ dlg->draw_whitespace_switch,
+ "active",
+ G_SETTINGS_BIND_GET | G_SETTINGS_BIND_SET);
+
+ g_object_bind_property (dlg->draw_whitespace_switch,
+ "active",
+ dlg->draw_whitespace_revealer,
+ "reveal-child",
+ G_BINDING_SYNC_CREATE | G_BINDING_DEFAULT);
+
+ g_settings_bind (dlg->editor_settings,
+ XED_SETTINGS_DRAW_WHITESPACE_LEADING,
+ dlg->draw_whitespace_leading_switch,
+ "active",
+ G_SETTINGS_BIND_GET | G_SETTINGS_BIND_SET);
+
+ g_settings_bind (dlg->editor_settings,
+ XED_SETTINGS_DRAW_WHITESPACE_TRAILING,
+ dlg->draw_whitespace_trailing_switch,
+ "active",
+ G_SETTINGS_BIND_GET | G_SETTINGS_BIND_SET);
+
+ g_settings_bind (dlg->editor_settings,
+ XED_SETTINGS_DRAW_WHITESPACE_INSIDE,
+ dlg->draw_whitespace_inside_switch,
+ "active",
+ G_SETTINGS_BIND_GET | G_SETTINGS_BIND_SET);
+
+ g_settings_bind (dlg->editor_settings,
+ XED_SETTINGS_DRAW_WHITESPACE_NEWLINE,
+ dlg->draw_whitespace_newline_switch,
+ "active",
+ G_SETTINGS_BIND_GET | G_SETTINGS_BIND_SET);
+
/* Highlighting */
g_settings_bind (dlg->editor_settings,
XED_SETTINGS_HIGHLIGHT_CURRENT_LINE,
diff --git a/xed/xed-settings.c b/xed/xed-settings.c
index ce9774f..2c46c99 100644
--- a/xed/xed-settings.c
+++ b/xed/xed-settings.c
@@ -333,6 +333,32 @@ on_max_recents_changed (GSettings *settings,
* update of the inline recents in the File menu */
}
+static void
+on_draw_whitespace_changed (GSettings *settings,
+ const gchar *key,
+ XedSettings *xs)
+{
+ GList *views;
+ gboolean draw_whitespace;
+
+ views = xed_app_get_views (XED_APP (g_application_get_default ()));
+ draw_whitespace = g_settings_get_boolean (settings, key);
+
+ g_list_foreach (views, (GFunc)xed_view_set_draw_whitespace, GINT_TO_POINTER (draw_whitespace));
+}
+
+static void
+on_draw_whitespace_locations_or_types_changed (GSettings *settings,
+ const gchar *key,
+ XedSettings *xs)
+{
+ GList *views;
+
+ views = xed_app_get_views (XED_APP (g_application_get_default ()));
+
+ g_list_foreach (views, (GFunc)xed_view_update_draw_whitespace_locations_and_types, NULL);
+}
+
static void
xed_settings_init (XedSettings *xs)
{
@@ -363,10 +389,20 @@ xed_settings_init (XedSettings *xs)
G_CALLBACK (on_auto_save_interval_changed), xs);
g_signal_connect (xs->priv->editor, "changed::syntax-highlighting",
G_CALLBACK (on_syntax_highlighting_changed), xs);
- g_signal_connect (xs->priv->ui, "changed::enable-tab-scrolling",
- G_CALLBACK (on_enable_tab_scrolling_changed), xs);
+ g_signal_connect (xs->priv->editor, "changed::draw-whitespace",
+ G_CALLBACK (on_draw_whitespace_changed), xs);
+ g_signal_connect (xs->priv->editor, "changed::draw-whitespace-leading",
+ G_CALLBACK (on_draw_whitespace_locations_or_types_changed), xs);
+ g_signal_connect (xs->priv->editor, "changed::draw-whitespace-trailing",
+ G_CALLBACK (on_draw_whitespace_locations_or_types_changed), xs);
+ g_signal_connect (xs->priv->editor, "changed::draw-whitespace-inside",
+ G_CALLBACK (on_draw_whitespace_locations_or_types_changed), xs);
+ g_signal_connect (xs->priv->editor, "changed::draw-whitespace-newline",
+ G_CALLBACK (on_draw_whitespace_locations_or_types_changed), xs);
/* ui changes */
+ g_signal_connect (xs->priv->ui, "changed::enable-tab-scrolling",
+ G_CALLBACK (on_enable_tab_scrolling_changed), xs);
g_signal_connect (xs->priv->ui, "changed::max-recents",
G_CALLBACK (on_max_recents_changed), xs);
}
diff --git a/xed/xed-settings.h b/xed/xed-settings.h
index 9114a33..8106ca5 100644
--- a/xed/xed-settings.h
+++ b/xed/xed-settings.h
@@ -88,6 +88,11 @@ void xed_settings_set_list (GSettings *settings,
#define XED_SETTINGS_BRACKET_MATCHING "bracket-matching"
#define XED_SETTINGS_DISPLAY_RIGHT_MARGIN "display-right-margin"
#define XED_SETTINGS_RIGHT_MARGIN_POSITION "right-margin-position"
+#define XED_SETTINGS_DRAW_WHITESPACE "draw-whitespace"
+#define XED_SETTINGS_DRAW_WHITESPACE_LEADING "draw-whitespace-leading"
+#define XED_SETTINGS_DRAW_WHITESPACE_TRAILING "draw-whitespace-trailing"
+#define XED_SETTINGS_DRAW_WHITESPACE_INSIDE "draw-whitespace-inside"
+#define XED_SETTINGS_DRAW_WHITESPACE_NEWLINE "draw-whitespace-newline"
#define XED_SETTINGS_SMART_HOME_END "smart-home-end"
#define XED_SETTINGS_WRITABLE_VFS_SCHEMES "writable-vfs-schemes"
#define XED_SETTINGS_RESTORE_CURSOR_POSITION "restore-cursor-position"
diff --git a/xed/xed-view.c b/xed/xed-view.c
index 3b84379..d68c31d 100644
--- a/xed/xed-view.c
+++ b/xed/xed-view.c
@@ -164,6 +164,7 @@ xed_view_constructed (GObject *object)
XedViewPrivate *priv;
gboolean use_default_font;
GtkSourceGutter *gutter;
+ gboolean draw_whitespace;
view = XED_VIEW (object);
priv = view->priv;
@@ -243,6 +244,15 @@ xed_view_constructed (GObject *object)
"smart-home-end",
G_SETTINGS_BIND_GET);
+ draw_whitespace = g_settings_get_boolean (priv->editor_settings, XED_SETTINGS_DRAW_WHITESPACE);
+
+ if (draw_whitespace)
+ {
+ xed_view_set_draw_whitespace (view, draw_whitespace);
+ }
+
+ xed_view_update_draw_whitespace_locations_and_types (view);
+
g_object_set (G_OBJECT (view),
"indent_on_tab", TRUE,
NULL);
@@ -834,3 +844,79 @@ xed_view_set_font (XedView *view,
gtk_widget_modify_font (GTK_WIDGET (view), font_desc);
pango_font_description_free (font_desc);
}
+
+static guint
+xed_view_get_draw_whitespace_locations_from_settings (GSettings* settings)
+{
+ guint locations;
+
+ locations = 0;
+
+ locations |= g_settings_get_boolean (settings, XED_SETTINGS_DRAW_WHITESPACE_LEADING)
+ ? GTK_SOURCE_SPACE_LOCATION_LEADING : 0;
+ locations |= g_settings_get_boolean (settings, XED_SETTINGS_DRAW_WHITESPACE_INSIDE)
+ ? GTK_SOURCE_SPACE_LOCATION_INSIDE_TEXT : 0;
+ locations |= g_settings_get_boolean (settings, XED_SETTINGS_DRAW_WHITESPACE_TRAILING)
+ ? GTK_SOURCE_SPACE_LOCATION_TRAILING : 0;
+
+ return locations;
+}
+
+static guint
+xed_view_get_draw_whitespace_types_from_settings (GSettings* settings)
+{
+ if (!g_settings_get_boolean (settings, XED_SETTINGS_DRAW_WHITESPACE_NEWLINE))
+ {
+ return GTK_SOURCE_SPACE_TYPE_ALL & ~GTK_SOURCE_SPACE_TYPE_NEWLINE;
+ }
+
+ return GTK_SOURCE_SPACE_TYPE_ALL;
+}
+
+/**
+ * xed_view_set_draw_whitespace:
+ * @view: a #XedView
+ * @enable: whether whitespace should be drawn
+ *
+ * Enables or disables rendering of any whitespace.
+ * The locations and types of whitespace to render is set by
+ * xed_view_update_draw_whitespace_locations_and_types()
+ *
+ **/
+
+void
+xed_view_set_draw_whitespace (XedView *view, gboolean enable)
+{
+ GtkSourceSpaceDrawer *spacedrawer;
+
+ spacedrawer = gtk_source_view_get_space_drawer (GTK_SOURCE_VIEW (view));
+ gtk_source_space_drawer_set_enable_matrix (spacedrawer, enable);
+}
+
+
+/**
+ * xed_view_update_draw_whitespace_locations_and_types:
+ * @view: a #XedView
+ *
+ * Updates the view to render whitespace at the locations and for types
+ * set in the preferences
+ *
+ **/
+
+void
+xed_view_update_draw_whitespace_locations_and_types (XedView *view)
+{
+ GtkSourceSpaceDrawer *spacedrawer;
+ guint locations, types;
+
+ spacedrawer = gtk_source_view_get_space_drawer (GTK_SOURCE_VIEW (view));
+ locations = xed_view_get_draw_whitespace_locations_from_settings (view->priv->editor_settings);
+ types = xed_view_get_draw_whitespace_types_from_settings (view->priv->editor_settings);
+
+ // disable other locations
+ gtk_source_space_drawer_set_types_for_locations (spacedrawer,
+ GTK_SOURCE_SPACE_LOCATION_ALL & ~locations,
+ GTK_SOURCE_SPACE_TYPE_NONE);
+ // enable chosen locations and types
+ gtk_source_space_drawer_set_types_for_locations (spacedrawer, locations, types);
+}
diff --git a/xed/xed-view.h b/xed/xed-view.h
index eab7295..1a0ef86 100644
--- a/xed/xed-view.h
+++ b/xed/xed-view.h
@@ -61,6 +61,8 @@ void xed_view_delete_selection (XedView *view);
void xed_view_select_all (XedView *view);
void xed_view_scroll_to_cursor (XedView *view);
void xed_view_set_font (XedView *view, gboolean def, const gchar *font_name);
+void xed_view_set_draw_whitespace (XedView *view, gboolean enable);
+void xed_view_update_draw_whitespace_locations_and_types (XedView *view);
G_END_DECLS