[gtk: 1/2] PrintUnixDialog: Slightly ease page range entry



commit 76b2f97602b70b48396b026cdc02234d9f83dc06
Author: Guillaume Maudoux <layus on gmail com>
Date:   Thu Jun 13 21:11:56 2019 +0000

    PrintUnixDialog: Slightly ease page range entry
    
    Page ranges entry can now be focused directly, and will automatically
    select the page ranges button when doing so.
    This avoids the sometimes counter-intuitive previous behavior where the
    entry was automatically focused when toggling the radio button, but the
    user may still find themselves clicking uselessly in the text entry
    because they scheduled it in their mental model.

 gtk/gtkprintunixdialog.c     | 19 +++++++++++++++++--
 gtk/ui/gtkprintunixdialog.ui |  2 +-
 2 files changed, 18 insertions(+), 3 deletions(-)
---
diff --git a/gtk/gtkprintunixdialog.c b/gtk/gtkprintunixdialog.c
index c1917999eb..d2d516c569 100644
--- a/gtk/gtkprintunixdialog.c
+++ b/gtk/gtkprintunixdialog.c
@@ -157,6 +157,9 @@ static void     emit_ok_response                   (GtkTreeView        *tree_vie
                                                    GtkTreePath        *path,
                                                    GtkTreeViewColumn  *column,
                                                    gpointer           *user_data);
+static gboolean page_range_entry_focus_changed     (GtkWidget          *entry,
+                                                    GParamSpec         *pspec,
+                                                    GtkPrintUnixDialog *dialog);
 static void     update_page_range_entry_sensitivity(GtkWidget          *button,
                                                    GtkPrintUnixDialog *dialog);
 static void     update_print_at_entry_sensitivity  (GtkWidget          *button,
@@ -562,6 +565,7 @@ gtk_print_unix_dialog_class_init (GtkPrintUnixDialogClass *class)
   gtk_widget_class_bind_template_callback (widget_class, error_dialogs);
   gtk_widget_class_bind_template_callback (widget_class, emit_ok_response);
   gtk_widget_class_bind_template_callback (widget_class, selected_printer_changed);
+  gtk_widget_class_bind_template_callback (widget_class, page_range_entry_focus_changed);
   gtk_widget_class_bind_template_callback (widget_class, update_page_range_entry_sensitivity);
   gtk_widget_class_bind_template_callback (widget_class, update_print_at_entry_sensitivity);
   gtk_widget_class_bind_template_callback (widget_class, update_print_at_option);
@@ -2308,6 +2312,19 @@ draw_collate (GtkDrawingArea *da,
     }
 }
 
+static gboolean
+page_range_entry_focus_changed (GtkWidget          *entry,
+                                GParamSpec         *pspec,
+                                GtkPrintUnixDialog *dialog)
+{
+  GtkPrintUnixDialogPrivate *priv = gtk_print_unix_dialog_get_instance_private (dialog);
+
+  if (gtk_widget_has_focus (entry))
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->page_range_radio), TRUE);
+
+  return FALSE;
+}
+
 static void
 update_page_range_entry_sensitivity (GtkWidget *button,
                                     GtkPrintUnixDialog *dialog)
@@ -2317,8 +2334,6 @@ update_page_range_entry_sensitivity (GtkWidget *button,
 
   active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
 
-  gtk_widget_set_sensitive (priv->page_range_entry, active);
-
   if (active)
     gtk_widget_grab_focus (priv->page_range_entry);
 }
diff --git a/gtk/ui/gtkprintunixdialog.ui b/gtk/ui/gtkprintunixdialog.ui
index bacfd31e07..ef905ecdbf 100644
--- a/gtk/ui/gtkprintunixdialog.ui
+++ b/gtk/ui/gtkprintunixdialog.ui
@@ -225,11 +225,11 @@
                                     </child>
                                     <child>
                                       <object class="GtkEntry" id="page_range_entry">
-                                        <property name="sensitive">0</property>
                                         <property name="can-focus">1</property>
                                         <property name="tooltip-text" translatable="yes">Specify one or more 
page ranges,
  e.g. 1–3, 7, 11</property>
                                         <property name="activates-default">1</property>
+                                        <signal name="notify::has-focus" 
handler="page_range_entry_focus_changed" swapped="no"/>
                                         <child internal-child="accessible">
                                           <object class="AtkObject" id="page_range_entry-atkobject">
                                             <property name="AtkObject::accessible-name" 
translatable="yes">Pages</property>


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