[gtk+/wip/matthiasc/font-variations: 52/62] font chooser: Add a monospace filter



commit c10b1f419bac3093dc92a5e28b5beabbb6949358
Author: Matthias Clasen <mclasen redhat com>
Date:   Thu Dec 28 08:17:21 2017 -0500

    font chooser: Add a monospace filter
    
    Since it is easy to do, why not.

 gtk/gtkfontchooserwidget.c     |   21 +++++++++++++++++++++
 gtk/ui/gtkfontchooserwidget.ui |    6 ++++++
 2 files changed, 27 insertions(+), 0 deletions(-)
---
diff --git a/gtk/gtkfontchooserwidget.c b/gtk/gtkfontchooserwidget.c
index 46380ef..44f2858 100644
--- a/gtk/gtkfontchooserwidget.c
+++ b/gtk/gtkfontchooserwidget.c
@@ -122,6 +122,8 @@ struct _GtkFontChooserWidgetPrivate
   GtkWidget    *language_filter_entry;
   char         *language_term;
 
+  GtkWidget    *monospace_filter_check;
+
   GtkWidget       *preview;
   gchar           *preview_text;
   gboolean         show_preview_entry;
@@ -750,6 +752,7 @@ gtk_font_chooser_widget_class_init (GtkFontChooserWidgetClass *klass)
   gtk_widget_class_bind_template_child_private (widget_class, GtkFontChooserWidget, 
language_filter_button_label);
   gtk_widget_class_bind_template_child_private (widget_class, GtkFontChooserWidget, language_list);
   gtk_widget_class_bind_template_child_private (widget_class, GtkFontChooserWidget, language_filter_entry);
+  gtk_widget_class_bind_template_child_private (widget_class, GtkFontChooserWidget, monospace_filter_check);
 
   gtk_widget_class_bind_template_callback (widget_class, text_changed_cb);
   gtk_widget_class_bind_template_callback (widget_class, stop_search_cb);
@@ -771,6 +774,7 @@ gtk_font_chooser_widget_class_init (GtkFontChooserWidgetClass *klass)
   gtk_widget_class_bind_template_callback (widget_class, language_filter_stop);
   gtk_widget_class_bind_template_callback (widget_class, language_filter_activated);
   gtk_widget_class_bind_template_callback (widget_class, popover_notify);
+  gtk_widget_class_bind_template_callback (widget_class, gtk_font_chooser_widget_refilter_font_list);
 
   gtk_widget_class_set_css_name (widget_class, I_("fontchooser"));
 }
@@ -1562,6 +1566,23 @@ visible_func (GtkTreeModel *model,
         }
     }
 
+  if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->monospace_filter_check)))
+    {
+      PangoFontFamily *family;
+
+      gtk_tree_model_get (priv->model, iter,
+                          FAMILY_COLUMN, &family,
+                          -1);
+
+      if (!pango_font_family_is_monospace (family))
+        result = FALSE;
+
+      g_object_unref (family);
+
+      if (!result)
+        return FALSE;
+    }
+
   if (priv->filter_func != NULL)
     {
       PangoFontFamily *family;
diff --git a/gtk/ui/gtkfontchooserwidget.ui b/gtk/ui/gtkfontchooserwidget.ui
index ad5c78c..2182cc7 100644
--- a/gtk/ui/gtkfontchooserwidget.ui
+++ b/gtk/ui/gtkfontchooserwidget.ui
@@ -368,6 +368,12 @@ emblem-documents-symbolic</property>
             </child>
           </object>
         </child>
+        <child>
+          <object class="GtkCheckButton" id="monospace_filter_check">
+            <property name="label" translatable="yes">Only monospace</property>
+            <signal name="notify::active" handler="gtk_font_chooser_widget_refilter_font_list" 
swapped="yes"/>
+          </object>
+        </child>
       </object>
     </child>
   </object>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]