[Xfce4-commits] [apps/mousepad] 17/45: Add color-scheme property to MousepadView

noreply at xfce.org noreply at xfce.org
Fri Jul 11 13:03:22 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 81a430c0ff61a50cf47cbcd1b3de49acf7f72b64
Author: Matthew Brush <mbrush at codebrainz.ca>
Date:   Sun Jul 6 21:38:30 2014 -0700

    Add color-scheme property to MousepadView
    
    Bind GSettings to property to keep in sync.
---
 mousepad/mousepad-view.c   |   65 ++++++++++++++++++++++++++++++++++++++++++++
 mousepad/mousepad-view.h   |    5 ++++
 mousepad/mousepad-window.c |   17 ------------
 3 files changed, 70 insertions(+), 17 deletions(-)

diff --git a/mousepad/mousepad-view.c b/mousepad/mousepad-view.c
index cddb68c..33b041d 100644
--- a/mousepad/mousepad-view.c
+++ b/mousepad/mousepad-view.c
@@ -138,6 +138,7 @@ enum
   PROP_FONT_NAME,
   PROP_SHOW_WHITESPACE,
   PROP_SHOW_LINE_ENDINGS,
+  PROP_COLOR_SCHEME,
   NUM_PROPERTIES
 };
 
@@ -191,6 +192,15 @@ mousepad_view_class_init (MousepadViewClass *klass)
                           "Whether line-endings are visualized in the view",
                           FALSE,
                           G_PARAM_CONSTRUCT | G_PARAM_READWRITE));
+
+  g_object_class_install_property (
+    gobject_class,
+    PROP_COLOR_SCHEME,
+    g_param_spec_string ("color-scheme",
+                         "ColorScheme",
+                         "The id of the syntax highlighting color scheme to use",
+                         NULL,
+                         G_PARAM_CONSTRUCT | G_PARAM_READWRITE));
 }
 
 
@@ -227,6 +237,7 @@ mousepad_view_init (MousepadView *view)
   mousepad_settings_bind ("view-show-right-margin", view, "show-right-margin", G_SETTINGS_BIND_DEFAULT);
   mousepad_settings_bind ("view-smart-home-end", view, "smart-home-end", G_SETTINGS_BIND_DEFAULT);
   mousepad_settings_bind ("view-tab-width", view, "tab-width", G_SETTINGS_BIND_DEFAULT);
+  mousepad_settings_bind ("view-color-scheme", view, "color-scheme", G_SETTINGS_BIND_DEFAULT);
 }
 
 
@@ -268,6 +279,9 @@ mousepad_view_set_property (GObject      *object,
     case PROP_SHOW_LINE_ENDINGS:
       mousepad_view_set_show_line_endings (view, g_value_get_boolean (value));
       break;
+    case PROP_COLOR_SCHEME:
+      mousepad_view_set_color_scheme (view, g_value_get_string (value));
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -295,6 +309,9 @@ mousepad_view_get_property (GObject    *object,
     case PROP_SHOW_LINE_ENDINGS:
       g_value_set_boolean (value, mousepad_view_get_show_line_endings (view));
       break;
+    case PROP_COLOR_SCHEME:
+      g_value_set_string (value, mousepad_view_get_color_scheme (view));
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -2555,3 +2572,51 @@ mousepad_view_get_show_line_endings (MousepadView *view)
 
   return view->show_line_endings;
 }
+
+
+
+void
+mousepad_view_set_color_scheme (MousepadView *view,
+                                const gchar  *color_scheme)
+{
+  GtkSourceBuffer      *buffer;
+  GtkSourceStyleScheme *scheme;
+  g_return_if_fail (MOUSEPAD_IS_VIEW (view));
+
+  if (color_scheme == NULL || g_strcmp0 (color_scheme, "none") == 0)
+    scheme = NULL;
+  else
+    {
+      GtkSourceStyleSchemeManager *manager;
+      manager = gtk_source_style_scheme_manager_get_default ();
+      scheme = gtk_source_style_scheme_manager_get_scheme (manager, color_scheme);
+      g_warn_if_fail (scheme != NULL);
+    }
+
+  buffer = (GtkSourceBuffer*) gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
+  if (GTK_IS_SOURCE_BUFFER (buffer))
+    {
+      gtk_source_buffer_set_style_scheme (buffer, scheme);
+      gtk_source_buffer_set_highlight_syntax (buffer, (scheme != NULL));
+      g_object_notify (G_OBJECT (view), "color-scheme");
+    }
+}
+
+
+
+const gchar *
+mousepad_view_get_color_scheme (MousepadView *view)
+{
+  GtkSourceBuffer      *buffer;
+  GtkSourceStyleScheme *scheme;
+
+  g_return_val_if_fail (MOUSEPAD_IS_VIEW (view), NULL);
+
+  buffer = (GtkSourceBuffer*) gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
+
+  scheme = gtk_source_buffer_get_style_scheme (buffer);
+  if (GTK_IS_SOURCE_STYLE_SCHEME (scheme))
+    return gtk_source_style_scheme_get_id (scheme);
+
+  return "none";
+}
diff --git a/mousepad/mousepad-view.h b/mousepad/mousepad-view.h
index df123a7..f2bf88f 100644
--- a/mousepad/mousepad-view.h
+++ b/mousepad/mousepad-view.h
@@ -110,6 +110,11 @@ void            mousepad_view_set_show_line_endings     (MousepadView      *view
 
 gboolean        mousepad_view_get_show_line_endings     (MousepadView      *view);
 
+void            mousepad_view_set_color_scheme          (MousepadView      *view,
+                                                         const gchar       *color_scheme);
+
+const gchar    *mousepad_view_get_color_scheme          (MousepadView      *view);
+
 G_END_DECLS
 
 #endif /* !__MOUSEPAD_VIEW_H__ */
diff --git a/mousepad/mousepad-window.c b/mousepad/mousepad-window.c
index 87b946f..1d255fe 100644
--- a/mousepad/mousepad-window.c
+++ b/mousepad/mousepad-window.c
@@ -4461,12 +4461,8 @@ static void
 mousepad_window_action_color_scheme (GtkToggleAction *action,
                                      MousepadWindow  *window)
 {
-  gint                  page_num = 0;
   guint                 scheme_id_hash;
-  GtkWidget            *page;
-  GtkTextBuffer        *buffer;
   GtkSourceStyleScheme *scheme = NULL;
-  MousepadDocument     *document;
   GSList               *schemes, *iter;
 
   mousepad_return_if_fail (MOUSEPAD_IS_WINDOW (window));
@@ -4499,19 +4495,6 @@ mousepad_window_action_color_scheme (GtkToggleAction *action,
                                     (scheme != NULL) ?
                                     gtk_source_style_scheme_get_id (scheme) :
                                     "none");
-
-      /* apply colour scheme to all open textviews */
-      while ((page = gtk_notebook_get_nth_page (GTK_NOTEBOOK (window->notebook), page_num)))
-        {
-          if (G_LIKELY (MOUSEPAD_IS_DOCUMENT (page)))
-            {
-              document = MOUSEPAD_DOCUMENT (page);
-              buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (document->textview));
-              gtk_source_buffer_set_highlight_syntax (GTK_SOURCE_BUFFER (buffer), (scheme != NULL));
-              gtk_source_buffer_set_style_scheme (GTK_SOURCE_BUFFER (buffer), scheme);
-            }
-            page_num++;
-        }
     }
 }
 

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


More information about the Xfce4-commits mailing list