[gcalctool/vala] Fix undo



commit 356cfbd500e14d2c99589c15e1f8e88d171c0781
Author: Robert Ancell <robert ancell canonical com>
Date:   Fri Oct 12 21:57:28 2012 +1300

    Fix undo

 src/math-equation.vala |   49 ++++++++++++++++++++++++-----------------------
 1 files changed, 25 insertions(+), 24 deletions(-)
---
diff --git a/src/math-equation.vala b/src/math-equation.vala
index df6a06a..6741820 100644
--- a/src/math-equation.vala
+++ b/src/math-equation.vala
@@ -17,24 +17,24 @@ public enum NumberMode
 }
 
 /* Expression mode state */
-private struct MathEquationState
+private class MathEquationState
 {
-    Number ans;             /* Previously calculated answer */
-    string expression;      /* Expression entered by user */
-    int ans_start;          /* Start character for ans variable in expression */
-    int ans_end;            /* End character for ans variable in expression */
-    int cursor;             /* ??? */
-    NumberMode number_mode; /* ??? */
-    bool can_super_minus;   /* true if entering minus can generate a superscript minus */
-    bool entered_multiply;  /* Last insert was a multiply character */
-    string status;          /* Equation status */
+    public Number ans;             /* Previously calculated answer */
+    public string expression;      /* Expression entered by user */
+    public int ans_start;          /* Start character for ans variable in expression */
+    public int ans_end;            /* End character for ans variable in expression */
+    public int cursor;             /* ??? */
+    public NumberMode number_mode; /* ??? */
+    public bool can_super_minus;   /* true if entering minus can generate a superscript minus */
+    public bool entered_multiply;  /* Last insert was a multiply character */
+    public string status;          /* Equation status */
 }
 
-private struct SolveData
+private class SolveData
 {
-    Number? number_result;
-    string text_result;
-    string error;
+    public Number? number_result;
+    public string text_result;
+    public string error;
 }
 
 public class MathEquation : Gtk.TextBuffer
@@ -123,8 +123,8 @@ public class MathEquation : Gtk.TextBuffer
     private Gtk.TextMark? ans_end_mark = null;
 
     private MathEquationState state;  /* Equation state */
-    private List<MathEquationState?> undo_stack; /* History of expression mode states */
-    private List<MathEquationState?> redo_stack;
+    private List<MathEquationState> undo_stack; /* History of expression mode states */
+    private List<MathEquationState> redo_stack;
     private bool in_undo_operation;
 
     private bool in_reformat;
@@ -136,12 +136,12 @@ public class MathEquation : Gtk.TextBuffer
     private MathVariables variables;
     private Serializer serializer;
 
-    private AsyncQueue<SolveData?> queue;
+    private AsyncQueue<SolveData> queue;
 
     public MathEquation ()
     {
-        undo_stack = new List<MathEquationState?> ();
-        redo_stack = new List<MathEquationState?> ();
+        undo_stack = new List<MathEquationState> ();
+        redo_stack = new List<MathEquationState> ();
 
         insert_text.connect (pre_insert_text_cb);
         delete_range.connect (pre_delete_range_cb);
@@ -168,6 +168,7 @@ public class MathEquation : Gtk.TextBuffer
 
         variables = new MathVariables ();
 
+        state = new MathEquationState ();
         state.status = "";
         word_size = 32;
         angle_units = AngleUnit.DEGREES;
@@ -177,7 +178,7 @@ public class MathEquation : Gtk.TextBuffer
         source_units = "";
         target_units = "";
         serializer = new Serializer (DisplayFormat.AUTOMATIC, 10, 9);
-        queue = new AsyncQueue<SolveData?> ();
+        queue = new AsyncQueue<SolveData> ();
 
         state.ans = new Number.integer (0);
 
@@ -363,7 +364,7 @@ public class MathEquation : Gtk.TextBuffer
             ans_end = iter.get_offset ();
         }
 
-        var s = MathEquationState ();
+        var s = new MathEquationState ();
         s.ans = state.ans;
         s.expression = display;
         s.ans_start = ans_start;
@@ -385,7 +386,7 @@ public class MathEquation : Gtk.TextBuffer
         status = "";
 
         /* Can't redo anymore */
-        redo_stack = new List<MathEquationState?> ();
+        redo_stack = new List<MathEquationState> ();
 
         state = get_current_state ();
         undo_stack.prepend (state);
@@ -813,7 +814,7 @@ public class MathEquation : Gtk.TextBuffer
      */
     private void* solve_real ()
     {
-        var solvedata = SolveData ();
+        var solvedata = new SolveData ();
 
         var text = get_equation ();
         /* Count the number of brackets and automatically add missing closing brackets */
@@ -950,7 +951,7 @@ public class MathEquation : Gtk.TextBuffer
             i++;
         }
 
-        var result = SolveData ();
+        var result = new SolveData ();
         result.text_result = text;
         queue.push (result);
 



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