[gnome-calculator/currency-display-format] Edited combobox_changed_cb so that to model gets updated



commit c10bcd6fa6cd1d6ebb7d44f044e0b7a7237dd6e5
Author: A.M. Rowsell <amrowsell frozenelectronics ca>
Date:   Wed Nov 4 18:30:46 2020 -0500

    Edited combobox_changed_cb so that to model gets updated
    
    However, this has introduced a regression: the to model now gets
    updated every time the from box is changed, which is not what we
    want. There's a couple options to fix this; copy the code that
    updates the to model into the new update_currency_labels() function;
    have some sort of boolean value that tells us whether the to model
    needs to be updated (only set to true when the currency format
    setting is changed, and then cleared after the models are updated)
    or adding an else statemet to the if (category != to_category)
    that updates the models only when the categories are different?
    
    Pushing this so Robert Roth can take a look @robertroth

 src/math-converter.vala    | 48 ++++++++++++++++------------------------------
 src/ui/math-preferences.ui |  2 +-
 2 files changed, 17 insertions(+), 33 deletions(-)
---
diff --git a/src/math-converter.vala b/src/math-converter.vala
index 11d0b59f..25eeb948 100644
--- a/src/math-converter.vala
+++ b/src/math-converter.vala
@@ -38,7 +38,7 @@ public class MathConverter : Gtk.Grid
     construct
     {
         settings = new Settings ("org.gnome.calculator");
-        settings.changed["currency-display-format"].connect (() => { update_financial_labels (); });
+        settings.changed["currency-display-format"].connect (() => { update_currency_labels (); });
         from_combo.set_cell_data_func (from_renderer, from_cell_data_func);
         CurrencyManager.get_default ().updated.connect (() => { update_result_label (); });
 
@@ -121,7 +121,7 @@ public class MathConverter : Gtk.Grid
         }
     }
 
-    private void update_financial_labels ()
+    private void update_currency_labels ()
     {
         update_from_model ();
         from_combobox_changed_cb ();
@@ -172,27 +172,7 @@ public class MathConverter : Gtk.Grid
             {
                 Gtk.TreeIter iter;
                 from_model.append (out iter, null);
-                if (c.name == "currency")
-                {
-                    var CurrencyFormat = settings.get_int ("currency-display-format");
-                    if (CurrencyFormat == 0) /* Currency names */
-                    {
-                        from_model.set (iter, 0, unit.display_name, 1, c, 2, unit, -1);
-                    }
-                    else if (CurrencyFormat == 1) /* Currency code */
-                    {
-                        from_model.set (iter, 0, unit.name, 1, c, 2, unit, -1);
-                    }
-                    else if (CurrencyFormat == 2) /* Both */
-                    {
-                        string DisplayName = unit.display_name + " " + unit.name;
-                        from_model.set (iter, 0, DisplayName, 1, c, 2, unit, -1);
-                    }
-                }
-                else
-                {
-                    from_model.set (iter, 0, unit.display_name, 1, c, 2, unit, -1);
-                }
+                from_model.set (iter, 0, get_unit_display_name (c, unit), 1, c, 2, unit, -1);
             }
         }
 
@@ -245,20 +225,24 @@ public class MathConverter : Gtk.Grid
         if (to_combo.get_active_iter (out to_iter))
             to_model.get (to_iter, 1, out to_category);
 
-        if (category != to_category)
+        /* FIXME: by taking this section out of the below if statement,
+         * it causes the to combo box to be reset every time the user selects
+         * something in the from box... which is not ideal */
+        /* Set the to combobox to be the list of units can be converted to */
+        to_model = new Gtk.ListStore (3, typeof (string), typeof (UnitCategory), typeof (Unit));
+        foreach (var u in category.get_units ())
         {
-            /* Set the to combobox to be the list of units can be converted to */
-            to_model = new Gtk.ListStore (3, typeof (string), typeof (UnitCategory), typeof (Unit));
-            foreach (var u in category.get_units ())
-            {
-                to_model.append (out iter);
-                to_model.set (iter, 0, get_unit_display_name(category, u), 1, category, 2, u, -1);
-            }
-            to_combo.model = to_model;
+            to_model.append (out iter);
+            to_model.set (iter, 0, get_unit_display_name(category, u), 1, category, 2, u, -1);
+        }
+        to_combo.model = to_model;
 
+        if (category != to_category)
+        {
             /* Select the first possible unit */
             to_combo.set_active (0);
         }
+
     }
 
     [GtkCallback]
diff --git a/src/ui/math-preferences.ui b/src/ui/math-preferences.ui
index 6985fb0f..4910e380 100644
--- a/src/ui/math-preferences.ui
+++ b/src/ui/math-preferences.ui
@@ -224,7 +224,7 @@
                 <property name="visible">True</property>
                 <property name="can-focus">False</property>
                 <property name="halign">start</property>
-                <property name="label" translatable="yes">Currenc_y format (requires restart)</property>
+                <property name="label" translatable="yes">Currenc_y format</property>
                 <property name="use-underline">True</property>
               </object>
               <packing>


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