[gcalctool/vala] Fix up MathEquation properties



commit d8206c00e0e151c3cc6df8b59ee611b27296198c
Author: Robert Ancell <robert ancell canonical com>
Date:   Fri Oct 12 22:20:57 2012 +1300

    Fix up MathEquation properties

 src/gcalctool.vala        |   22 ++++----
 src/math-buttons.vala     |   18 +++---
 src/math-display.vala     |    4 +-
 src/math-equation.vala    |  142 +++++++++++++++++++++-----------------------
 src/math-preferences.vala |   88 +++++++---------------------
 5 files changed, 112 insertions(+), 162 deletions(-)
---
diff --git a/src/gcalctool.vala b/src/gcalctool.vala
index 5484f51..0564944 100644
--- a/src/gcalctool.vala
+++ b/src/gcalctool.vala
@@ -52,12 +52,12 @@ public class GCalctool : Gtk.Application
         var target_units = settings.get_string ("target-units");
 
         var equation = new MathEquation ();
-        equation.set_accuracy (accuracy);
+        equation.accuracy = accuracy;
         equation.word_size = word_size;
-        equation.set_show_thousands_separators (show_tsep);
-        equation.set_show_trailing_zeroes (show_zeroes);
-        equation.set_number_format (number_format);
-        equation.set_angle_units (angle_units);
+        equation.show_thousands_separators = show_tsep;
+        equation.show_trailing_zeroes = show_zeroes;
+        equation.number_format = number_format;
+        equation.angle_units = angle_units;
         equation.source_currency = source_currency;
         equation.target_currency = target_currency;
         equation.source_units = source_units;
@@ -116,12 +116,12 @@ public class GCalctool : Gtk.Application
         var buttons = window.buttons;
 
         settings.set_enum ("button-mode", buttons.mode);
-        settings.set_int ("accuracy", equation.get_accuracy ());
+        settings.set_int ("accuracy", equation.accuracy);
         settings.set_int ("word-size", equation.word_size);
-        settings.set_boolean ("show-thousands", equation.get_show_thousands_separators ());
-        settings.set_boolean ("show-zeroes", equation.get_show_trailing_zeroes ());
-        settings.set_enum ("number-format", equation.get_number_format ());
-        settings.set_enum ("angle-units", equation.get_angle_units ());
+        settings.set_boolean ("show-thousands", equation.show_thousands_separators);
+        settings.set_boolean ("show-zeroes", equation.show_trailing_zeroes);
+        settings.set_enum ("number-format", equation.number_format);
+        settings.set_enum ("angle-units", equation.angle_units);
         settings.set_string ("source-currency", equation.source_currency);
         settings.set_string ("target-currency", equation.target_currency);
         settings.set_string ("source-units", equation.source_units);
@@ -244,7 +244,7 @@ public class GCalctool : Gtk.Application
         default:
         case ButtonMode.BASIC:
             state = "basic";
-            //FIXME: Should it revert to decimal mode? equation.set_number_format (window->priv->equation, DEC);
+            //FIXME: Should it revert to decimal mode? equation.number_format = NumberFormat.DECIMAL;
             break;
 
         case ButtonMode.ADVANCED:
diff --git a/src/math-buttons.vala b/src/math-buttons.vala
index 7b9c47f..e93d8b2 100644
--- a/src/math-buttons.vala
+++ b/src/math-buttons.vala
@@ -474,7 +474,7 @@ public class MathButtons : Gtk.Box
         if (toggle_button != null)
         {
             superscript_toggles.append (toggle_button);
-            if (equation.get_number_mode () == NumberMode.SUPERSCRIPT)
+            if (equation.number_mode == NumberMode.SUPERSCRIPT)
                 toggle_button.set_active (true);
             toggle_button.clicked.connect (set_superscript_cb);
         }
@@ -482,7 +482,7 @@ public class MathButtons : Gtk.Box
         if (toggle_button != null)
         {
             subscript_toggles.append (toggle_button);
-            if (equation.get_number_mode () == NumberMode.SUBSCRIPT)
+            if (equation.number_mode == NumberMode.SUBSCRIPT)
                 toggle_button.set_active (true);
             toggle_button.clicked.connect (set_subscript_cb);
         }
@@ -977,12 +977,12 @@ public class MathButtons : Gtk.Box
 
         if (button.get_active ())
         {
-            equation.set_number_mode (NumberMode.SUPERSCRIPT);
+            equation.number_mode = NumberMode.SUPERSCRIPT;
             if (!equation.get_has_selection ())
                 remove_trailing_spaces ();
         }
-        else if (equation.get_number_mode () == NumberMode.SUPERSCRIPT)
-            equation.set_number_mode (NumberMode.NORMAL);
+        else if (equation.number_mode == NumberMode.SUPERSCRIPT)
+            equation.number_mode = NumberMode.NORMAL;
     }
 
     private void set_subscript_cb (Gtk.Button widget)
@@ -991,17 +991,17 @@ public class MathButtons : Gtk.Box
 
         if (button.get_active ())
         {
-            equation.set_number_mode (NumberMode.SUBSCRIPT);
+            equation.number_mode = NumberMode.SUBSCRIPT;
             if (!equation.get_has_selection ())
                 remove_trailing_spaces ();
         }
-        else if (equation.get_number_mode () == NumberMode.SUBSCRIPT)
-            equation.set_number_mode (NumberMode.NORMAL);
+        else if (equation.number_mode == NumberMode.SUBSCRIPT)
+            equation.number_mode = NumberMode.NORMAL;
     }
 
     private void number_mode_changed_cb ()
     {
-        var mode = equation.get_number_mode ();
+        var mode = equation.number_mode;
         foreach (var toggle in superscript_toggles)
             toggle.set_active (mode == NumberMode.SUPERSCRIPT);
         foreach (var toggle in subscript_toggles)
diff --git a/src/math-display.vala b/src/math-display.vala
index 5ca12fc..256cd73 100644
--- a/src/math-display.vala
+++ b/src/math-display.vala
@@ -224,7 +224,7 @@ public class MathDisplay : Gtk.Viewport
             }
         }
 
-        if (state == Gdk.ModifierType.CONTROL_MASK || equation.get_number_mode () == NumberMode.SUPERSCRIPT)
+        if (state == Gdk.ModifierType.CONTROL_MASK || equation.number_mode == NumberMode.SUPERSCRIPT)
         {
             switch (event.keyval)
             {
@@ -270,7 +270,7 @@ public class MathDisplay : Gtk.Viewport
                 return true;
             }
         }
-        else if (state == Gdk.ModifierType.MOD1_MASK || equation.get_number_mode () == NumberMode.SUBSCRIPT)
+        else if (state == Gdk.ModifierType.MOD1_MASK || equation.number_mode == NumberMode.SUBSCRIPT)
         {
             switch (event.keyval)
             {
diff --git a/src/math-equation.vala b/src/math-equation.vala
index 6741820..d8f9173 100644
--- a/src/math-equation.vala
+++ b/src/math-equation.vala
@@ -113,8 +113,8 @@ public class MathEquation : Gtk.TextBuffer
         }
     }
 
-    private AngleUnit angle_units;  /* Units for trigonometric functions */
-    private NumberMode number_mode;   /* ??? */
+    private AngleUnit _angle_units;  /* Units for trigonometric functions */
+    private NumberMode _number_mode;   /* ??? */
     private bool can_super_minus; /* true if entering minus can generate a superscript minus */
 
     private unichar digits[16];      /* Localized digits */
@@ -171,7 +171,7 @@ public class MathEquation : Gtk.TextBuffer
         state = new MathEquationState ();
         state.status = "";
         word_size = 32;
-        angle_units = AngleUnit.DEGREES;
+        _angle_units = AngleUnit.DEGREES;
         // FIXME: Pick based on locale
         source_currency = "";
         target_currency = "";
@@ -435,7 +435,7 @@ public class MathEquation : Gtk.TextBuffer
             apply_tag (ans_tag, start, end);
         }
 
-        set_number_mode (s.number_mode);
+        number_mode = s.number_mode;
         can_super_minus = s.can_super_minus;
         state.entered_multiply = s.entered_multiply;
         status = s.status;
@@ -505,63 +505,59 @@ public class MathEquation : Gtk.TextBuffer
         return digits[digit];
     }
 
-    public void set_accuracy (int accuracy)
+    public int accuracy
     {
-        if (serializer.get_trailing_digits () == accuracy)
-            return;
-        serializer.set_trailing_digits (accuracy);
-        reformat_display ();
-        notify_property ("accuracy");
-    }
-
-    public int get_accuracy ()
-    {
-        return serializer.get_trailing_digits ();
+        get { return serializer.get_trailing_digits (); }
+        set
+        {
+            if (serializer.get_trailing_digits () == value)
+                return;
+            serializer.set_trailing_digits (value);
+            reformat_display ();
+            notify_property ("accuracy");
+        }
     }
 
-    public void set_show_thousands_separators (bool visible)
+    public bool show_thousands_separators
     {
-        if (serializer.get_show_thousands_separators () == visible)
-            return;
-
-        serializer.set_show_thousands_separators (visible);
-        reformat_display ();
-        notify_property ("show-thousands-separators");
-    }
+        get { return serializer.get_show_thousands_separators (); }
+        set
+        {
+            if (serializer.get_show_thousands_separators () == value)
+                return;
 
-    public bool get_show_thousands_separators ()
-    {
-        return serializer.get_show_thousands_separators ();
+            serializer.set_show_thousands_separators (value);
+            reformat_display ();
+            notify_property ("show-thousands-separators");
+        }
     }
 
-    public void set_show_trailing_zeroes (bool visible)
+    public bool show_trailing_zeroes
     {
-        if (serializer.get_show_trailing_zeroes () == visible)
-            return;
-
-        serializer.set_show_trailing_zeroes (visible);
-        reformat_display ();
-        notify_property ("show-trailing-zeroes");
-    }
+        get { return serializer.get_show_trailing_zeroes (); }
+        set
+        {
+            if (serializer.get_show_trailing_zeroes () == value)
+                return;
 
-    public bool get_show_trailing_zeroes ()
-    {
-        return serializer.get_show_trailing_zeroes ();
+            serializer.set_show_trailing_zeroes (value);
+            reformat_display ();
+            notify_property ("show-trailing-zeroes");
+        }
     }
 
-    public void set_number_format (DisplayFormat format)
+    public DisplayFormat number_format
     {
-        if (serializer.get_number_format () == format)
-            return;
-
-        serializer.set_number_format (format);
-        reformat_display ();
-        notify_property ("number-format");
-    }
+        get { return serializer.get_number_format (); }
+        set
+        {
+            if (serializer.get_number_format () == value)
+                return;
 
-    public DisplayFormat get_number_format ()
-    {
-        return serializer.get_number_format ();
+            serializer.set_number_format (value);
+            reformat_display ();
+            notify_property ("number-format");
+        }
     }
 
     public int number_base
@@ -578,18 +574,17 @@ public class MathEquation : Gtk.TextBuffer
         }
     }
 
-    public void set_angle_units (AngleUnit angle_units)
+    public AngleUnit angle_units
     {
-        if (this.angle_units == angle_units)
-            return;
-
-        this.angle_units = angle_units;
-        notify_property ("angle-units");
-    }
+        get { return _angle_units; }
+        set
+        {
+            if (_angle_units == value)
+                return;
 
-    public AngleUnit get_angle_units ()
-    {
-        return angle_units;
+            _angle_units = value;
+            notify_property ("angle-units");
+        }
     }
 
     public string status
@@ -666,20 +661,19 @@ public class MathEquation : Gtk.TextBuffer
         return serializer;
     }
 
-    public void set_number_mode (NumberMode mode)
+    public NumberMode number_mode
     {
-        if (number_mode == mode)
-            return;
-
-        can_super_minus = mode == NumberMode.SUPERSCRIPT;
+        get { return _number_mode; }
+        set
+        {
+            if (_number_mode == value)
+                return;
 
-        number_mode = mode;
-        notify_property ("number-mode");
-    }
+            can_super_minus = value == NumberMode.SUPERSCRIPT;
 
-    public NumberMode get_number_mode ()
-    {
-        return number_mode;
+            _number_mode = value;
+            notify_property ("number-mode");
+        }
     }
 
     public bool get_in_solve ()
