[gnome-calculator/wip-gtk4-port] Use changed listener instead of key listener for variable popover



commit 1d12f5f6ee00f4fe7561ba7d21b20f711d84df7e
Author: Robert Roth <robert roth off gmail com>
Date:   Fri Oct 1 12:18:41 2021 +0300

    Use changed listener instead of key listener for variable popover

 src/math-variable-popover.vala  | 16 ++++------------
 src/ui/math-variable-popover.ui |  1 -
 2 files changed, 4 insertions(+), 13 deletions(-)
---
diff --git a/src/math-variable-popover.vala b/src/math-variable-popover.vala
index a6c67981..187fcdad 100644
--- a/src/math-variable-popover.vala
+++ b/src/math-variable-popover.vala
@@ -79,19 +79,11 @@ public class MathVariablePopover : Gtk.Popover
     }
 
     [GtkCallback]
-    private bool variable_name_key_press_cb (Gtk.Widget widget, Gdk.EventKey event)
+    private void variable_name_changed_cb (Gtk.Editable editable)
     {
-        /* Can't have whitespace in names, so replace with underscores */
-        if (event.keyval == Gdk.Key.space || event.keyval == Gdk.Key.KP_Space)
-            event.keyval = Gdk.Key.underscore;
-
-        return false;
-    }
-
-    [GtkCallback]
-    private void variable_name_changed_cb ()
-    {
-        store_variable_button.sensitive = (variable_name_entry.get_text () != "");
+        var entry = editable as Gtk.Entry;
+        entry.text = entry.text.replace (" ", "_");
+        store_variable_button.sensitive = (entry.text != "");
     }
 
     [GtkCallback]
diff --git a/src/ui/math-variable-popover.ui b/src/ui/math-variable-popover.ui
index 7a4c5d1a..bf1a43ae 100644
--- a/src/ui/math-variable-popover.ui
+++ b/src/ui/math-variable-popover.ui
@@ -39,7 +39,6 @@
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
                 <property name="receives_default">True</property>
-                <signal name="key_press_event" handler="variable_name_key_press_cb" swapped="no"/>
                 <signal name="changed" handler="variable_name_changed_cb" swapped="no"/>
                 <signal name="activate" handler="store_variable_cb" swapped="no"/>
               </object>


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