[Xfce4-commits] [apps/mousepad] 15/45: Add view-show-whitespace and view-show-line-endings

noreply at xfce.org noreply at xfce.org
Fri Jul 11 13:03:20 CEST 2014


This is an automated email from the git hooks/post-receive script.

mbrush pushed a commit to branch master
in repository apps/mousepad.

commit f0391f0b26ca3769d8172b2502dd482cf7ad26d0
Author: Matthew Brush <mbrush at codebrainz.ca>
Date:   Sun Jul 6 20:10:16 2014 -0700

    Add view-show-whitespace and view-show-line-endings
    
    Add the properties to MousepadView and make them update the base
    GtkSourceView's draw-spaces flags property. Bind GSettings to new
    properties.
---
 mousepad/mousepad-view.c               |  107 ++++++++++++++++++++++++++++++++
 mousepad/mousepad-view.h               |   10 +++
 mousepad/org.xfce.Mousepad.gschema.xml |   19 ++++++
 3 files changed, 136 insertions(+)

diff --git a/mousepad/mousepad-view.c b/mousepad/mousepad-view.c
index 1956c82..f31a6a7 100644
--- a/mousepad/mousepad-view.c
+++ b/mousepad/mousepad-view.c
@@ -124,6 +124,10 @@ struct _MousepadView
 
   /* the font used in the view */
   gchar              *font_name;
+
+  /* whitespace visualization */
+  gboolean            show_whitespace;
+  gboolean            show_line_endings;
 };
 
 
@@ -132,6 +136,8 @@ enum
 {
   PROP_0,
   PROP_FONT_NAME,
+  PROP_SHOW_WHITESPACE,
+  PROP_SHOW_LINE_ENDINGS,
   NUM_PROPERTIES
 };
 
@@ -167,6 +173,24 @@ mousepad_view_class_init (MousepadViewClass *klass)
                          "The name of the font to use in the view",
                          MOUSEPAD_VIEW_DEFAULT_FONT,
                          G_PARAM_READWRITE));
+
+  g_object_class_install_property (
+    gobject_class,
+    PROP_SHOW_WHITESPACE,
+    g_param_spec_boolean ("show-whitespace",
+                          "ShowWhitespace",
+                          "Whether whitespace is visualized in the view",
+                          FALSE,
+                          G_PARAM_CONSTRUCT | G_PARAM_READWRITE));
+
+  g_object_class_install_property (
+    gobject_class,
+    PROP_SHOW_LINE_ENDINGS,
+    g_param_spec_boolean ("show-line-endings",
+                          "ShowLineEndings",
+                          "Whether line-endings are visualized in the view",
+                          FALSE,
+                          G_PARAM_CONSTRUCT | G_PARAM_READWRITE));
 }
 
 
@@ -192,6 +216,8 @@ mousepad_view_init (MousepadView *view)
   mousepad_settings_bind ("view-line-numbers", view, "show-line-numbers", G_SETTINGS_BIND_DEFAULT);
   mousepad_settings_bind ("view-auto-indent", view, "auto-indent", G_SETTINGS_BIND_DEFAULT);
   mousepad_settings_bind ("view-font-name", view, "font-name", G_SETTINGS_BIND_DEFAULT);
+  mousepad_settings_bind ("view-show-whitespace", view, "show-whitespace", G_SETTINGS_BIND_DEFAULT);
+  mousepad_settings_bind ("view-show-line-endings", view, "show-line-endings", G_SETTINGS_BIND_DEFAULT);
 }
 
 
@@ -227,6 +253,12 @@ mousepad_view_set_property (GObject      *object,
     case PROP_FONT_NAME:
       mousepad_view_set_font_name (view, g_value_get_string (value));
       break;
+    case PROP_SHOW_WHITESPACE:
+      mousepad_view_set_show_whitespace (view, g_value_get_boolean (value));
+      break;
+    case PROP_SHOW_LINE_ENDINGS:
+      mousepad_view_set_show_line_endings (view, g_value_get_boolean (value));
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -248,6 +280,12 @@ mousepad_view_get_property (GObject    *object,
     case PROP_FONT_NAME:
       g_value_set_string (value, mousepad_view_get_font_name (view));
       break;
+    case PROP_SHOW_WHITESPACE:
+      g_value_set_boolean (value, mousepad_view_get_show_whitespace (view));
+      break;
+    case PROP_SHOW_LINE_ENDINGS:
+      g_value_set_boolean (value, mousepad_view_get_show_line_endings (view));
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -2475,6 +2513,29 @@ mousepad_view_set_font_name (MousepadView *view,
 
 
 
+static void
+mousepad_view_update_draw_spaces (MousepadView *view)
+{
+  GtkSourceDrawSpacesFlags flags = 0;
+
+  if (view->show_whitespace)
+    {
+      flags |= GTK_SOURCE_DRAW_SPACES_SPACE |
+               GTK_SOURCE_DRAW_SPACES_TAB |
+               GTK_SOURCE_DRAW_SPACES_NBSP |
+               GTK_SOURCE_DRAW_SPACES_LEADING |
+               GTK_SOURCE_DRAW_SPACES_TEXT |
+               GTK_SOURCE_DRAW_SPACES_TRAILING;
+    }
+
+  if (view->show_line_endings)
+    flags |= GTK_SOURCE_DRAW_SPACES_NEWLINE;
+
+  gtk_source_view_set_draw_spaces (GTK_SOURCE_VIEW (view), flags);
+}
+
+
+
 const gchar *
 mousepad_view_get_font_name (MousepadView *view)
 {
@@ -2482,3 +2543,49 @@ mousepad_view_get_font_name (MousepadView *view)
 
   return view->font_name;
 }
+
+
+
+void
+mousepad_view_set_show_whitespace (MousepadView *view,
+                                   gboolean      show)
+{
+  g_return_if_fail (MOUSEPAD_IS_VIEW (view));
+
+  view->show_whitespace = show;
+  mousepad_view_update_draw_spaces (view);
+  g_object_notify (G_OBJECT (view), "show-whitespace");
+}
+
+
+
+gboolean
+mousepad_view_get_show_whitespace (MousepadView *view)
+{
+  g_return_val_if_fail (MOUSEPAD_IS_VIEW (view), FALSE);
+
+  return view->show_whitespace;
+}
+
+
+
+void
+mousepad_view_set_show_line_endings (MousepadView *view,
+                                     gboolean      show)
+{
+  g_return_if_fail (MOUSEPAD_IS_VIEW (view));
+
+  view->show_line_endings = show;
+  mousepad_view_update_draw_spaces (view);
+  g_object_notify (G_OBJECT (view), "show-line-endings");
+}
+
+
+
+gboolean
+mousepad_view_get_show_line_endings (MousepadView *view)
+{
+  g_return_val_if_fail (MOUSEPAD_IS_VIEW (view), FALSE);
+
+  return view->show_line_endings;
+}
diff --git a/mousepad/mousepad-view.h b/mousepad/mousepad-view.h
index 042483f..b3d1609 100644
--- a/mousepad/mousepad-view.h
+++ b/mousepad/mousepad-view.h
@@ -112,6 +112,16 @@ void            mousepad_view_set_font_name             (MousepadView      *view
 
 const gchar    *mousepad_view_get_font_name             (MousepadView      *view);
 
+void            mousepad_view_set_show_whitespace       (MousepadView      *view,
+                                                         gboolean           show);
+
+gboolean        mousepad_view_get_show_whitespace       (MousepadView      *view);
+
+void            mousepad_view_set_show_line_endings     (MousepadView      *view,
+                                                         gboolean           show);
+
+gboolean        mousepad_view_get_show_line_endings     (MousepadView      *view);
+
 G_END_DECLS
 
 #endif /* !__MOUSEPAD_VIEW_H__ */
diff --git a/mousepad/org.xfce.Mousepad.gschema.xml b/mousepad/org.xfce.Mousepad.gschema.xml
index 37756f4..d7ff57f 100644
--- a/mousepad/org.xfce.Mousepad.gschema.xml
+++ b/mousepad/org.xfce.Mousepad.gschema.xml
@@ -1,4 +1,5 @@
 <schemalist>
+
   <schema id="org.xfce.Mousepad" path="/org/xfce/Mousepad/" gettext-domain="mousepad">
 
     <!-- Search preferences -->
@@ -71,6 +72,24 @@
       </description>
     </key>
 
+    <key name="view-show-whitespace" type="b">
+      <default>false</default>
+      <summary>Show whitespace</summary>
+      <description>
+        When true whitespace will be visualized in the view.
+        See also 'view-show-line-endings'.
+      </description>
+    </key>
+
+    <key name="view-show-line-endings" type="b">
+      <default>false</default>
+      <summary>Show line endings</summary>
+      <description>
+        When true newlines will be visualized in the view.
+        See also 'view-show-whitespace'.
+      </description>
+    </key>
+
     <key name="view-line-numbers" type="b">
       <default>false</default>
       <summary>Show line numbers</summary>

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list