[gnome-calculator] History follows preferences (fixes #105, fixes #168, fixes #159)
- From: Robert Roth <robertroth src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calculator] History follows preferences (fixes #105, fixes #168, fixes #159)
- Date: Thu, 4 Jun 2020 08:20:26 +0000 (UTC)
commit 3854b4937a112afee4b345f768d63370a0e1e3f9
Author: Robert Roth <robert roth off gmail com>
Date: Thu Jun 4 11:20:13 2020 +0300
History follows preferences (fixes #105, fixes #168, fixes #159)
lib/math-equation.vala | 5 +++--
src/math-display.vala | 2 ++
src/math-history.vala | 43 ++++++++++++++++++++++---------------------
3 files changed, 27 insertions(+), 23 deletions(-)
---
diff --git a/lib/math-equation.vala b/lib/math-equation.vala
index 3d983ecc..46c91c08 100644
--- a/lib/math-equation.vala
+++ b/lib/math-equation.vala
@@ -118,6 +118,7 @@ public class MathEquation : Gtk.SourceBuffer
}
public signal void history_signal (string answer, Number number, int number_base, uint
representation_base); /*signal to be emitted when a new calculation is tp be entered in history-view */
+ public signal void display_changed (Serializer serializer);
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 */
@@ -394,6 +395,8 @@ public class MathEquation : Gtk.SourceBuffer
/* Add/remove thousands separators */
reformat_separators ();
+
+ this.display_changed (serializer);
}
private MathEquationState get_current_state ()
@@ -795,8 +798,6 @@ public class MathEquation : Gtk.SourceBuffer
/* Show the number in the user chosen format */
var text = serializer.to_string (x);
- if (representation_base != 0)
- serializer.set_representation_base (number_base);
this.history_signal (get_current_state ().expression, x, number_base, representation_base); /*emits
signal to enter a new entry into history-view */
set_text (text, -1);
state.ans = x;
diff --git a/src/math-display.vala b/src/math-display.vala
index b08d53bf..a56a012c 100644
--- a/src/math-display.vala
+++ b/src/math-display.vala
@@ -38,6 +38,8 @@ public class MathDisplay : Gtk.Viewport
history = new HistoryView ();
history.answer_clicked.connect ((ans) => { insert_text (ans); });
history.equation_clicked.connect ((eq) => { display_text (eq); });
+ history.set_serializer (equation.serializer);
+ _equation.display_changed.connect (history.set_serializer);
main_box.add (history);
main_box.show_all ();
diff --git a/src/math-history.vala b/src/math-history.vala
index f30d53af..5331217d 100644
--- a/src/math-history.vala
+++ b/src/math-history.vala
@@ -11,16 +11,13 @@
[GtkTemplate (ui = "/org/gnome/calculator/history-view.ui")]
public class HistoryView : Gtk.ScrolledWindow
{
- string? last_answer = null;
string? last_equation = null;
- Serializer serializer_four = new Serializer (DisplayFormat.AUTOMATIC, 10, 4);
- Serializer serializer_nine = new Serializer (DisplayFormat.AUTOMATIC, 10, 9);
-
[GtkChild]
Gtk.ListBox listbox;
private int _rows = 0;
+ private Serializer serializer;
private int _current = 0;
public int rows {get {return _rows;} }
public int current {get {return _current;} set {_current = value.clamp(0, _rows); } }
@@ -50,19 +47,10 @@ public class HistoryView : Gtk.ScrolledWindow
public void insert_entry (string equation, Number answer, int number_base, uint representation_base)
{
- serializer_four.set_base (number_base);
- serializer_nine.set_base (number_base);
-
- serializer_four.set_representation_base (representation_base);
- serializer_nine.set_representation_base (representation_base);
-
- var answer_nine_digits = serializer_nine.to_string (answer);
- var answer_four_digits = serializer_four.to_string (answer);
-
- if (last_answer == answer_nine_digits && last_equation == equation)
+ if (last_equation == equation)
return;
- var entry = new HistoryEntry (equation, answer_four_digits, answer_nine_digits);
+ var entry = new HistoryEntry (equation, answer, serializer);
listbox.insert (entry, -1);
entry.show ();
@@ -70,7 +58,6 @@ public class HistoryView : Gtk.ScrolledWindow
entry.answer_clicked.connect ((ans) => { this.answer_clicked (ans); });
entry.equation_clicked.connect ((eq) => { this.equation_clicked (eq); });
- last_answer = answer_nine_digits;
last_equation = equation;
_rows++;
current = rows - 1;
@@ -83,6 +70,12 @@ public class HistoryView : Gtk.ScrolledWindow
_current = 0;
listbox.foreach ((child) => { listbox.remove(child); });
}
+
+ public void set_serializer (Serializer serializer)
+ {
+ this.serializer = serializer;
+ listbox.foreach ((child) => { ((HistoryEntry)child).redisplay (serializer); });
+ }
}
[GtkTemplate (ui = "/org/gnome/calculator/history-entry.ui")]
@@ -93,18 +86,26 @@ public class HistoryEntry : Gtk.ListBoxRow
[GtkChild]
public Gtk.Label answer_label;
+ private Number number;
+
public signal void answer_clicked (string ans);
public signal void equation_clicked (string equation);
public HistoryEntry (string equation,
- string answer_four_digits,
- string answer_nine_digits)
+ Number answer,
+ Serializer serializer)
{
+ this.number = answer;
+ equation_label.set_text (equation);
equation_label.set_tooltip_text (equation);
- answer_label.set_tooltip_text (answer_nine_digits);
+ redisplay (serializer);
+ }
- equation_label.set_text (equation);
- answer_label.set_text (answer_four_digits);
+ public void redisplay (Serializer serializer)
+ {
+ var answer = serializer.to_string (number);
+ answer_label.set_tooltip_text (answer);
+ answer_label.set_text (answer);
}
[GtkCallback]
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]