[gtk/fontchooser-selection] fontchooser: Fix programmatic selection




commit 7000b2de8d0764655143e567349af290b0e1b6fd
Author: Matthias Clasen <mclasen redhat com>
Date:   Thu Dec 30 00:43:34 2021 -0500

    fontchooser: Fix programmatic selection
    
    The changes in 8caadaf4047952c30d did not work
    since the selection model is set to autoselect,
    so the first time items are added to the list,
    we select one.
    
    Fixes: #4564
    
    What this commit does not fix is scrolling the
    selected item into view.

 gtk/gtkfontchooserwidget.c     | 6 ++++--
 gtk/ui/gtkfontchooserwidget.ui | 1 +
 2 files changed, 5 insertions(+), 2 deletions(-)
---
diff --git a/gtk/gtkfontchooserwidget.c b/gtk/gtkfontchooserwidget.c
index 0ab9c8f228..47f8e08693 100644
--- a/gtk/gtkfontchooserwidget.c
+++ b/gtk/gtkfontchooserwidget.c
@@ -2334,10 +2334,12 @@ gtk_font_chooser_widget_merge_font_desc (GtkFontChooserWidget       *fontchooser
   if (mask & PANGO_FONT_MASK_SIZE)
     {
       double font_size = (double) pango_font_description_get_size (fontchooser->font_desc) / PANGO_SCALE;
-      /* XXX: This clamps, which can cause it to reloop into here, do we need
-       * to block its signal handler? */
+      g_signal_handlers_block_by_func (gtk_range_get_adjustment (GTK_RANGE (fontchooser->size_slider)), 
size_change_cb, fontchooser);
+      g_signal_handlers_block_by_func (gtk_spin_button_get_adjustment 
(GTK_SPIN_BUTTON(fontchooser->size_spin)), size_change_cb, fontchooser);
       gtk_range_set_value (GTK_RANGE (fontchooser->size_slider), font_size);
       gtk_spin_button_set_value (GTK_SPIN_BUTTON (fontchooser->size_spin), font_size);
+      g_signal_handlers_unblock_by_func (gtk_range_get_adjustment (GTK_RANGE (fontchooser->size_slider)), 
size_change_cb, fontchooser);
+      g_signal_handlers_unblock_by_func (gtk_spin_button_get_adjustment 
(GTK_SPIN_BUTTON(fontchooser->size_spin)), size_change_cb, fontchooser);
     }
   if (mask & (PANGO_FONT_MASK_FAMILY | PANGO_FONT_MASK_STYLE | PANGO_FONT_MASK_VARIANT |
               PANGO_FONT_MASK_WEIGHT | PANGO_FONT_MASK_STRETCH))
diff --git a/gtk/ui/gtkfontchooserwidget.ui b/gtk/ui/gtkfontchooserwidget.ui
index fdd9cf597a..076f9a057d 100644
--- a/gtk/ui/gtkfontchooserwidget.ui
+++ b/gtk/ui/gtkfontchooserwidget.ui
@@ -1,6 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface domain="gtk40">
   <object class="GtkSingleSelection" id="selection">
+    <property name="autoselect">0</property>
     <signal name="notify::selected-item" handler="selection_changed_cb" object="GtkFontChooserWidget" 
swapped="0"/>
     <signal name="items-changed" handler="rows_changed_cb" object="GtkFontChooserWidget" swapped="1"/>
     <property name="model">


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