[gcalctool/vala] Tidy up MathEquation



commit f8aab1c97780525c497c8c062b2c6b2fc7cf8d90
Author: Robert Ancell <robert ancell canonical com>
Date:   Sat Oct 13 20:49:31 2012 +1300

    Tidy up MathEquation

 src/math-equation.vala |   52 +++++++++++++++++------------------------------
 1 files changed, 19 insertions(+), 33 deletions(-)
---
diff --git a/src/math-equation.vala b/src/math-equation.vala
index b5fcea6..5f26972 100644
--- a/src/math-equation.vala
+++ b/src/math-equation.vala
@@ -143,11 +143,6 @@ public class MathEquation : Gtk.TextBuffer
         undo_stack = new List<MathEquationState> ();
         redo_stack = new List<MathEquationState> ();
 
-        insert_text.connect (pre_insert_text_cb);
-        delete_range.connect (pre_delete_range_cb);
-        insert_text.connect_after (insert_text_cb);
-        delete_range.connect_after (delete_range_cb);
-
         /* Default to using untranslated digits, this is because it doesn't make sense in most languages and we need to make this optional.
          * See https://bugzilla.gnome.org/show_bug.cgi?id=632661 */
         var use_default_digits = true;
@@ -1041,13 +1036,15 @@ public class MathEquation : Gtk.TextBuffer
         set_number (x);
     }
 
-    private void pre_insert_text_cb (Gtk.TextIter location, string text, int len)
+    protected override void insert_text (ref Gtk.TextIter location, string text, int len)
     {
         if (in_reformat)
+        {
+            base.insert_text (ref location, text, len);
             return;
+        }
 
-        /* If following a delete then have already pushed undo stack (Gtk.TextBuffer
-           doesn't indicate replace operations so we have to infer them) */
+        /* If following a delete then have already pushed undo stack (Gtk.TextBuffer doesn't indicate replace operations so we have to infer them) */
         if (!in_delete)
             push_undo_stack ();
 
@@ -1072,23 +1069,29 @@ public class MathEquation : Gtk.TextBuffer
             if (offset > ans_start && offset < ans_end)
                 clear_ans (true);
         }
-    }
 
-    private bool on_delete ()
-    {
-        in_delete = false;
-        return false;
+        base.insert_text (ref location, text, len);
+
+        state.entered_multiply = text == "Ã";
+
+        /* Update thousands separators */
+        reformat_separators ();
+
+        notify_property ("display");
     }
 
-    private void pre_delete_range_cb (Gtk.TextIter start, Gtk.TextIter end)
+    protected override void delete_range (Gtk.TextIter start, Gtk.TextIter end)
     {
         if (in_reformat)
+        {
+            base.delete_range (start, end);
             return;
+        }
 
         push_undo_stack ();
 
         in_delete = true;
-        Idle.add (on_delete);
+        Idle.add (() => { in_delete = false; return false; });
 
         if (ans_start_mark != null)
         {
@@ -1101,25 +1104,8 @@ public class MathEquation : Gtk.TextBuffer
             if (start_offset < ans_end && end_offset > ans_start)
                 clear_ans (true);
         }
-    }
 
-    private void insert_text_cb (Gtk.TextIter location, string text, int len)
-    {
-        if (in_reformat)
-            return;
-
-        state.entered_multiply = text == "Ã";
-
-        /* Update thousands separators */
-        reformat_separators ();
-
-        notify_property ("display");
-    }
-
-    private void delete_range_cb (Gtk.TextIter start, Gtk.TextIter end)
-    {
-        if (in_reformat)
-            return;
+        base.delete_range (start, end);
 
         state.entered_multiply = false;
 



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