Commit d6c1d26a authored by Robert Roth's avatar Robert Roth

Ignore keypresses while calculating result (fixes #47)

parent 7899ad89
Pipeline #72470 passed with stages
in 16 minutes and 46 seconds
......@@ -135,6 +135,8 @@ public class MathEquation : Gtk.SourceBuffer
private bool in_reformat;
private bool in_delete;
private uint in_progress_timeout;
private uint looking_for_answer_timeout;
private bool _in_solve;
public bool in_solve
......@@ -1105,8 +1107,8 @@ public class MathEquation : Gtk.SourceBuffer
new Thread<void*> ("", solve_real);
Timeout.add (50, look_for_answer);
Timeout.add (100, show_in_progress);
looking_for_answer_timeout = Timeout.add (50, look_for_answer);
in_progress_timeout = Timeout.add (100, show_in_progress);
}
/* Fix the offsets to consider thousand separators inserted by the gui. */
......@@ -1209,6 +1211,8 @@ public class MathEquation : Gtk.SourceBuffer
{
var x = number;
var factors = x.factorize ();
var result = new SolveData ();
queue.push (result);
var text = "";
var i = 0;
......@@ -1220,9 +1224,7 @@ public class MathEquation : Gtk.SourceBuffer
i++;
}
var result = new SolveData ();
result.text_result = text;
queue.push (result);
return null;
}
......@@ -1245,8 +1247,8 @@ public class MathEquation : Gtk.SourceBuffer
new Thread<void*> ("", factorize_real);
Timeout.add (50, look_for_answer);
Timeout.add (100, show_in_progress);
looking_for_answer_timeout = Timeout.add (50, look_for_answer);
in_progress_timeout = Timeout.add (100, show_in_progress);
}
public void delete_next ()
......@@ -1283,6 +1285,12 @@ public class MathEquation : Gtk.SourceBuffer
number_mode = NumberMode.NORMAL;
set_text ("", -1);
clear_ans (false);
if (in_solve) {
_in_solve = false;
queue.try_pop ();
Source.remove (looking_for_answer_timeout);
Source.remove (in_progress_timeout);
}
}
public void insert_shift (int count)
......
......@@ -148,6 +148,20 @@ public class MathDisplay : Gtk.Viewport
private bool key_press_cb (Gdk.EventKey event)
{
/* Clear on escape */
var state = event.state & (Gdk.ModifierType.CONTROL_MASK | Gdk.ModifierType.MOD1_MASK);
if ((event.keyval == Gdk.Key.Escape && state == 0) ||
(event.keyval == Gdk.Key.Delete && state == Gdk.ModifierType.SHIFT_MASK))
{
equation.clear ();
status_changed_cb ();
return true;
}
/* Ignore keypresses while calculating */
if (equation.in_solve)
return true;
/* Treat keypad keys as numbers even when numlock is off */
uint new_keyval = 0;
switch (event.keyval)
......@@ -194,7 +208,6 @@ public class MathDisplay : Gtk.Viewport
return key_press_event (new_event);
}
var state = event.state & (Gdk.ModifierType.CONTROL_MASK | Gdk.ModifierType.MOD1_MASK);
var c = Gdk.keyval_to_unicode (event.keyval);
/* Solve on enter */
......@@ -206,14 +219,6 @@ public class MathDisplay : Gtk.Viewport
return true;
}
/* Clear on escape */
if ((event.keyval == Gdk.Key.Escape && state == 0) ||
(event.keyval == Gdk.Key.Delete && state == Gdk.ModifierType.SHIFT_MASK))
{
equation.clear ();
return true;
}
/* Numeric keypad will insert '.' or ',' depending on layout */
if ((event.keyval == Gdk.Key.KP_Decimal) ||
(event.keyval == Gdk.Key.KP_Separator) ||
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment