[gnome-calculator] Moved preferences dialog UI to template
- From: Robert Roth <robertroth src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calculator] Moved preferences dialog UI to template
- Date: Fri, 5 Jun 2020 20:57:32 +0000 (UTC)
commit b5a8a420728d18615f263cad4162d6dd77375f6f
Author: Robert Roth <robert roth off gmail com>
Date: Fri Jun 5 23:55:44 2020 +0300
Moved preferences dialog UI to template
src/math-preferences.vala | 259 ++++++++--------------------------
src/ui/gnome-calculator.gresource.xml | 1 +
src/ui/math-preferences.ui | 232 ++++++++++++++++++++++++++++++
3 files changed, 291 insertions(+), 201 deletions(-)
---
diff --git a/src/math-preferences.vala b/src/math-preferences.vala
index 9e1cdfeb..8c64a48a 100644
--- a/src/math-preferences.vala
+++ b/src/math-preferences.vala
@@ -7,239 +7,96 @@
* version. See http://www.gnu.org/copyleft/gpl.html the full text of the
* license.
*/
-
+[GtkTemplate (ui = "/org/gnome/calculator/math-preferences.ui")]
public class MathPreferencesDialog : Gtk.Dialog
{
public MathEquation equation { private get; construct; }
- private Gtk.ComboBox angle_unit_combo;
- private Gtk.ComboBox refresh_interval_combo;
- private Gtk.ComboBox word_size_combo;
- private Gtk.SpinButton decimal_places_spin;
- private Gtk.Switch thousands_separator_switch;
- private Gtk.Switch trailing_zeroes_switch;
+ [GtkChild]
+ private Gtk.ComboBoxText combo_angle_units;
+ [GtkChild]
+ private Gtk.ComboBoxText combo_refresh_interval;
+ [GtkChild]
+ private Gtk.ComboBoxText combo_word_size;
+ [GtkChild]
+ private Gtk.SpinButton spinbutton_decimals;
+ [GtkChild]
+ private Gtk.Switch switch_thousands_separators;
+ [GtkChild]
+ private Gtk.Switch switch_trailing_zeroes;
+
private Settings settings;
public MathPreferencesDialog (MathEquation eq)
{
- Object(use_header_bar: 1, equation: eq, resizable: false);
+ Object (equation: eq);
}
construct
{
settings = new Settings ("org.gnome.calculator");
- set_title (/* Title of preferences dialog */
- _("Preferences"));
- border_width = 8;
-
- ((Gtk.HeaderBar) get_header_bar ()).show_close_button = true;
-
- var grid = new Gtk.Grid ();
- grid.show ();
- grid.border_width = 5;
- grid.column_spacing = 6;
- grid.row_spacing = 12;
- get_content_area ().pack_start (grid, true, true, 0);
-
- var renderer = new Gtk.CellRendererText ();
-
- 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);
-
- 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, 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, 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, 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, 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, 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, 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, 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, 4, 1, 1);
-
- 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,
- /* Preferences dialog: Angle unit combo box: Use degrees for trigonometric calculations */
- _("Degrees"), 1, AngleUnit.DEGREES, -1);
- model.append (out iter);
- model.set (iter, 0,
- /* Preferences dialog: Angle unit combo box: Use radians for trigonometric calculations */
- _("Radians"), 1, AngleUnit.RADIANS, -1);
- model.append (out iter);
- model.set (iter, 0,
- /* Preferences dialog: Angle unit combo box: Use gradians for trigonometric calculations
*/
- _("Gradians"), 1, AngleUnit.GRADIANS, -1);
- renderer = new Gtk.CellRendererText ();
- angle_unit_combo.pack_start (renderer, true);
- angle_unit_combo.add_attribute (renderer, "text", 0);
-
- label = new Gtk.Label.with_mnemonic (/* Preferences dialog: Label for word size combo box */
- _("Word _size:"));
- label.show ();
- label.xalign = 0;
- 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, 5, 1, 1);
-
- model = new Gtk.ListStore (2, typeof (string), typeof (int));
- word_size_combo.model = model;
- model.append (out iter);
- model.set (iter, 0, /* Word size combo: 8 bits */ _("8 bits"), 1, 8);
- model.append (out iter);
- model.set (iter, 0, /* Word size combo: 16 bits */ _("16 bits"), 1, 16);
- model.append (out iter);
- model.set (iter, 0, /* Word size combo: 32 bits */ _("32 bits"), 1, 32);
- model.append (out iter);
- model.set (iter, 0, /* Word size combo: 64 bits */ _("64 bits"), 1, 64);
- renderer = new Gtk.CellRendererText ();
- word_size_combo.pack_start (renderer, true);
- word_size_combo.add_attribute (renderer, "text", 0);
-
- label = new Gtk.Label.with_mnemonic (/* Preferences dialog: Label for exchange rate refresh interval
combo box */
- _("E_xchange rate refresh interval"));
- label.show ();
- label.xalign = 0;
- 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, 6, 1, 1);
-
- model = new Gtk.ListStore (2, typeof (string), typeof (int));
- refresh_interval_combo.model = model;
- model.append (out iter);
- model.set (iter, 0, /* Refresh interval combo: never */ _("never"), 1, 0);
- model.append (out iter);
- model.set (iter, 0, /* Refresh interval combo: daily */ _("daily"), 1, 60 * 60 * 24);
- model.append (out iter);
- model.set (iter, 0, /* Refresh interval combo: weekly */ _("weekly"), 1, 60 * 60 * 24 * 7);
- renderer = new Gtk.CellRendererText ();
- refresh_interval_combo.pack_start (renderer, true);
- refresh_interval_combo.add_attribute (renderer, "text", 0);
-
- decimal_places_spin.set_value (equation.accuracy);
- equation.notify["accuracy"].connect ((pspec) => { decimal_places_spin.set_value (equation.accuracy);
});
-
- thousands_separator_switch.set_active (equation.show_thousands_separators);
- equation.notify["show-thousands-separators"].connect (() => { thousands_separator_switch.set_active
(equation.show_thousands_separators); });
-
- 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 (word_size_combo, equation.word_size);
- equation.notify["word-size"].connect ((pspec) => { set_combo_box_from_int (word_size_combo,
equation.word_size); });
-
- set_combo_box_from_int (angle_unit_combo, equation.angle_units);
- equation.notify["angle-units"].connect ((pspec) => { set_combo_box_from_int (angle_unit_combo,
equation.angle_units); });
-
- set_combo_box_from_int (refresh_interval_combo, settings.get_int ("refresh-interval"));
- }
- protected override void response (int id)
- {
- hide ();
- }
+ spinbutton_decimals.value_changed.connect (() => { equation.accuracy =
spinbutton_decimals.get_value_as_int (); });
+ switch_trailing_zeroes.state_set.connect ((state) => { equation.show_trailing_zeroes = state; });
+ switch_thousands_separators.state_set.connect ((state) => { equation.show_thousands_separators =
state; });
+ combo_angle_units.changed.connect (combo_angle_units_changed_cb);
+ combo_word_size.changed.connect (combo_word_size_changed_cb);
+ combo_refresh_interval.changed.connect (combo_refresh_interval_changed_cb);
- protected override bool delete_event (Gdk.EventAny event)
- {
- hide ();
- return true;
+ spinbutton_decimals.set_value (equation.accuracy);
+ equation.notify["accuracy"].connect ((pspec) => { spinbutton_decimals.set_value (equation.accuracy);
});
+
+ switch_thousands_separators.set_active (equation.show_thousands_separators);
+ equation.notify["show-thousands-separators"].connect (() => { switch_thousands_separators.set_active
(equation.show_thousands_separators); });
+
+ switch_trailing_zeroes.set_active (equation.show_trailing_zeroes);
+ equation.notify["show-trailing_zeroes"].connect (() => { switch_trailing_zeroes.set_active
(equation.show_trailing_zeroes); });
+
+ set_combo_box_from_int (combo_word_size, equation.word_size);
+ equation.notify["word-size"].connect ((pspec) => { set_combo_box_from_int (combo_word_size,
equation.word_size); });
+
+ set_combo_box_from_int (combo_angle_units, equation.angle_units);
+ equation.notify["angle-units"].connect ((pspec) => { set_combo_box_from_int (combo_angle_units,
equation.angle_units); });
+
+ set_combo_box_from_int (combo_refresh_interval, settings.get_int ("refresh-interval"));
}
- private void angle_unit_combo_changed_cb (Gtk.ComboBox combo)
+
+ private void combo_angle_units_changed_cb (Gtk.ComboBox combo)
{
- Gtk.TreeIter iter;
- combo.get_active_iter (out iter);
- AngleUnit value;
- combo.model.get (iter, 1, out value, -1);
+ string active_id = combo.get_active_id ();
+ AngleUnit value = (AngleUnit) int.parse (active_id);
equation.angle_units = value;
}
- private void word_size_combo_changed_cb (Gtk.ComboBox combo)
+ private void combo_word_size_changed_cb (Gtk.ComboBox combo)
{
- Gtk.TreeIter iter;
- combo.get_active_iter (out iter);
- int value;
- combo.model.get (iter, 1, out value, -1);
+ string active_id = combo.get_active_id ();
+ int value = int.parse (active_id);
equation.word_size = value;
}
- private void refresh_interval_combo_changed_cb (Gtk.ComboBox combo)
+ private void combo_refresh_interval_changed_cb (Gtk.ComboBox combo)
{
- Gtk.TreeIter iter;
- combo.get_active_iter (out iter);
- int value;
- combo.model.get (iter, 1, out value, -1);
+ string active_id = combo.get_active_id ();
+ int value = int.parse (active_id);
settings.set_int ("refresh-interval", value);
CurrencyManager.get_default ().refresh_interval = value;
+ }
+ protected override void response (int id)
+ {
+ hide ();
+ }
+
+ protected override bool delete_event (Gdk.EventAny event)
+ {
+ hide ();
+ return true;
}
private void set_combo_box_from_int (Gtk.ComboBox combo, int value)
{
- Gtk.TreeIter iter;
- var valid = combo.model.get_iter_first (out iter);
- while (valid)
- {
- int v;
-
- combo.model.get (iter, 1, out v, -1);
- if (v == value)
- break;
- valid = combo.model.iter_next (ref iter);
- }
- if (!valid)
- valid = combo.model.get_iter_first (out iter);
-
- combo.set_active_iter (iter);
+ combo.active_id = value.to_string ();
}
}
diff --git a/src/ui/gnome-calculator.gresource.xml b/src/ui/gnome-calculator.gresource.xml
index 4196d220..434d1920 100644
--- a/src/ui/gnome-calculator.gresource.xml
+++ b/src/ui/gnome-calculator.gresource.xml
@@ -12,6 +12,7 @@
<file preprocess="xml-stripblanks">math-variable-popover.ui</file>
<file preprocess="xml-stripblanks">math-window.ui</file>
<file preprocess="xml-stripblanks">math-shortcuts.ui</file>
+ <file preprocess="xml-stripblanks">math-preferences.ui</file>
<file>calculator.css</file>
</gresource>
</gresources>
diff --git a/src/ui/math-preferences.ui b/src/ui/math-preferences.ui
new file mode 100644
index 00000000..51d0be37
--- /dev/null
+++ b/src/ui/math-preferences.ui
@@ -0,0 +1,232 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.22.2 -->
+<interface>
+ <requires lib="gtk+" version="3.22"/>
+ <object class="GtkAdjustment" id="adjustment_decimals">
+ <property name="upper">100</property>
+ <property name="step_increment">1</property>
+ <property name="page_increment">10</property>
+ </object>
+ <template class="MathPreferencesDialog" parent="GtkDialog">
+ <property name="can_focus">False</property>
+ <property name="border_width">8</property>
+ <property name="resizable">False</property>
+ <property name="destroy_with_parent">True</property>
+ <property name="type_hint">dialog</property>
+ <property name="gravity">center</property>
+ <child type="titlebar">
+ <object class="GtkHeaderBar" id="headerbar">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="title" translatable="yes">Preferences</property>
+ <property name="show_close_button">True</property>
+ <property name="decoration_layout">:close</property>
+ <child>
+ <placeholder/>
+ </child>
+ </object>
+ </child>
+ <child internal-child="vbox">
+ <object class="GtkBox" id="preferences_container">
+ <property name="can_focus">False</property>
+ <property name="orientation">vertical</property>
+ <property name="spacing">2</property>
+ <child internal-child="action_area">
+ <object class="GtkButtonBox">
+ <property name="can_focus">False</property>
+ <property name="layout_style">end</property>
+ <child>
+ <placeholder/>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkGrid" id="preferences_grid">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="border_width">5</property>
+ <property name="row_spacing">12</property>
+ <property name="column_spacing">6</property>
+ <child>
+ <object class="GtkLabel" id="label_decimals_number">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="halign">start</property>
+ <property name="label" translatable="yes">Number of _decimals</property>
+ <property name="use_underline">True</property>
+ <property name="mnemonic_widget">spinbutton_decimals</property>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label_trailing_zeroes">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="halign">start</property>
+ <property name="label" translatable="yes">Trailing _zeroes</property>
+ <property name="use_underline">True</property>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label_thousands_separator">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="halign">start</property>
+ <property name="label" translatable="yes">_Thousands separators</property>
+ <property name="use_underline">True</property>
+ <property name="mnemonic_widget">switch_thousands_separators</property>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">2</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label_angle_units">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="halign">start</property>
+ <property name="label" translatable="yes">_Angle units</property>
+ <property name="use_underline">True</property>
+ <property name="mnemonic_widget">combo_angle_units</property>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">3</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label_word_size">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="halign">start</property>
+ <property name="label" translatable="yes">Word _size</property>
+ <property name="use_underline">True</property>
+ <property name="mnemonic_widget">combo_word_size</property>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">4</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label_exchange_refresh">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="halign">start</property>
+ <property name="label" translatable="yes">E_xchange rate refresh interval</property>
+ <property name="use_underline">True</property>
+ <property name="mnemonic_widget">combo_refresh_interval</property>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">5</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkSpinButton" id="spinbutton_decimals">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="adjustment">adjustment_decimals</property>
+ <property name="numeric">True</property>
+ <property name="value">9</property>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="top_attach">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkSwitch" id="switch_trailing_zeroes">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="halign">end</property>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="top_attach">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkSwitch" id="switch_thousands_separators">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="halign">end</property>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="top_attach">2</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkComboBoxText" id="combo_angle_units">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <items>
+ <item id="0" translatable="yes">Degrees</item>
+ <item id="1" translatable="yes">Radians</item>
+ <item id="2" translatable="yes">Gradians</item>
+ </items>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="top_attach">3</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkComboBoxText" id="combo_word_size">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <items>
+ <item id="8" translatable="yes" comments="Word size combo: 8 bits">8 bits</item>
+ <item id="16" translatable="yes" comments="Word size combo: 16 bits">16 bits</item>
+ <item id="32" translatable="yes" comments="Word size combo: 32 bits">32 bits</item>
+ <item id="64" translatable="yes" comments="Word size combo: 64 bits">64 bits</item>
+ </items>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="top_attach">4</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkComboBoxText" id="combo_refresh_interval">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <items>
+ <item id="0" translatable="yes" comments="Refresh interval combo: never">never</item>
+ <item id="86400" translatable="yes" comments="Refresh interval combo: daily">daily</item>
+ <item id="604800" translatable="yes" comments="Refresh interval combo:
weekly">weekly</item>
+ </items>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="top_attach">5</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ </template>
+</interface>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]