[Xfce4-commits] [apps/mousepad] 36/45: Add use-default-monospace-font setting

noreply at xfce.org noreply at xfce.org
Fri Jul 11 13:03:41 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 4b7ffa3ba33aa7ba45aa7950df41ffa9016daa34
Author: Matthew Brush <mbrush at codebrainz.ca>
Date:   Thu Jul 10 14:36:08 2014 -0700

    Add use-default-monospace-font setting
    
    And hookup the related widget(s) in the preferences dialog. This new
    setting allows to use the default font without overwriting the previous
    font-name that was set.
---
 mousepad/mousepad-prefs-dialog.c       |   10 ++--
 mousepad/mousepad-prefs-dialog.glade   |    2 -
 mousepad/mousepad-settings.h           |    1 +
 mousepad/mousepad-view.c               |   98 ++++++++++++++++++++++++--------
 mousepad/org.xfce.Mousepad.gschema.xml |    9 +++
 5 files changed, 90 insertions(+), 30 deletions(-)

diff --git a/mousepad/mousepad-prefs-dialog.c b/mousepad/mousepad-prefs-dialog.c
index 3562a61..353df21 100644
--- a/mousepad/mousepad-prefs-dialog.c
+++ b/mousepad/mousepad-prefs-dialog.c
@@ -17,7 +17,7 @@
 #define WID_HIGHLIGHT_MATCHING_BRACES_CHECK "/prefs/view/display/highlight-braces-check"
 #define WID_WORD_WRAP_CHECK                 "/prefs/view/display/word-wrap-check"
 
-#define WID_DEFAULT_FONT_CHECK              "/prefs/view/font/default-check"
+#define WID_USE_DEFAULT_FONT_CHECK          "/prefs/view/font/default-check"
 #define WID_FONT_BUTTON                     "/prefs/view/font/chooser-button"
 #define WID_SCHEME_COMBO                    "/prefs/view/color-scheme-combo"
 #define WID_SCHEME_MODEL                    "/prefs/view/color-scheme-model"
@@ -277,7 +277,6 @@ mousepad_prefs_dialog_home_end_setting_changed (MousepadPrefsDialog *self,
                                                 GSettings           *settings)
 {
   GtkComboBox *combo;
-  gint         value;
 
   /* don't do anything when the combo box is itself updating the setting */
   if (self->blocked)
@@ -335,9 +334,9 @@ mousepad_prefs_dialog_init (MousepadPrefsDialog *self)
   g_object_bind_property (check, "active", widget, "sensitive", G_BINDING_SYNC_CREATE);
 
   /* enable/disable font chooser button when the default font checkbox is changed */
-  check = mousepad_builder_get_widget (self->builder, WID_DEFAULT_FONT_CHECK);
+  check = mousepad_builder_get_widget (self->builder, WID_USE_DEFAULT_FONT_CHECK);
   widget = mousepad_builder_get_widget (self->builder, WID_FONT_BUTTON);
-  g_object_bind_property (check, "active", widget, "sensitive", G_BINDING_SYNC_CREATE);
+  g_object_bind_property (check, "active", widget, "sensitive", G_BINDING_SYNC_CREATE | G_BINDING_INVERT_BOOLEAN);
 
   /* bind checkboxes to settings */
 #define BIND_CHECKBOX(setting)                                           \
@@ -354,6 +353,7 @@ mousepad_prefs_dialog_init (MousepadPrefsDialog *self)
   BIND_CHECKBOX (SHOW_RIGHT_MARGIN);
   BIND_CHECKBOX (HIGHLIGHT_CURRENT_LINE);
   BIND_CHECKBOX (WORD_WRAP);
+  BIND_CHECKBOX (USE_DEFAULT_FONT);
 
   /* Editor */
   BIND_CHECKBOX (AUTO_INDENT);
@@ -377,7 +377,7 @@ mousepad_prefs_dialog_init (MousepadPrefsDialog *self)
   MOUSEPAD_SETTING_BIND (FONT_NAME,
                          gtk_builder_get_object (self->builder, WID_FONT_BUTTON),
                          "font-name",
-                         G_SETTINGS_BIND_DEFAULT);
+                         G_SETTINGS_BIND_DEFAULT | G_SETTINGS_BIND_NO_SENSITIVITY);
 
   mousepad_prefs_dialog_setup_color_schemes_combo (self);
 
