[gtk/fix-initial-font-selection] fontchooser: Fix initial font selection




commit 8caadaf4047952c30dce197130e4217186962ab4
Author: Matthias Clasen <mclasen redhat com>
Date:   Tue Mar 2 17:55:30 2021 -0500

    fontchooser: Fix initial font selection
    
    The change in 740559a54f to populate the list incrementally
    broke initial font selection. Fix that, by trying to select
    until the incremental filling is done.
    
    Fixes: #3687

 gtk/gtkfontchooserwidget.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)
---
diff --git a/gtk/gtkfontchooserwidget.c b/gtk/gtkfontchooserwidget.c
index 7e70bd1d58..be3b4cd027 100644
--- a/gtk/gtkfontchooserwidget.c
+++ b/gtk/gtkfontchooserwidget.c
@@ -1095,6 +1095,9 @@ add_languages_from_font (GtkFontChooserWidget *self,
 }
 #endif
 
+static gboolean
+gtk_font_chooser_widget_ensure_matching_selection (GtkFontChooserWidget *self);
+
 /* We incrementally populate our fontlist to prevent blocking
  * the font chooser for a long time with expensive FcFontSort
  * calls in pango for every row in the list).
@@ -1135,6 +1138,9 @@ add_to_fontlist (GtkWidget     *widget,
 
   gtk_slice_list_model_set_size (model, n);
 
+  if (gtk_single_selection_get_selected (GTK_SINGLE_SELECTION (self->selection)) == 
GTK_INVALID_LIST_POSITION)
+    gtk_font_chooser_widget_ensure_matching_selection (self);
+
   if (n == G_MAXUINT)
     return G_SOURCE_REMOVE;
   else
@@ -1348,7 +1354,7 @@ my_pango_font_family_equal (const char *familya,
   return g_ascii_strcasecmp (familya, familyb) == 0;
 }
 
-static void
+static gboolean
 gtk_font_chooser_widget_ensure_matching_selection (GtkFontChooserWidget *self)
 {
   const char *desc_family;
@@ -1358,7 +1364,7 @@ gtk_font_chooser_widget_ensure_matching_selection (GtkFontChooserWidget *self)
   if (desc_family == NULL)
     {
       gtk_single_selection_set_selected (self->selection, GTK_INVALID_LIST_POSITION);
-      return;
+      return TRUE;
     }
 
   n = g_list_model_get_n_items (G_LIST_MODEL (self->selection));
@@ -1397,7 +1403,13 @@ gtk_font_chooser_widget_ensure_matching_selection (GtkFontChooserWidget *self)
       pango_font_description_free (merged);
     }
 
-  gtk_single_selection_set_selected (self->selection, i);
+  if (i < n)
+    {
+      gtk_single_selection_set_selected (self->selection, i);
+      return TRUE;
+    }
+
+  return FALSE;
 }
 
 static PangoFontFace *
@@ -2352,6 +2364,7 @@ gtk_font_chooser_widget_take_font_desc (GtkFontChooserWidget *fontchooser,
   if (mask & (PANGO_FONT_MASK_FAMILY | PANGO_FONT_MASK_STYLE | PANGO_FONT_MASK_VARIANT |
               PANGO_FONT_MASK_WEIGHT | PANGO_FONT_MASK_STRETCH))
     {
+      gtk_single_selection_set_selected (fontchooser->selection, GTK_INVALID_LIST_POSITION);
       gtk_font_chooser_widget_ensure_matching_selection (fontchooser);
     }
 


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