window: Store filter info in GSettings
This commit is contained in:
@@ -40,9 +40,6 @@ class Window(Adw.ApplicationWindow):
|
|||||||
search_text = GObject.Property(type=str)
|
search_text = GObject.Property(type=str)
|
||||||
show_hidden = GObject.Property(type=bool, default=False)
|
show_hidden = GObject.Property(type=bool, default=False)
|
||||||
|
|
||||||
_sort_prop = "last-played"
|
|
||||||
_invert_sort = True
|
|
||||||
|
|
||||||
@GObject.Property(type=Gio.ListStore)
|
@GObject.Property(type=Gio.ListStore)
|
||||||
def games(self) -> Gio.ListStore:
|
def games(self) -> Gio.ListStore:
|
||||||
"""Model of the user's games."""
|
"""Model of the user's games."""
|
||||||
@@ -58,6 +55,7 @@ class Window(Adw.ApplicationWindow):
|
|||||||
"width": "default-width",
|
"width": "default-width",
|
||||||
"height": "default-height",
|
"height": "default-height",
|
||||||
"is-maximized": "maximized",
|
"is-maximized": "maximized",
|
||||||
|
"show-hidden": "show-hidden",
|
||||||
}.items():
|
}.items():
|
||||||
state_settings.bind(key, self, name, Gio.SettingsBindFlags.DEFAULT)
|
state_settings.bind(key, self, name, Gio.SettingsBindFlags.DEFAULT)
|
||||||
|
|
||||||
@@ -68,7 +66,12 @@ class Window(Adw.ApplicationWindow):
|
|||||||
self.add_action(Gio.PropertyAction.new("show-hidden", self, "show-hidden"))
|
self.add_action(Gio.PropertyAction.new("show-hidden", self, "show-hidden"))
|
||||||
self.add_action_entries((
|
self.add_action_entries((
|
||||||
("search", lambda *_: self.search_entry.grab_focus()),
|
("search", lambda *_: self.search_entry.grab_focus()),
|
||||||
("sort", self._sort, "s", "'last_played'"),
|
(
|
||||||
|
"sort",
|
||||||
|
self._sort,
|
||||||
|
"s",
|
||||||
|
state_settings.get_value("sort-mode").print_(False),
|
||||||
|
),
|
||||||
))
|
))
|
||||||
|
|
||||||
@Gtk.Template.Callback()
|
@Gtk.Template.Callback()
|
||||||
@@ -136,16 +139,21 @@ class Window(Adw.ApplicationWindow):
|
|||||||
|
|
||||||
def _sort(self, action: Gio.SimpleAction, parameter: GLib.Variant, *_args):
|
def _sort(self, action: Gio.SimpleAction, parameter: GLib.Variant, *_args):
|
||||||
action.change_state(parameter)
|
action.change_state(parameter)
|
||||||
prop, invert = SORT_MODES[parameter.get_string()]
|
sort_mode = parameter.get_string()
|
||||||
opposite = (self._sort_prop == prop) and (self._invert_sort != invert)
|
|
||||||
self._sort_prop, self._invert_sort = prop, invert
|
prop, invert = SORT_MODES[sort_mode]
|
||||||
|
prev_prop, prev_invert = SORT_MODES[state_settings.get_string("sort-mode")]
|
||||||
|
opposite = (prev_prop == prop) and (prev_invert != invert)
|
||||||
|
|
||||||
|
state_settings.set_string("sort-mode", sort_mode)
|
||||||
self.sorter.changed(
|
self.sorter.changed(
|
||||||
Gtk.SorterChange.INVERTED if opposite else Gtk.SorterChange.DIFFERENT
|
Gtk.SorterChange.INVERTED if opposite else Gtk.SorterChange.DIFFERENT
|
||||||
)
|
)
|
||||||
|
|
||||||
def _sort_func(self, game1: Game, game2: Game, _) -> int:
|
def _sort_func(self, game1: Game, game2: Game, _) -> int:
|
||||||
a = (game2 if self._invert_sort else game1).get_property(self._sort_prop)
|
prop, invert = SORT_MODES[state_settings.get_string("sort-mode")]
|
||||||
b = (game1 if self._invert_sort else game2).get_property(self._sort_prop)
|
a = (game2 if invert else game1).get_property(prop)
|
||||||
|
b = (game1 if invert else game2).get_property(prop)
|
||||||
return (
|
return (
|
||||||
locale.strcoll(*self._sortable(a, b))
|
locale.strcoll(*self._sortable(a, b))
|
||||||
if isinstance(a, str)
|
if isinstance(a, str)
|
||||||
|
|||||||
@@ -12,5 +12,18 @@
|
|||||||
<key name="is-maximized" type="b">
|
<key name="is-maximized" type="b">
|
||||||
<default>false</default>
|
<default>false</default>
|
||||||
</key>
|
</key>
|
||||||
|
<key name="sort-mode" type="s">
|
||||||
|
<choices>
|
||||||
|
<choice value="last_played" />
|
||||||
|
<choice value="a-z" />
|
||||||
|
<choice value="z-a" />
|
||||||
|
<choice value="newest" />
|
||||||
|
<choice value="oldest" />
|
||||||
|
</choices>
|
||||||
|
<default>"last_played"</default>
|
||||||
|
</key>
|
||||||
|
<key name="show-hidden" type="b">
|
||||||
|
<default>false</default>
|
||||||
|
</key>
|
||||||
</schema>
|
</schema>
|
||||||
</schemalist>
|
</schemalist>
|
||||||
|
|||||||
Reference in New Issue
Block a user