[gnome-calculator] Fixed crash on variable name entry (fixes #282)



commit 5b387d03f434922e1811919aedb2d475cc874da4
Author: Robert Roth <robert roth off gmail com>
Date:   Tue Jun 14 10:01:52 2022 +0300

    Fixed crash on variable name entry (fixes #282)

 src/math-variable-popover.vala  | 6 +++++-
 src/ui/math-variable-popover.ui | 1 -
 2 files changed, 5 insertions(+), 2 deletions(-)
---
diff --git a/src/math-variable-popover.vala b/src/math-variable-popover.vala
index 2318934d..76b17eea 100644
--- a/src/math-variable-popover.vala
+++ b/src/math-variable-popover.vala
@@ -42,11 +42,14 @@ public class MathVariablePopover : MathPopover<MathVariable>
     [GtkChild]
     private unowned Gtk.Button store_variable_button;
 
+    private ulong changed_handler;
+
     public MathVariablePopover (MathEquation equation, ListStore model, CompareDataFunc compare_func)
     {
         base(equation, model, (a,b) => MathVariable.name_compare_func(a as MathVariable,b as MathVariable));
 
         variable_list.bind_model (model, (variable) => make_item_row (variable as MathVariable));
+        changed_handler = variable_name_entry.changed.connect (variable_name_changed_cb);
         equation.history_signal.connect (this.handler);
         item_deleted.connect (delete_variable_cb);
     }
@@ -72,11 +75,12 @@ public class MathVariablePopover : MathPopover<MathVariable>
         equation.insert (variable.name);
     }
 
-    [GtkCallback]
     private void variable_name_changed_cb (Gtk.Editable editable)
     {
         var entry = editable as Gtk.Entry;
+        SignalHandler.block (entry, changed_handler);
         entry.text = entry.text.replace (" ", "_");
+        SignalHandler.unblock (entry, changed_handler);
         store_variable_button.sensitive = (entry.text != "");
     }
 
diff --git a/src/ui/math-variable-popover.ui b/src/ui/math-variable-popover.ui
index cb98fc49..17ed4c8a 100644
--- a/src/ui/math-variable-popover.ui
+++ b/src/ui/math-variable-popover.ui
@@ -30,7 +30,6 @@
               <object class="GtkEntry" id="variable_name_entry">
                 <property name="placeholder_text" translatable="yes">Variable name</property>
                 <property name="receives_default">True</property>
-                <signal name="changed" handler="variable_name_changed_cb" swapped="no"/>
                 <signal name="activate" handler="store_variable_cb" swapped="no"/>
               </object>
             </child>


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