summaryrefslogtreecommitdiff
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
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)
-rw-r--r--data/org.mate.pluma.gschema.xml.in25
-rw-r--r--pluma/pluma-prefs-manager-app.c180
-rw-r--r--pluma/pluma-prefs-manager.c64
-rw-r--r--pluma/pluma-prefs-manager.h26
-rw-r--r--pluma/pluma-view.c83
-rw-r--r--pluma/pluma-view.h8
6 files changed, 386 insertions, 0 deletions
diff --git a/data/org.mate.pluma.gschema.xml.in b/data/org.mate.pluma.gschema.xml.in
index 7cbaba7f..81071391 100644
--- a/data/org.mate.pluma.gschema.xml.in
+++ b/data/org.mate.pluma.gschema.xml.in
@@ -1,5 +1,10 @@
<?xml version="1.0"?>
<schemalist gettext-domain="@GETTEXT_PACKAGE@">
+ <enum id="org.mate.pluma.SpaceDrawer">
+ <value nick="draw-none" value="0"/>
+ <value nick="draw-trailing" value="1"/>
+ <value nick="draw-all" value="2"/>
+ </enum>
<schema id="org.mate.pluma" path="/org/mate/pluma/">
<key name="use-default-font" type="b">
<default>true</default>
@@ -216,5 +221,25 @@
<summary>Active plugins</summary>
<description>List of active plugins. It contains the "Location" of the active plugins. See the .pluma-plugin file for obtaining the "Location" of a given plugin.</description>
</key>
+ <key name="enable-space-drawer-newline" type="b">
+ <default>false</default>
+ <summary>Draw newline</summary>
+ <description>Whether pluma should draw newlines in the editor window.</description>
+ </key>
+ <key name="enable-space-drawer-nbsp" enum="org.mate.pluma.SpaceDrawer">
+ <default>'draw-none'</default>
+ <summary>Draw nbsp</summary>
+ <description>Whether pluma should draw not breaking spaces in the editor window: 'draw-none' no drawing; 'draw-trailing' drawing only trailing spaces; 'draw-all' drawing all spaces.</description>
+ </key>
+ <key name="enable-space-drawer-tab" enum="org.mate.pluma.SpaceDrawer">
+ <default>'draw-none'</default>
+ <summary>Draw tabs</summary>
+ <description>Whether pluma should draw tabs in the editor window: 'draw-none' no drawing; 'draw-trailing' drawing only trailing spaces; 'draw-all' drawing all spaces.</description>
+ </key>
+ <key name="enable-space-drawer-space" enum="org.mate.pluma.SpaceDrawer">
+ <default>'draw-none'</default>
+ <summary>Draw spaces</summary>
+ <description>Whether pluma should draw spaces in the editor window: 'draw-none' no drawing; 'draw-trailing' drawing only trailing spaces; 'draw-all' drawing all spaces.</description>
+ </key>
</schema>
</schemalist>
diff --git a/pluma/pluma-prefs-manager-app.c b/pluma/pluma-prefs-manager-app.c
index 76d3942e..c1887f96 100644
--- a/pluma/pluma-prefs-manager-app.c
+++ b/pluma/pluma-prefs-manager-app.c
@@ -116,6 +116,22 @@ static void pluma_prefs_manager_lockdown_changed (GSettings *settings,
gchar *key,
gpointer user_data);
+static void pluma_prefs_manager_draw_spaces_changed (GSettings *settings,
+ gchar *key,
+ gpointer user_data);
+
+static void pluma_prefs_manager_draw_tabs_changed (GSettings *settings,
+ gchar *key,
+ gpointer user_data);
+
+static void pluma_prefs_manager_draw_newlines_changed (GSettings *settings,
+ gchar *key,
+ gpointer user_data);
+
+static void pluma_prefs_manager_draw_nbsp_changed (GSettings *settings,
+ gchar *key,
+ gpointer user_data);
+
/* GUI state is serialized to a .desktop file, not in GSettings */
#define PLUMA_STATE_DEFAULT_WINDOW_STATE 0
@@ -713,6 +729,27 @@ pluma_prefs_manager_app_init (void)
"changed",
G_CALLBACK (pluma_prefs_manager_lockdown_changed),
NULL);
+
+ g_signal_connect (pluma_prefs_manager->settings,
+ "changed::" GPM_SPACE_DRAWER_SPACE,
+ G_CALLBACK (pluma_prefs_manager_draw_spaces_changed),
+ NULL);
+
+ g_signal_connect (pluma_prefs_manager->settings,
+ "changed::" GPM_SPACE_DRAWER_TAB,
+ G_CALLBACK (pluma_prefs_manager_draw_tabs_changed),
+ NULL);
+
+ g_signal_connect (pluma_prefs_manager->settings,
+ "changed::" GPM_SPACE_DRAWER_NEWLINE,
+ G_CALLBACK (pluma_prefs_manager_draw_newlines_changed),
+ NULL);
+
+ g_signal_connect (pluma_prefs_manager->settings,
+ "changed::" GPM_SPACE_DRAWER_NBSP,
+ G_CALLBACK (pluma_prefs_manager_draw_nbsp_changed),
+ NULL);
+
}
return pluma_prefs_manager != NULL;
@@ -1439,3 +1476,146 @@ pluma_prefs_manager_lockdown_changed (GSettings *settings,
PLUMA_LOCKDOWN_SAVE_TO_DISK,
locked);
}
+
+#ifdef GTK_SOURCE_VERSION_3_24
+static void
+pluma_prefs_manager_space_drawer_generic (GSettings *settings,
+ gint level,
+ GtkSourceSpaceTypeFlags type)
+{
+
+ GList *views;
+ GList *l;
+
+ pluma_debug (DEBUG_PREFS);
+
+ views = pluma_app_get_views (pluma_app_get_default ());
+ l = views;
+
+ while (l != NULL)
+ {
+ pluma_set_source_space_drawer_by_level (GTK_SOURCE_VIEW (l->data),
+ level, type);
+ l = l->next;
+ }
+
+ g_list_free (views);
+}
+#else
+static void
+pluma_prefs_manager_draw_generic (GSettings *settings,
+ gint level,
+ GtkSourceDrawSpacesFlags type)
+{
+
+ GList *views;
+ GList *l;
+
+ pluma_debug (DEBUG_PREFS);
+
+ views = pluma_app_get_views (pluma_app_get_default ());
+ l = views;
+
+ while (l != NULL)
+ {
+ GtkSourceSpaceTypeFlags value;
+
+ value = gtk_source_view_get_draw_spaces (GTK_SOURCE_VIEW (l->data));
+ if (level > 0)
+ value |= type;
+ else
+ value &= ~type;
+ gtk_source_view_set_draw_spaces (GTK_SOURCE_VIEW (l->data),
+ value);
+ l = l->next;
+ }
+
+ g_list_free (views);
+}
+#endif
+
+static void
+pluma_prefs_manager_draw_spaces_changed (GSettings *settings,
+ gchar *key,
+ gpointer user_data)
+{
+ pluma_debug (DEBUG_PREFS);
+
+ if (strcmp (key, GPM_SPACE_DRAWER_SPACE))
+ return;
+
+#ifdef GTK_SOURCE_VERSION_3_24
+ pluma_prefs_manager_space_drawer_generic (settings,
+ g_settings_get_enum (settings, key),
+ GTK_SOURCE_SPACE_TYPE_SPACE);
+#else
+ pluma_prefs_manager_draw_generic (settings,
+ g_settings_get_enum (settings, key),
+ GTK_SOURCE_DRAW_SPACES_SPACE);
+#endif
+}
+
+static void
+pluma_prefs_manager_draw_tabs_changed (GSettings *settings,
+ gchar *key,
+ gpointer user_data)
+{
+ pluma_debug (DEBUG_PREFS);
+
+ if (strcmp (key, GPM_SPACE_DRAWER_TAB))
+ return;
+
+#ifdef GTK_SOURCE_VERSION_3_24
+ pluma_prefs_manager_space_drawer_generic (settings,
+ g_settings_get_enum (settings, key),
+ GTK_SOURCE_SPACE_TYPE_TAB);
+#else
+ pluma_prefs_manager_draw_generic (settings,
+ g_settings_get_enum (settings, key),
+ GTK_SOURCE_DRAW_SPACES_TAB);
+#endif
+
+}
+
+static void
+pluma_prefs_manager_draw_newlines_changed (GSettings *settings,
+ gchar *key,
+ gpointer user_data)
+{
+ pluma_debug (DEBUG_PREFS);
+
+ if (strcmp (key, GPM_SPACE_DRAWER_NEWLINE))
+ return;
+
+#ifdef GTK_SOURCE_VERSION_3_24
+ pluma_prefs_manager_space_drawer_generic (settings,
+ g_settings_get_boolean (settings, key) ? 1 : 0,
+ GTK_SOURCE_SPACE_TYPE_NEWLINE);
+#else
+ pluma_prefs_manager_draw_generic (settings,
+ g_settings_get_boolean (settings, key) ? 1 : 0,
+ GTK_SOURCE_DRAW_SPACES_NEWLINE);
+#endif
+
+}
+
+static void
+pluma_prefs_manager_draw_nbsp_changed (GSettings *settings,
+ gchar *key,
+ gpointer user_data)
+{
+ pluma_debug (DEBUG_PREFS);
+
+ if (strcmp (key, GPM_SPACE_DRAWER_NBSP))
+ return;
+
+#ifdef GTK_SOURCE_VERSION_3_24
+ pluma_prefs_manager_space_drawer_generic (settings,
+ g_settings_get_enum (settings, key),
+ GTK_SOURCE_SPACE_TYPE_NBSP);
+#else
+ pluma_prefs_manager_draw_generic (settings,
+ g_settings_get_enum (settings, key),
+ GTK_SOURCE_DRAW_SPACES_NBSP);
+#endif
+}
diff --git a/pluma/pluma-prefs-manager.c b/pluma/pluma-prefs-manager.c
index c82c887c..e83f44ed 100644
--- a/pluma/pluma-prefs-manager.c
+++ b/pluma/pluma-prefs-manager.c
@@ -122,6 +122,33 @@ pluma_prefs_manager_ ## name ## _can_set (void) \
}
+
+#define DEFINE_ENUM_PREF(name, key) gint \
+pluma_prefs_manager_get_ ## name (void) \
+{ \
+ pluma_debug (DEBUG_PREFS); \
+ \
+ return pluma_prefs_manager_get_enum (key); \
+} \
+ \
+void \
+pluma_prefs_manager_set_ ## name (gint v) \
+{ \
+ pluma_debug (DEBUG_PREFS); \
+ \
+ pluma_prefs_manager_set_enum (key, \
+ v); \
+} \
+ \
+gboolean \
+pluma_prefs_manager_ ## name ## _can_set (void) \
+{ \
+ pluma_debug (DEBUG_PREFS); \
+ \
+ return pluma_prefs_manager_key_is_writable (key); \
+}
+
+
PlumaPrefsManager *pluma_prefs_manager = NULL;
@@ -133,6 +160,8 @@ static gint pluma_prefs_manager_get_int (const gchar* key);
static gchar *pluma_prefs_manager_get_string (const gchar* key);
+static gint pluma_prefs_manager_get_enum (const gchar* key);
+
gboolean
pluma_prefs_manager_init (void)
@@ -189,6 +218,14 @@ pluma_prefs_manager_get_string (const gchar* key)
return g_settings_get_string (pluma_prefs_manager->settings, key);
}
+static gint
+pluma_prefs_manager_get_enum (const gchar* key)
+{
+ pluma_debug (DEBUG_PREFS);
+
+ return g_settings_get_enum (pluma_prefs_manager->settings, key);
+}
+
static void
pluma_prefs_manager_set_bool (const gchar* key, gboolean value)
{
@@ -224,6 +261,17 @@ pluma_prefs_manager_set_string (const gchar* key, const gchar* value)
g_settings_set_string (pluma_prefs_manager->settings, key, value);
}
+static void
+pluma_prefs_manager_set_enum (const gchar* key, gint value)
+{
+ pluma_debug (DEBUG_PREFS);
+
+ g_return_if_fail (g_settings_is_writable (
+ pluma_prefs_manager->settings, key));
+
+ g_settings_set_enum (pluma_prefs_manager->settings, key, value);
+}
+
static gboolean
pluma_prefs_manager_key_is_writable (const gchar* key)
{
@@ -939,3 +987,19 @@ pluma_prefs_manager_get_lockdown (void)
return lockdown;
}
+
+/* enable drawing 'normal' spaces */
+DEFINE_ENUM_PREF(draw_spaces,
+ GPM_SPACE_DRAWER_SPACE)
+
+/* enable drawing tabs */
+DEFINE_ENUM_PREF(draw_tabs,
+ GPM_SPACE_DRAWER_TAB)
+
+/* enable drawing newline */
+DEFINE_BOOL_PREF(draw_newlines,
+ GPM_SPACE_DRAWER_NEWLINE)
+
+/* enable drawing nbsp */
+DEFINE_ENUM_PREF(draw_nbsp,
+ GPM_SPACE_DRAWER_NBSP)
diff --git a/pluma/pluma-prefs-manager.h b/pluma/pluma-prefs-manager.h
index 18dc043f..8124b1fd 100644
--- a/pluma/pluma-prefs-manager.h
+++ b/pluma/pluma-prefs-manager.h
@@ -122,6 +122,12 @@
#define GPM_DEFAULT_AUTO_SAVE_INTERVAL 10 /* minutes */
#define GPM_DEFAULT_MAX_RECENTS 5
+/* space drawer settings */
+#define GPM_SPACE_DRAWER_SPACE "enable-space-drawer-space"
+#define GPM_SPACE_DRAWER_TAB "enable-space-drawer-tab"
+#define GPM_SPACE_DRAWER_NEWLINE "enable-space-drawer-newline"
+#define GPM_SPACE_DRAWER_NBSP "enable-space-drawer-nbsp"
+
typedef enum {
PLUMA_TOOLBAR_SYSTEM = 0,
PLUMA_TOOLBAR_ICONS,
@@ -330,6 +336,26 @@ PlumaLockdownMask pluma_prefs_manager_get_lockdown (void);
GSList* pluma_prefs_manager_get_gslist (GSettings *settings, const gchar *key);
void pluma_prefs_manager_set_gslist (GSettings *settings, const gchar *key, GSList *list);
+/* Enable drawing space */
+gint pluma_prefs_manager_get_draw_spaces (void);
+void pluma_prefs_manager_set_draw_spaces (gint enable_draw_spaces);
+gboolean pluma_prefs_manager_draw_spaces_can_set (void);
+
+/* Enable drawing tab */
+gint pluma_prefs_manager_get_draw_tabs (void);
+void pluma_prefs_manager_set_draw_tabs (gint enable_draw_tabs);
+gboolean pluma_prefs_manager_draw_tabs_can_set (void);
+
+/* Enable drawing newline */
+gboolean pluma_prefs_manager_get_draw_newlines (void);
+void pluma_prefs_manager_set_draw_newlines (gboolean enable_draw_newlines);
+gboolean pluma_prefs_manager_draw_newlines_can_set (void);
+
+/* Enable drawing nbsp */
+gint pluma_prefs_manager_get_draw_nbsp (void);
+void pluma_prefs_manager_set_draw_nbsp (gint enable_draw_nbsp);
+gboolean pluma_prefs_manager_draw_nbsp_can_set (void);
+
#endif /* __PLUMA_PREFS_MANAGER_H__ */
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;
diff --git a/pluma/pluma-view.h b/pluma/pluma-view.h
index c8877d5f..b8286205 100644
--- a/pluma/pluma-view.h
+++ b/pluma/pluma-view.h
@@ -107,6 +107,14 @@ void pluma_view_set_font (PlumaView *view,
gboolean def,
const gchar *font_name);
+#ifdef GTK_SOURCE_VERSION_3_24
+void
+pluma_set_source_space_drawer_by_level (GtkSourceView *view,
+ gint level,
+ GtkSourceSpaceTypeFlags type);
+#endif
+
+
G_END_DECLS
#endif /* __PLUMA_VIEW_H__ */