@@ -746,7 +740,7 @@ public class MathEquation : Gtk.TextBuffer
 
         /* Disable super/subscript mode when finished entering */
         if ("ââÂÂÂââââââââââââââââ".index_of (text) >= 0)
-            set_number_mode (NumberMode.NORMAL);
+            number_mode = NumberMode.NORMAL;
 
         delete_selection (false, false);
         insert_at_cursor (text, -1);
@@ -781,7 +775,7 @@ public class MathEquation : Gtk.TextBuffer
     public void insert_exponent ()
     {
         insert ("Ã10");
-        set_number_mode (NumberMode.SUPERSCRIPT);
+        number_mode = NumberMode.SUPERSCRIPT;
     }
 
     public void insert_subtract ()
@@ -794,7 +788,7 @@ public class MathEquation : Gtk.TextBuffer
         else
         {
             insert ("â");
-            set_number_mode (NumberMode.NORMAL);
+            number_mode = NumberMode.NORMAL;
         }
     }
 
@@ -928,7 +922,7 @@ public class MathEquation : Gtk.TextBuffer
 
         in_solve = true;
 
-        set_number_mode (NumberMode.NORMAL);
+        number_mode = NumberMode.NORMAL;
 
         new Thread<void*> ("", solve_real);
 
@@ -1011,7 +1005,7 @@ public class MathEquation : Gtk.TextBuffer
 
     public void clear ()
     {
-        set_number_mode (NumberMode.NORMAL);
+        number_mode = NumberMode.NORMAL;
         set_text ("", -1);
         clear_ans (false);
     }
diff --git a/src/math-preferences.vala b/src/math-preferences.vala
index 66e66de..51b8582 100644
--- a/src/math-preferences.vala
+++ b/src/math-preferences.vala
@@ -100,7 +100,7 @@ public class MathPreferencesDialog : Gtk.Dialog
         }
 
         decimal_places_spin.show ();
-        decimal_places_spin.value_changed.connect (decimal_places_spin_change_value_cb);
+        decimal_places_spin.value_changed.connect (() => { equation.accuracy = decimal_places_spin.get_value_as_int (); });
         places_box.pack_start (decimal_places_spin, false, false, 0);
 
         if (tokens.length == 2)
@@ -114,13 +114,13 @@ public class MathPreferencesDialog : Gtk.Dialog
         trailing_zeroes_check = new Gtk.CheckButton.with_mnemonic (/* Preferences dialog: label for show trailing zeroes check button */
                                                                    _("Show trailing _zeroes"));
         trailing_zeroes_check.show ();
-        trailing_zeroes_check.toggled.connect (trailing_zeroes_check_toggled_cb);
+        trailing_zeroes_check.toggled.connect (() => { equation.show_trailing_zeroes = trailing_zeroes_check.get_active (); });
         format_options_box.pack_start (trailing_zeroes_check, false, false, 0);
 
         thousands_separator_check = new Gtk.CheckButton.with_mnemonic (/* Preferences dialog: label for show show thousands separator check button */
                                                                        _("Show _thousands separators"));
         thousands_separator_check.show ();
