From 8068b9b9f0fc479a77290e5fe1c477ab48b8267d Mon Sep 17 00:00:00 2001 From: SubhadeepJasu Date: Sat, 11 Jan 2025 22:09:08 +0530 Subject: [PATCH] Add preferences dialog --- ...github.subhadeepjasu.pebbles.gresource.xml | 1 + ...ithub.subhadeepjasu.pebbles.gschema.xml.in | 4 +- .../emblems/currency-conv-symbolic.svg | 13 +-- .../scalable/emblems/volume-conv-symbolic.svg | 5 +- data/meson.build | 1 + data/style.scss | 14 +++ data/ui/main_window.blp | 14 +++ data/ui/preferences_dialog.blp | 97 +++++++++++++++++++ data/ui/scientific_view.blp | 20 ++++ src/Common.vala | 2 +- src/meson.build | 1 + src/shell/MainWindow.vala | 15 ++- src/shell/dialogs/PreferencesDialog.vala | 32 ++++++ src/shell/widgets/ScientificDisplay.vala | 9 ++ 14 files changed, 214 insertions(+), 14 deletions(-) create mode 100644 data/ui/preferences_dialog.blp create mode 100644 src/shell/dialogs/PreferencesDialog.vala diff --git a/data/com.github.subhadeepjasu.pebbles.gresource.xml b/data/com.github.subhadeepjasu.pebbles.gresource.xml index 129d614..bb1eaa6 100644 --- a/data/com.github.subhadeepjasu.pebbles.gresource.xml +++ b/data/com.github.subhadeepjasu.pebbles.gresource.xml @@ -3,6 +3,7 @@ style.css ui/main_window.ui + ui/preferences_dialog.ui ui/button.ui ui/popover_menu_item.ui ui/display.ui diff --git a/data/com.github.subhadeepjasu.pebbles.gschema.xml.in b/data/com.github.subhadeepjasu.pebbles.gschema.xml.in index acb2a9a..c33fe42 100644 --- a/data/com.github.subhadeepjasu.pebbles.gschema.xml.in +++ b/data/com.github.subhadeepjasu.pebbles.gschema.xml.in @@ -20,8 +20,8 @@ - - + + diff --git a/data/icons/scalable/emblems/currency-conv-symbolic.svg b/data/icons/scalable/emblems/currency-conv-symbolic.svg index f845795..f633774 100644 --- a/data/icons/scalable/emblems/currency-conv-symbolic.svg +++ b/data/icons/scalable/emblems/currency-conv-symbolic.svg @@ -1,11 +1,12 @@ - - - - - - + + + + + + + diff --git a/data/icons/scalable/emblems/volume-conv-symbolic.svg b/data/icons/scalable/emblems/volume-conv-symbolic.svg index 7f36de1..66ff4bd 100644 --- a/data/icons/scalable/emblems/volume-conv-symbolic.svg +++ b/data/icons/scalable/emblems/volume-conv-symbolic.svg @@ -1,5 +1,4 @@ - - - + + diff --git a/data/meson.build b/data/meson.build index 0573f9e..ff6a6b6 100644 --- a/data/meson.build +++ b/data/meson.build @@ -18,6 +18,7 @@ stylesheet_deps = custom_target( blueprint_files = [ 'ui/main_window.blp', + 'ui/preferences_dialog.blp', 'ui/button.blp', 'ui/popover_menu_item.blp', 'ui/display.blp', diff --git a/data/style.scss b/data/style.scss index c57d2b5..2ecf25c 100644 --- a/data/style.scss +++ b/data/style.scss @@ -165,3 +165,17 @@ button.pressed { } } } + +.preferences-group { + margin: 8px; + + .heading { + font-weight: bold; + margin-bottom: 8px; + } + + .combo { + background: #0000000a; + border-top: 1px solid #0002; + } +} diff --git a/data/ui/main_window.blp b/data/ui/main_window.blp index 0488fe5..443a581 100644 --- a/data/ui/main_window.blp +++ b/data/ui/main_window.blp @@ -52,6 +52,8 @@ template $PebblesMainWindow: Adw.ApplicationWindow { navigation_headerbar.show-back-button: true; main_headerbar.show-start-title-buttons: true; main_headerbar.show-title: false; + history_button.visible: false; + history_item.visible: true; } } @@ -525,6 +527,12 @@ template $PebblesMainWindow: Adw.ApplicationWindow { orientation: horizontal; } + $PebblesPopoverMenuItem history_item { + text: _("History"); + action_name: "win.history"; + visible: false; + } + $PebblesPopoverMenuItem controls_item { text: _("Controls"); accel: "F1"; @@ -558,6 +566,12 @@ template $PebblesMainWindow: Adw.ApplicationWindow { focusable: false; focus-on-click: false; tooltip-text: _("History"); + action-name: "win.history"; + } + + [end] + Box spinner_box { + Spinner spinner {} } } diff --git a/data/ui/preferences_dialog.blp b/data/ui/preferences_dialog.blp new file mode 100644 index 0000000..313deb4 --- /dev/null +++ b/data/ui/preferences_dialog.blp @@ -0,0 +1,97 @@ +// SPDX-License-Identifier: GPL-3.0-or-later +// SPDX-FileCopyrightText: 2024 Subhadeep Jasu +using Gtk 4.0; +using Adw 1; + +template $PebblesPreferencesDialog: Adw.PreferencesDialog { + Adw.PreferencesPage { + Adw.PreferencesGroup { + title: _("General"); + styles ["preferences-group"] + + Adw.SwitchRow { + title: _("Save State"); + subtitle: _("Load last session on startup"); + focus-on-click: false; + focusable: false; + } + + Adw.ActionRow float_accuracy { + title: _("Precision"); + subtitle: _("Number of decimal places"); + focus-on-click: false; + focusable: false; + + SpinButton { + width-request: 100; + adjustment: Adjustment { + lower: 0; + upper: 9; + step-increment: 1; + }; + focus-on-click: false; + focusable: false; + can-focus: false; + } + } + + Adw.ExpanderRow { + title: _("Scientific Constants Button"); + subtitle: _("The scientific constants to insert when the 'Constants' button is clicked"); + focus-on-click: false; + focusable: false; + can-focus: false; + + Adw.ComboRow constants_select_1 { + title: _("Constants Button Default"); + use-subtitle: true; + model: bind template.constant_button_model; + focus-on-click: false; + focusable: false; + } + + Adw.ComboRow constants_select_2 { + title: _("Constants Button Shifted"); + use-subtitle: true; + model: bind template.constant_button_model; + focus-on-click: false; + focusable: false; + } + } + } + + Adw.PreferencesGroup { + title: _("Calculus"); + styles ["preferences-group"] + + Adw.ActionRow { + title: _("Integration Resolution"); + subtitle: _("Higher resolution means more time to process"); + focus-on-click: false; + focusable: false; + + Scale { + width-request: 200; + adjustment: Adjustment { + lower: 0; + upper: 9; + step-increment: 1; + }; + focus-on-click: false; + focusable: false; + } + } + } + + Adw.PreferencesGroup { + title: _("Converters"); + styles ["preferences-group"] + + Adw.EntryRow { + title: _("Currency Converter API Key"); + focus-on-click: false; + focusable: false; + } + } + } +} diff --git a/data/ui/scientific_view.blp b/data/ui/scientific_view.blp index 8dd8c6c..787b0ec 100644 --- a/data/ui/scientific_view.blp +++ b/data/ui/scientific_view.blp @@ -476,6 +476,7 @@ template $PebblesScientificView: Gtk.Grid { accel_markup: "Return"; visible: bind template.collapsed; focus-on-click: false; + key: "=, Return"; styles [ "suggested-action", @@ -533,6 +534,7 @@ template $PebblesScientificView: Gtk.Grid { tooltip_desc: _("x raised to the power y"); accel_markup: "Q"; focus-on-click: false; + key: "q"; styles [ "special-action", @@ -553,6 +555,7 @@ template $PebblesScientificView: Gtk.Grid { tooltip_desc: _("10 raised to the power x"); accel_markup: "Z"; focus-on-click: false; + key: "z"; styles [ "special-action", @@ -572,6 +575,7 @@ template $PebblesScientificView: Gtk.Grid { tooltip_desc: _("Add it to the value in Memory"); accel_markup: "F3"; focus-on-click: false; + key: "F3"; styles [ "memory-action", @@ -592,6 +596,7 @@ template $PebblesScientificView: Gtk.Grid { tooltip_desc: _("Sine"); accel_markup: "S"; focus-on-click: false; + key: "s"; styles [ "special-action", @@ -612,6 +617,7 @@ template $PebblesScientificView: Gtk.Grid { tooltip_desc: _("Hyberbolic Sine"); accel_markup: "H"; focus-on-click: false; + key: "h"; styles [ "special-action", @@ -632,6 +638,7 @@ template $PebblesScientificView: Gtk.Grid { tooltip_desc: _("Log base 10"); accel_markup: "L"; focus-on-click: false; + key: "l"; styles [ "special-action", @@ -651,6 +658,7 @@ template $PebblesScientificView: Gtk.Grid { tooltip_desc: _("Subtract it from the value in Memory"); accel_markup: "F4"; focus-on-click: false; + key: "F4"; styles [ "memory-action", @@ -671,6 +679,7 @@ template $PebblesScientificView: Gtk.Grid { tooltip_desc: _("Cosine"); accel_markup: "C"; focus-on-click: false; + key: "c"; styles [ "special-action", @@ -691,6 +700,7 @@ template $PebblesScientificView: Gtk.Grid { tooltip_desc: _("Hyberbolic Cosine"); accel_markup: "O"; focus-on-click: false; + key: "o"; styles [ "special-action", @@ -711,6 +721,7 @@ template $PebblesScientificView: Gtk.Grid { tooltip_desc: _("Modulus"); accel_markup: "M"; focus-on-click: false; + key: "m"; styles [ "special-action", @@ -730,6 +741,7 @@ template $PebblesScientificView: Gtk.Grid { tooltip_desc: _("Recall value from Memory"); accel_markup: "F5"; focus-on-click: false; + key: "F5"; styles [ "memory-action", @@ -750,6 +762,7 @@ template $PebblesScientificView: Gtk.Grid { tooltip_desc: _("Tangent"); accel_markup: "T"; focus-on-click: false; + key: "t"; styles [ "special-action", @@ -770,6 +783,7 @@ template $PebblesScientificView: Gtk.Grid { tooltip_desc: _("Hyberbolic Tangent"); accel_markup: "A"; focus-on-click: false; + key: "a"; styles [ "special-action", @@ -790,6 +804,7 @@ template $PebblesScientificView: Gtk.Grid { tooltip_desc: _("Permutations"); accel_markup: "P"; focus-on-click: false; + key: "p"; styles [ "special-action", @@ -809,6 +824,7 @@ template $PebblesScientificView: Gtk.Grid { tooltip_desc: _("Memory Clear"); accel_markup: "F6"; focus-on-click: false; + key: "F6"; styles [ "memory-action", @@ -829,6 +845,7 @@ template $PebblesScientificView: Gtk.Grid { tooltip_desc: _("Factorial"); accel_markup: "F"; focus-on-click: false; + key: "f"; styles [ "special-action", @@ -848,6 +865,7 @@ template $PebblesScientificView: Gtk.Grid { tooltip_desc: bind template.constant_desc; accel_markup: "R"; focus-on-click: false; + key: "r"; styles [ "special-action", @@ -867,6 +885,7 @@ template $PebblesScientificView: Gtk.Grid { tooltip_desc: _("Insert last answer"); accel_markup: "F7"; focus-on-click: false; + key: "F7"; styles [ "special-action", @@ -887,6 +906,7 @@ template $PebblesScientificView: Gtk.Grid { accel_markup: "Return"; visible: bind template.show_hide_fx_btn; focus-on-click: false; + key: "Return"; styles [ "suggested-action", diff --git a/src/Common.vala b/src/Common.vala index ee68b05..e03ce2a 100644 --- a/src/Common.vala +++ b/src/Common.vala @@ -34,8 +34,8 @@ namespace Pebbles { public enum ConstantKeyIndex { EULER, ARCHIMEDES, - IMAGINARY, GOLDEN_RATIO, + IMAGINARY, EULER_MASCH, CONWAY, KHINCHIN, diff --git a/src/meson.build b/src/meson.build index 181e02d..a0a463a 100644 --- a/src/meson.build +++ b/src/meson.build @@ -49,6 +49,7 @@ pebbles_lib = shared_library('pebbles', 'Application.vala', 'Settings.vala', 'shell/MainWindow.vala', + 'shell/dialogs/PreferencesDialog.vala', 'shell/widgets/Button.vala', 'shell/widgets/PopoverMenuItem.vala', 'shell/widgets/Display.vala', diff --git a/src/shell/MainWindow.vala b/src/shell/MainWindow.vala index 030e88c..2043006 100644 --- a/src/shell/MainWindow.vala +++ b/src/shell/MainWindow.vala @@ -4,6 +4,7 @@ namespace Pebbles { [GtkTemplate (ui = "/com/github/subhadeepjasu/pebbles/ui/main_window.ui")] public class MainWindow : Adw.ApplicationWindow { + private PreferencesDialog preferences_dialog; [GtkChild] private unowned Adw.ToastOverlay toast_overlay; [GtkChild] @@ -12,6 +13,8 @@ namespace Pebbles { [GtkChild] private unowned Adw.HeaderBar main_headerbar; [GtkChild] + private unowned Gtk.Spinner spinner; + [GtkChild] private unowned Button angle_mode; [GtkChild] private unowned Gtk.Box menu_box; @@ -97,6 +100,10 @@ namespace Pebbles { add_action (open_controls_action); var open_preferences_action = new SimpleAction ("preferences", null); + open_preferences_action.activate.connect (() => { + preferences_dialog = new PreferencesDialog (); + preferences_dialog.present (this); + }); add_action (open_preferences_action); var enable_scientific_mode_action = new SimpleAction ("open_scientific_mode", null); @@ -123,6 +130,8 @@ namespace Pebbles { size_t length; string json = gen.to_data (out length); print (json + "\n"); + + spinner.spinning = true; on_evaluate (json); }); } @@ -140,7 +149,7 @@ namespace Pebbles { ( Gdk.ModifierType.CONTROL_MASK | Gdk.ModifierType.ALT_MASK - )) != 0 || shift_key) { + )) != 0 || shift_key || preferences_dialog.visible) { return false; } @@ -158,7 +167,7 @@ namespace Pebbles { ( Gdk.ModifierType.CONTROL_MASK | Gdk.ModifierType.ALT_MASK - )) != 0 || shift_key) { + )) != 0 || shift_key || preferences_dialog.visible) { return; } @@ -194,6 +203,7 @@ namespace Pebbles { protected void on_evaluation_completed (string data) { Idle.add (() => { + spinner.spinning = false; var parser = new Json.Parser (); try { parser.load_from_data (data, -1); @@ -217,6 +227,7 @@ namespace Pebbles { } protected void on_memory_change (string context, bool present) { + spinner.spinning = false; switch (context) { case "sci": scientific_view.set_memory_present (present); diff --git a/src/shell/dialogs/PreferencesDialog.vala b/src/shell/dialogs/PreferencesDialog.vala new file mode 100644 index 0000000..50543a3 --- /dev/null +++ b/src/shell/dialogs/PreferencesDialog.vala @@ -0,0 +1,32 @@ +namespace Pebbles { + [GtkTemplate (ui = "/com/github/subhadeepjasu/pebbles/ui/preferences_dialog.ui")] + public class PreferencesDialog : Adw.PreferencesDialog { + protected Gtk.StringList constant_button_model { get; private set; } + protected List constants_list; + + construct { + // TRANSLATORS: The left quotation mark symbol + var laquo = _("“"); + // TRANSLATORS: The right quotation mark symbol + var raquo = _("”"); + + constants_list = new List (); + constants_list.append (_("Euler's constant (exponential)") + " " + laquo + "e" + raquo); + constants_list.append (_("Archimedes' constant (pi)") + " " + laquo + "\xCF\x80" + raquo); + constants_list.append (_("Golden ratio (phi)") + " " + laquo + "\xCF\x86" + raquo); + constants_list.append (_("Imaginary number") + " " + laquo + "j" + raquo); + constants_list.append (_("Euler–Mascheroni constant (gamma)") + " " + laquo + "\xF0\x9D\x9B\xBE" + raquo); + constants_list.append (_("Conway's constant (lambda)") + " " + laquo + "\xCE\xBB" + raquo); + constants_list.append (_("Khinchin's constant") + " " + laquo + "K" + raquo); + constants_list.append (_("The Feigenbaum constant alpha") + " " + laquo + "\xCE\xB1" + raquo); + constants_list.append (_("The Feigenbaum constant delta") + " " + laquo + "\xCE\xB4" + raquo); + constants_list.append (_("Apery's constant") + " " + laquo + "\xF0\x9D\x9B\x87(3)" + raquo); + var constants_array = new string[constants_list.length ()]; + for (uint8 i = 0; i < constants_array.length; i++) { + constants_array[i] = constants_list.nth_data (i); + } + + constant_button_model = new Gtk.StringList (constants_array); + } + } +} diff --git a/src/shell/widgets/ScientificDisplay.vala b/src/shell/widgets/ScientificDisplay.vala index e35a802..ace543e 100644 --- a/src/shell/widgets/ScientificDisplay.vala +++ b/src/shell/widgets/ScientificDisplay.vala @@ -88,6 +88,15 @@ namespace Pebbles { set_angle_unit (settings.global_angle_unit); }); + realize.connect_after (() => { + var window = (MainWindow) get_ancestor (typeof (MainWindow)); + window.on_key_down.connect ((mode) => { + if (mode == "sci" && !main_entry.has_focus) { + main_entry.grab_focus_without_selecting (); + } + }); + }); + set_angle_unit (settings.global_angle_unit); }