[gnome-calculator] Moved number format selection to app menu (fixes #24)
- From: Robert Roth <robertroth src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calculator] Moved number format selection to app menu (fixes #24)
- Date: Fri, 5 Jun 2020 13:16:55 +0000 (UTC)
commit 5de98eeb7c36c33f2206aee5bfe4dccfd176f3de
Author: Robert Roth <robert roth off gmail com>
Date: Fri Jun 5 16:16:36 2020 +0300
Moved number format selection to app menu (fixes #24)
src/math-preferences.vala | 83 +++++++++--------------------------------------
src/math-window.vala | 4 ++-
src/ui/math-window.ui | 33 +++++++++++++++++++
3 files changed, 51 insertions(+), 69 deletions(-)
---
diff --git a/src/math-preferences.vala b/src/math-preferences.vala
index b67ebb75..9e1cdfeb 100644
--- a/src/math-preferences.vala
+++ b/src/math-preferences.vala
@@ -14,7 +14,6 @@ public class MathPreferencesDialog : Gtk.Dialog
private Gtk.ComboBox angle_unit_combo;
private Gtk.ComboBox refresh_interval_combo;
- private Gtk.ComboBox number_format_combo;
private Gtk.ComboBox word_size_combo;
private Gtk.SpinButton decimal_places_spin;
private Gtk.Switch thousands_separator_switch;
@@ -42,104 +41,64 @@ public class MathPreferencesDialog : Gtk.Dialog
grid.row_spacing = 12;
get_content_area ().pack_start (grid, true, true, 0);
- var label = new Gtk.Label.with_mnemonic (/* Preferences dialog: Label for number format combo box */
- _("Number _Format:"));
- label.show ();
- label.xalign = 0;
- grid.attach (label, 0, 0, 1, 1);
-
- number_format_combo = new Gtk.ComboBox ();
- label.mnemonic_widget = number_format_combo;
- number_format_combo.show ();
- number_format_combo.changed.connect (number_format_combo_changed_cb);
- grid.attach (number_format_combo, 1, 0, 1, 1);
-
- var model = new Gtk.ListStore (2, typeof (string), typeof (int));
- number_format_combo.model = model;
- Gtk.TreeIter iter;
- model.append (out iter);
- model.set (iter, 0,
- /* Number display mode combo: Automatic, e.g. 1234 (or scientific for large number
1.234×10^99) */
- _("Automatic"), 1, DisplayFormat.AUTOMATIC, -1);
- model.append (out iter);
- model.set (iter, 0,
- /* Number display mode combo: Fixed, e.g. 1234 */
- _("Fixed"), 1, DisplayFormat.FIXED, -1);
- model.append (out iter);
- model.set (iter, 0,
- /* Number display mode combo: Scientific, e.g. 1.234×10^3 */
- _("Scientific"), 1, DisplayFormat.SCIENTIFIC, -1);
- model.append (out iter);
- model.set (iter, 0,
- /* Number display mode combo: Engineering, e.g. 1.234k */
- _("Engineering"), 1, DisplayFormat.ENGINEERING, -1);
var renderer = new Gtk.CellRendererText ();
- number_format_combo.pack_start (renderer, true);
- number_format_combo.add_attribute (renderer, "text", 0);
-
- var format_options_box = new Gtk.Box (Gtk.Orientation.VERTICAL, 6);
- format_options_box.margin_bottom = 6;
- format_options_box.margin_start = 12;
- format_options_box.halign = Gtk.Align.CENTER;
- format_options_box.valign = Gtk.Align.CENTER;
- format_options_box.show ();
- grid.attach (format_options_box, 0, 1, 2, 1);
var decimal_places_adjustment = new Gtk.Adjustment (0.0, 0.0, 100.0, 1.0, 1.0, 0.0);
decimal_places_spin = new Gtk.SpinButton (decimal_places_adjustment, 0.0, 0);
- label = new Gtk.Label.with_mnemonic (/* Preferences dialog: label for show trailing zeroes check
button */
+ var label = new Gtk.Label.with_mnemonic (/* Preferences dialog: label for show trailing zeroes check
button */
_("Number of _decimals"));
label.mnemonic_widget = decimal_places_spin;
label.show ();
label.xalign = 0;
- grid.attach (label, 0, 2, 1, 1);
+ grid.attach (label, 0, 1, 1, 1);
decimal_places_spin.show ();
decimal_places_spin.value_changed.connect (() => { equation.accuracy =
decimal_places_spin.get_value_as_int (); });
- grid.attach (decimal_places_spin, 1, 2, 1, 1);
+ grid.attach (decimal_places_spin, 1, 1, 1, 1);
label = new Gtk.Label.with_mnemonic (/* Preferences dialog: label for show trailing zeroes switch */
_("Trailing _zeroes"));
label.xalign = 0;
label.show ();
- grid.attach (label, 0, 3, 1, 1);
+ grid.attach (label, 0, 2, 1, 1);
label.mnemonic_widget = trailing_zeroes_switch;
trailing_zeroes_switch = new Gtk.Switch ();
trailing_zeroes_switch.show ();
trailing_zeroes_switch.state_set.connect ((state) => { equation.show_trailing_zeroes = state; });
trailing_zeroes_switch.halign = Gtk.Align.END;
- grid.attach (trailing_zeroes_switch, 1, 3, 1, 1);
+ grid.attach (trailing_zeroes_switch, 1, 2, 1, 1);
label = new Gtk.Label.with_mnemonic (/* Preferences dialog: label for show show thousands separator
switch */
_("_Thousands separators"));
label.xalign = 0;
label.show ();
label.mnemonic_widget = thousands_separator_switch;
- grid.attach (label, 0, 4, 1, 1);
+ grid.attach (label, 0, 3, 1, 1);
thousands_separator_switch = new Gtk.Switch ();
thousands_separator_switch.show ();
thousands_separator_switch.state_set.connect ((state) => { equation.show_thousands_separators =
state; });
thousands_separator_switch.halign = Gtk.Align.END;
- grid.attach (thousands_separator_switch, 1, 4, 1, 1);
+ grid.attach (thousands_separator_switch, 1, 3, 1, 1);
label = new Gtk.Label.with_mnemonic (/* Preferences dialog: Label for angle unit combo box */
_("_Angle units:"));
label.show ();
label.xalign = 0;
- grid.attach (label, 0, 5, 1, 1);
+ grid.attach (label, 0, 4, 1, 1);
angle_unit_combo = new Gtk.ComboBox ();
label.mnemonic_widget = angle_unit_combo;
angle_unit_combo.show ();
angle_unit_combo.changed.connect (angle_unit_combo_changed_cb);
- grid.attach (angle_unit_combo, 1, 5, 1, 1);
+ grid.attach (angle_unit_combo, 1, 4, 1, 1);
- model = new Gtk.ListStore (2, typeof (string), typeof (int));
+ Gtk.TreeIter iter;
+ var model = new Gtk.ListStore (2, typeof (string), typeof (int));
angle_unit_combo.model = model;
model.append (out iter);
model.set (iter, 0,
@@ -161,13 +120,13 @@ public class MathPreferencesDialog : Gtk.Dialog
_("Word _size:"));
label.show ();
label.xalign = 0;
- grid.attach (label, 0, 6, 1, 1);
+ grid.attach (label, 0, 5, 1, 1);
word_size_combo = new Gtk.ComboBox ();
label.mnemonic_widget = word_size_combo;
word_size_combo.show ();
word_size_combo.changed.connect (word_size_combo_changed_cb);
- grid.attach (word_size_combo, 1, 6, 1, 1);
+ grid.attach (word_size_combo, 1, 5, 1, 1);
model = new Gtk.ListStore (2, typeof (string), typeof (int));
word_size_combo.model = model;
@@ -187,13 +146,13 @@ public class MathPreferencesDialog : Gtk.Dialog
_("E_xchange rate refresh interval"));
label.show ();
label.xalign = 0;
- grid.attach (label, 0, 7, 1, 1);
+ grid.attach (label, 0, 6, 1, 1);
refresh_interval_combo = new Gtk.ComboBox ();
label.mnemonic_widget = refresh_interval_combo;
refresh_interval_combo.show ();
refresh_interval_combo.changed.connect (refresh_interval_combo_changed_cb);
- grid.attach (refresh_interval_combo, 1, 7, 1, 1);
+ grid.attach (refresh_interval_combo, 1, 6, 1, 1);
model = new Gtk.ListStore (2, typeof (string), typeof (int));
refresh_interval_combo.model = model;
@@ -216,9 +175,6 @@ public class MathPreferencesDialog : Gtk.Dialog
trailing_zeroes_switch.set_active (equation.show_trailing_zeroes);
equation.notify["show-trailing_zeroes"].connect (() => { trailing_zeroes_switch.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); });
@@ -239,15 +195,6 @@ public class MathPreferencesDialog : Gtk.Dialog
return true;
}
- private void number_format_combo_changed_cb (Gtk.ComboBox combo)
- {
- Gtk.TreeIter iter;
- combo.get_active_iter (out iter);
- DisplayFormat value;
- combo.model.get (iter, 1, out value, -1);
- equation.number_format = value;
- }
-
private void angle_unit_combo_changed_cb (Gtk.ComboBox combo)
{
Gtk.TreeIter iter;
diff --git a/src/math-window.vala b/src/math-window.vala
index dc244ccf..c1d00dbb 100644
--- a/src/math-window.vala
+++ b/src/math-window.vala
@@ -49,7 +49,9 @@ public class MathWindow : Gtk.ApplicationWindow
right_aligned = true;
add_action_entries (window_entries, this);
-
+ var settings = new Settings ("org.gnome.calculator");
+ add_action (settings.create_action ("number-format"));
+ settings.bind ("number-format", _equation, "number_format", SettingsBindFlags.DEFAULT);
converter.set_equation (_equation);
converter.set_category (null);
converter.set_conversion (equation.source_units, equation.target_units);
diff --git a/src/ui/math-window.ui b/src/ui/math-window.ui
index e855c403..d2e233df 100644
--- a/src/ui/math-window.ui
+++ b/src/ui/math-window.ui
@@ -50,6 +50,39 @@
<attribute name="action">app.new-window</attribute>
</item>
</section>
+
+ <section>
+ <item>
+ <attribute name="label" translatable="yes">Number format</attribute>
+ <attribute name="action">false</attribute>
+ </item>
+ <item>
+ <!-- Translators: entry of the Setup submenu of the hamburger menu (with a mnemonic that appears
when pressing Alt); set number format to "automatic"; other possible options are "_Fixed", "_Scientific" and
"_Engineering" -->
+ <attribute name="label" translatable="yes">_Automatic</attribute>
+ <attribute name="action">win.number-format</attribute>
+ <attribute name="target">automatic</attribute>
+ </item>
+ <item>
+ <!-- Translators: entry of the Setup submenu of the hamburger menu (with a mnemonic that appears
when pressing Alt); set number format to "fixed"; other possible options are "_Automatic", "_Scientific" and
"_Engineering" -->
+ <attribute name="label" translatable="yes">_Fixed</attribute>
+ <attribute name="action">win.number-format</attribute>
+ <attribute name="target">fixed</attribute>
+ </item>
+ <item>
+ <!-- Translators: entry of the Setup submenu of the hamburger menu (with a mnemonic that appears
when pressing Alt); set number format to "scientific"; other possible options are "_Fixed", "_Automatic" and
"_Engineering" -->
+ <attribute name="label" translatable="yes">_Scientific</attribute>
+ <attribute name="action">win.number-format</attribute>
+ <attribute name="target">scientific</attribute>
+ </item>
+ <item>
+ <!-- Translators: entry of the Setup submenu of the hamburger menu (with a mnemonic that appears
when pressing Alt); set number format to "engineering"; other possible options are "_Fixed", "_Scientific"
and "_Automatic" -->
+ <attribute name="label" translatable="yes">_Engineering</attribute>
+ <attribute name="action">win.number-format</attribute>
+ <attribute name="target">engineering</attribute>
+ </item>
+
+ </section>
+
<section>
<attribute name="id">help-section</attribute>
<item>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]