diff --git a/mousepad/mousepad-prefs-dialog.glade b/mousepad/mousepad-prefs-dialog.glade
index 365ffeb..ce99499 100644
--- a/mousepad/mousepad-prefs-dialog.glade
+++ b/mousepad/mousepad-prefs-dialog.glade
@@ -272,7 +272,6 @@
                         <property name="visible">True</property>
                         <property name="can_focus">True</property>
                         <property name="receives_default">False</property>
-                        <property name="active">True</property>
                         <property name="draw_indicator">True</property>
                       </object>
                       <packing>
@@ -284,7 +283,6 @@
                     <child>
                       <object class="GtkFontButton" id="/prefs/view/font/chooser-button">
                         <property name="visible">True</property>
-                        <property name="sensitive">False</property>
                         <property name="can_focus">True</property>
                         <property name="receives_default">True</property>
                       </object>
diff --git a/mousepad/mousepad-settings.h b/mousepad/mousepad-settings.h
index 9ddabc0..8aef4d2 100644
--- a/mousepad/mousepad-settings.h
+++ b/mousepad/mousepad-settings.h
@@ -9,6 +9,7 @@ G_BEGIN_DECLS
 /* Setting names */
 #define MOUSEPAD_SETTING_AUTO_INDENT                "/preferences/view/auto-indent"
 #define MOUSEPAD_SETTING_FONT_NAME                  "/preferences/view/font-name"
+#define MOUSEPAD_SETTING_USE_DEFAULT_FONT           "/preferences/view/use-default-monospace-font"
 #define MOUSEPAD_SETTING_SHOW_WHITESPACE            "/preferences/view/show-whitespace"
 #define MOUSEPAD_SETTING_SHOW_LINE_ENDINGS          "/preferences/view/show-line-endings"
 #define MOUSEPAD_SETTING_HIGHLIGHT_CURRENT_LINE     "/preferences/view/highlight-current-line"
diff --git a/mousepad/mousepad-view.c b/mousepad/mousepad-view.c
index d26e687..d362973 100644
--- a/mousepad/mousepad-view.c
+++ b/mousepad/mousepad-view.c
@@ -89,6 +89,7 @@ static void      mousepad_view_transpose_lines               (GtkTextBuffer
                                                               GtkTextIter         *end_iter);
 static void      mousepad_view_transpose_words               (GtkTextBuffer       *buffer,
                                                               GtkTextIter         *iter);
+static void      mousepad_view_update_font                   (MousepadView        *view);
 
 
 
@@ -99,37 +100,38 @@ struct _MousepadViewClass
 
 struct _MousepadView
 {
-  GtkSourceView  __parent__;
+  GtkSourceView         __parent__;
 
   /* the selection style tag */
-  GtkTextTag         *selection_tag;
+  GtkTextTag           *selection_tag;
 
   /* list with all the selection marks */
-  GSList             *selection_marks;
+  GSList               *selection_marks;
 
   /* selection timeout id */
-  guint               selection_timeout_id;
+  guint                 selection_timeout_id;
 
   /* coordinates for the selection */
-  gint                selection_start_x;
-  gint                selection_start_y;
-  gint                selection_end_x;
-  gint                selection_end_y;
+  gint                  selection_start_x;
+  gint                  selection_start_y;
+  gint                  selection_end_x;
+  gint                  selection_end_y;
 
   /* length of the selection (-1 = zerro width selection, 0 = no selection) */
-  gint                selection_length;
+  gint                  selection_length;
 
   /* if the selection is in editing mode */
-  guint               selection_editing : 1;
+  guint                 selection_editing : 1;
 
   /* the font used in the view */
-  gchar              *font_name;
+  gchar                *font_name;
+  PangoFontDescription *font_desc;
 
   /* whitespace visualization */
-  gboolean            show_whitespace;
-  gboolean            show_line_endings;
+  gboolean              show_whitespace;
+  gboolean              show_line_endings;
 
-  gchar              *color_scheme;
+  gchar                *color_scheme;
 };
 
 
@@ -237,6 +239,17 @@ mousepad_view_buffer_changed (MousepadView *view,
 }
 
 
+
+static void
+mousepad_view_use_default_font_setting_changed (MousepadView *view,
+                                                gchar        *key,
+                                                GSettings    *settings)
+{
+  mousepad_view_update_font (view);
+}
+
+
+
 static void
 mousepad_view_init (MousepadView *view)
 {
@@ -247,6 +260,8 @@ mousepad_view_init (MousepadView *view)
   view->selection_length = 0;
   view->selection_editing = FALSE;
   view->color_scheme = g_strdup ("none");
+  view->font_name = NULL;
+  view->font_desc = NULL;
 
   /* make sure any buffers set on the view get the color scheme applied to them */
   g_signal_connect (view,
@@ -282,6 +297,12 @@ mousepad_view_init (MousepadView *view)
   BIND_ (COLOR_SCHEME,           "color-scheme");
   BIND_ (WORD_WRAP,              "word-wrap");
 
+  /* override with default font when the setting is enabled */
+  MOUSEPAD_SETTING_CONNECT (USE_DEFAULT_FONT,
+                            G_CALLBACK (mousepad_view_use_default_font_setting_changed),
+                            view,
+                            G_CONNECT_SWAPPED);
+
 #undef BIND_
 }
 
@@ -2528,24 +2549,22 @@ mousepad_view_set_font_name (MousepadView *view,
   font_desc = pango_font_description_from_string (font_name);
   if (G_LIKELY (font_desc != NULL))
     {
-      /* Override the GtkWidget's font */
-#if GTK_CHECK_VERSION(3, 0, 0)
-      gtk_widget_override_font (GTK_WIDGET (view), font_desc);
-#else
-      gtk_widget_modify_font (GTK_WIDGET (view), font_desc);
-#endif
-
       /* Save the normalized representation of the font as a string */
       g_free (view->font_name);
       view->font_name = pango_font_description_to_string (font_desc);
 
+      /* save the font description for later updating */
+      pango_font_description_free (view->font_desc);
+      view->font_desc = font_desc;
+
+      /* apply either the default or this font depending on settings */
+      mousepad_view_update_font (view);
+
       /* Notify interested parties that the property has changed */
       g_object_notify (G_OBJECT (view), "font-name");
     }
   else
     g_critical ("Invalid font-name given: %s", font_name);
-
-  pango_font_description_free (font_desc);
 }
 
 
@@ -2573,6 +2592,39 @@ mousepad_view_update_draw_spaces (MousepadView *view)
 
 
 
+static void
+mousepad_view_override_font (MousepadView         *view,
+                             PangoFontDescription *font_desc)
+{
+#if GTK_CHECK_VERSION (3, 0, 0)
+  gtk_widget_override_font (GTK_WIDGET (view), font_desc);
+#else
+  gtk_widget_modify_font (GTK_WIDGET (view), font_desc);
+#endif
+}
+
+
+
+static void
+mousepad_view_update_font (MousepadView *view)
+{
+  gboolean use_default;
+
+  use_default = MOUSEPAD_SETTING_GET_BOOLEAN (USE_DEFAULT_FONT);
+
+  if (use_default)
+    {
+      PangoFontDescription *font_desc;
+      font_desc = pango_font_description_from_string (MOUSEPAD_VIEW_DEFAULT_FONT);
+      mousepad_view_override_font (view, font_desc);
+      pango_font_description_free (font_desc);
+    }
+  else
+    mousepad_view_override_font (view, view->font_desc);
+}
+
+
+
 const gchar *
 mousepad_view_get_font_name (MousepadView *view)
 {
diff --git a/mousepad/org.xfce.Mousepad.gschema.xml b/mousepad/org.xfce.Mousepad.gschema.xml
index bd013f8..7f994b6 100644
--- a/mousepad/org.xfce.Mousepad.gschema.xml
+++ b/mousepad/org.xfce.Mousepad.gschema.xml
@@ -41,6 +41,15 @@
         font description syntax for greater control.
       </description>
     </key>
+    <key name="use-default-monospace-font" type="b">
+      <default>true</default>
+      <summary>Use default monospace font</summary>
+      <description>
+        When enabled, rather than using the font specified in the 'font-name'
+        setting, the default fixed-width font will be used (ie. the font
+        name 'Monospace').
+      </description>
+    </key>
     <key name="show-whitespace" type="b">
       <default>false</default>
       <summary>Show whitespace</summary>

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


More information about the Xfce4-commits mailing list