From ff566ecef7557a847352b30eb5d67bafaa3f2b6c Mon Sep 17 00:00:00 2001 From: Diego Garcia Gangl Date: Sat, 14 Sep 2024 19:08:26 -0300 Subject: [PATCH] Use stateful actions for sorting order --- GTG/gtk/browser/main_window.py | 37 +++++++++++++++++++--------------- GTG/gtk/data/main_window.ui | 6 ++++-- 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/GTG/gtk/browser/main_window.py b/GTG/gtk/browser/main_window.py index 13500793d..74244452c 100644 --- a/GTG/gtk/browser/main_window.py +++ b/GTG/gtk/browser/main_window.py @@ -243,8 +243,6 @@ def _set_actions(self): ('recurring_month', self.on_set_recurring_every_month, None), ('recurring_year', self.on_set_recurring_every_year, None), ('recurring_toggle', self.on_toggle_recurring, None), - ('sort_asc', self.on_sort_order_asc, None), - ('sort_desc', self.on_sort_order_desc, None), ] for action, callback, accel in action_entries: @@ -268,6 +266,14 @@ def _set_actions(self): sort_action.connect('change-state', self.on_sort) self.add_action(sort_action) + order_variant = GLib.Variant.new_string('ASC') + order_action = Gio.SimpleAction.new_stateful('sort_order', + order_variant.get_type(), + order_variant) + + order_action.connect('change-state', self.on_sort_order) + self.add_action(order_action) + def _init_icon_theme(self): """ @@ -1305,6 +1311,19 @@ def on_sort(self, action, value) -> None: self.store_sorting(value_str.lower()) + def on_sort_order(self, action, value) -> None: + + action.set_state(value) + value_str = value.get_string() + + if value_str == 'ASC': + self.get_pane().set_sort_order(reverse=False) + self.change_sort_icon('ASC') + else: + self.get_pane().set_sort_order(reverse=True) + self.change_sort_icon('DESC') + + def store_sorting(self, mode: str) -> None: """Store sorting mode.""" @@ -1317,20 +1336,6 @@ def store_sorting(self, mode: str) -> None: self.config.set('sort_mode_open', mode) - def on_sort_order_asc(self, action, params) -> None: - """Set ascending order for current sorter.""" - - self.get_pane().set_sort_order(reverse=False) - self.change_sort_icon('ASC') - - - def on_sort_order_desc(self, action, params) -> None: - """Set descending order for current sorter.""" - - self.get_pane().set_sort_order(reverse=True) - self.change_sort_icon('DESC') - - def set_sorter(self, value: str) -> None: """Set sorter for current task pane.""" diff --git a/GTG/gtk/data/main_window.ui b/GTG/gtk/data/main_window.ui index 780efdf6e..2831460ce 100644 --- a/GTG/gtk/data/main_window.ui +++ b/GTG/gtk/data/main_window.ui @@ -238,11 +238,13 @@
Ascending Order - win.sort_asc + ASC + win.sort_order Descending Order - win.sort_desc + DESC + win.sort_order