[gnome-text-editor] prefs: fix keyboard activation of style schemes



commit 6524b5d6dfc8978d37874e4da4100f84ab380602
Author: Christian Hergert <chergert redhat com>
Date:   Tue Dec 28 13:27:58 2021 -0800

    prefs: fix keyboard activation of style schemes
    
    Fixes #273

 src/editor-preferences-dialog.c  | 19 +++++++++++++++++++
 src/editor-preferences-dialog.ui |  1 +
 2 files changed, 20 insertions(+)
---
diff --git a/src/editor-preferences-dialog.c b/src/editor-preferences-dialog.c
index e3a15e4..cc7ef90 100644
--- a/src/editor-preferences-dialog.c
+++ b/src/editor-preferences-dialog.c
@@ -337,6 +337,24 @@ update_custom_font_cb (EditorPreferencesDialog *self,
   gtk_css_provider_load_from_data (self->css_provider, "", -1);
 }
 
+static void
+style_scheme_activated_cb (EditorPreferencesDialog *self,
+                           GtkFlowBoxChild         *child,
+                           GtkFlowBox              *flow_box)
+{
+  GtkWidget *preview;
+
+  g_assert (EDITOR_IS_PREFERENCES_DIALOG (self));
+  g_assert (GTK_IS_FLOW_BOX_CHILD (child));
+  g_assert (GTK_IS_FLOW_BOX (flow_box));
+
+  if ((preview = gtk_flow_box_child_get_child (child)))
+    {
+      g_assert (GTK_SOURCE_IS_STYLE_SCHEME_PREVIEW (preview));
+      gtk_widget_activate (preview);
+    }
+}
+
 static void
 editor_preferences_dialog_constructed (GObject *object)
 {
@@ -373,6 +391,7 @@ editor_preferences_dialog_class_init (EditorPreferencesDialogClass *klass)
   gtk_widget_class_bind_template_child (widget_class, EditorPreferencesDialog, scheme_group);
   gtk_widget_class_bind_template_child (widget_class, EditorPreferencesDialog, source_view);
   gtk_widget_class_bind_template_child (widget_class, EditorPreferencesDialog, use_custom_font);
+  gtk_widget_class_bind_template_callback (widget_class, style_scheme_activated_cb);
 
   g_type_ensure (EDITOR_TYPE_PREFERENCES_FONT);
   g_type_ensure (EDITOR_TYPE_PREFERENCES_SPIN);
diff --git a/src/editor-preferences-dialog.ui b/src/editor-preferences-dialog.ui
index f8f384c..6726572 100644
--- a/src/editor-preferences-dialog.ui
+++ b/src/editor-preferences-dialog.ui
@@ -41,6 +41,7 @@
             </child>
             <child>
               <object class="GtkFlowBox" id="scheme_group">
+                <signal name="child-activated" handler="style_scheme_activated_cb" swapped="true"/>
                 <property name="hexpand">true</property>
                 <property name="column-spacing">0</property>
                 <property name="row-spacing">0</property>


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