-        thousands_separator_check.toggled.connect (thousands_separator_check_toggled_cb);
+        thousands_separator_check.toggled.connect (() => { equation.show_thousands_separators = thousands_separator_check.get_active (); });
         format_options_box.pack_start (thousands_separator_check, false, false, 0);
 
         label = new Gtk.Label.with_mnemonic (/* Preferences dialog: Label for angle unit combo box */
@@ -179,19 +179,23 @@ public class MathPreferencesDialog : Gtk.Dialog
         word_size_combo.pack_start (renderer, true);
         word_size_combo.add_attribute (renderer, "text", 0);
 
-        equation.notify["accuracy"].connect ((pspec) => { accuracy_cb (); });
-        equation.notify["show-thousands-separators"].connect ((pspec) => { show_thousands_separators_cb (); });
-        equation.notify["show-trailing_zeroes"].connect ((pspec) => { show_trailing_zeroes_cb (); });
-        equation.notify["number-format"].connect ((pspec) => { number_format_cb (); });
-        equation.notify["word-size"].connect ((pspec) => { word_size_cb (); });
-        equation.notify["angle-units"].connect ((pspec) => { angle_unit_cb (); });
-
-        accuracy_cb ();
-        show_thousands_separators_cb ();
-        show_trailing_zeroes_cb ();
-        number_format_cb ();
-        word_size_cb ();
-        angle_unit_cb ();
+        decimal_places_spin.set_value (equation.accuracy);
+        equation.notify["accuracy"].connect ((pspec) => { decimal_places_spin.set_value (equation.accuracy); });
+
+        thousands_separator_check.set_active (equation.show_thousands_separators);
+        equation.notify["show-thousands-separators"].connect (() => { thousands_separator_check.set_active (equation.show_thousands_separators); });
+
+        trailing_zeroes_check.set_active (equation.show_trailing_zeroes);
+        equation.notify["show-trailing_zeroes"].connect (() => { trailing_zeroes_check.set_active (equation.show_trailing_zeroes); });
+
+        set_combo_box_from_int (number_format_combo, equation.number_format);
+        equation.notify["number-format"].connect ((pspec) => { set_combo_box_from_int (number_format_combo, equation.number_format); });
+
+        set_combo_box_from_int (word_size_combo, equation.word_size);
+        equation.notify["word-size"].connect ((pspec) => { set_combo_box_from_int (word_size_combo, equation.word_size); });
+
+        set_combo_box_from_int (angle_unit_combo, equation.angle_units);
+        equation.notify["angle-units"].connect ((pspec) => { set_combo_box_from_int (angle_unit_combo, equation.angle_units); });
     }
 
     protected override void response (int id)
@@ -211,7 +215,7 @@ public class MathPreferencesDialog : Gtk.Dialog
         combo.get_active_iter (out iter);
         DisplayFormat value;
         combo.model.get (iter, 1, out value, -1);
-        equation.set_number_format (value);
+        equation.number_format = value;
     }
 
     private void angle_unit_combo_changed_cb (Gtk.ComboBox combo)
@@ -220,7 +224,7 @@ public class MathPreferencesDialog : Gtk.Dialog
         combo.get_active_iter (out iter);
         AngleUnit value;
         combo.model.get (iter, 1, out value, -1);
-        equation.set_angle_units (value);
+        equation.angle_units = value;
     }
 
     private void word_size_combo_changed_cb (Gtk.ComboBox combo)
@@ -232,54 +236,6 @@ public class MathPreferencesDialog : Gtk.Dialog
         equation.word_size = value;
     }
 
-    private void decimal_places_spin_change_value_cb (Gtk.SpinButton spin)
-    {
-        var value = spin.get_value_as_int ();
-        equation.set_accuracy (value);
-    }
-
-    private void thousands_separator_check_toggled_cb (Gtk.ToggleButton check)
-    {
-        var value = check.get_active ();
-        equation.set_show_thousands_separators (value);
-    }
-
-    private void trailing_zeroes_check_toggled_cb (Gtk.ToggleButton check)
-    {
-        var value = check.get_active ();
-        equation.set_show_trailing_zeroes (value);
-    }
-
-    private void accuracy_cb ()
-    {
-        decimal_places_spin.set_value (equation.get_accuracy ());
-    }
-
-    private void show_thousands_separators_cb ()
-    {
-        thousands_separator_check.set_active (equation.get_show_thousands_separators ());
-    }
-
-    private void show_trailing_zeroes_cb ()
-    {
-        trailing_zeroes_check.set_active (equation.get_show_trailing_zeroes ());
-    }
-
-    private void number_format_cb ()
-    {
-        set_combo_box_from_int (number_format_combo, equation.get_number_format ());
-    }
-
-    private void word_size_cb ()
-    {
-        set_combo_box_from_int (word_size_combo, equation.word_size);
-    }
-
-    private void angle_unit_cb ()
-    {
-        set_combo_box_from_int (angle_unit_combo, equation.get_angle_units ());
-    }
-
     private void set_combo_box_from_int (Gtk.ComboBox combo, int value)
     {
         Gtk.TreeIter iter;



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