Add a 'Sort Installed First' menu item

This defaults to 'on', and then we get the normal
installed-games-at-the-top behavior.

If you uncheck it, the installed games sort amongst all the others.

The other benefit here is that this gives users a visual clue about
what the sorting will be, and where their recently installed game is.
This commit is contained in:
Daniel Johnson 2023-04-07 19:00:14 -04:00 committed by Mathieu Comandon
parent fcbfc7af59
commit e960b18447
2 changed files with 56 additions and 15 deletions

View file

@ -168,6 +168,12 @@ class LutrisWindow(Gtk.ApplicationWindow,
default=self.view_sorting,
enabled=lambda: self.is_view_sort_active
),
"view-sorting-installed-first": Action(
self.on_view_sorting_installed_first_change,
type="b",
default=self.view_sorting_installed_first,
enabled=lambda: self.is_view_sort_active
),
"view-sorting-ascending": Action(
self.on_view_sorting_direction_change,
type="b",
@ -290,6 +296,10 @@ class LutrisWindow(Gtk.ApplicationWindow,
def view_sorting_ascending(self):
return settings.read_setting("view_sorting_ascending").lower() != "false"
@property
def view_sorting_installed_first(self):
return settings.read_setting("view_sorting_installed_first").lower() != "false"
@property
def show_hidden_games(self):
return settings.read_setting("show_hidden_games").lower() == "true"
@ -300,12 +310,20 @@ class LutrisWindow(Gtk.ApplicationWindow,
exactly a match for what self.apply_view_sort does, but it is as close
as may be, in the hope that a faster DB sort will get is close and result
in a faster sort overall."""
return [("installed", "COLLATE NOCASE DESC"), (
params = []
if self.view_sorting_installed_first:
params.append(("installed", "COLLATE NOCASE DESC"))
params.append((
self.view_sorting,
"COLLATE NOCASE ASC"
if self.view_sorting_ascending
else "COLLATE NOCASE DESC"
)]
))
return params
@property
def is_view_sort_active(self):
@ -353,15 +371,19 @@ class LutrisWindow(Gtk.ApplicationWindow,
if view_sorting == "name":
value = natural_sort_key(value)
# We want installed games to always be first, even in
# a descending sort.
if self.view_sorting_ascending:
installation_flag = not installation_flag
# Users may have obsolete view_sorting settings, so
# we must tolerate them. We treat them all as blank.
value = value or sort_defaults.get(view_sorting, "")
return [installation_flag, value]
if self.view_sorting_installed_first:
# We want installed games to always be first, even in
# a descending sort.
if self.view_sorting_ascending:
installation_flag = not installation_flag
return [installation_flag, value]
return value
return sorted(items, key=get_sort_value, reverse=not self.view_sorting_ascending)
@ -854,6 +876,11 @@ class LutrisWindow(Gtk.ApplicationWindow,
settings.write_setting("view_sorting_ascending", bool(value))
self.emit("view-updated")
def on_view_sorting_installed_first_change(self, action, value):
self.actions["view-sorting-installed-first"].set_state(value)
settings.write_setting("view_sorting_installed_first", bool(value))
self.emit("view-updated")
def on_side_panel_state_change(self, action, value):
"""Callback to handle side panel toggle"""
action.set_state(value)

View file

@ -326,9 +326,12 @@
</packing>
</child>
<child>
<object class="GtkSeparator">
<object class="GtkModelButton">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="can-focus">True</property>
<property name="receives-default">False</property>
<property name="action-name">win.view-sorting-installed-first</property>
<property name="text" translatable="yes">Sort Installed First</property>
</object>
<packing>
<property name="expand">False</property>
@ -350,6 +353,17 @@
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkSeparator">
<property name="visible">True</property>
<property name="can-focus">False</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">3</property>
</packing>
</child>
<child>
<object class="GtkModelButton">
<property name="visible">True</property>
@ -362,7 +376,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">3</property>
<property name="position">4</property>
</packing>
</child>
<child>
@ -377,7 +391,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">4</property>
<property name="position">5</property>
</packing>
</child>
<child>
@ -392,7 +406,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">5</property>
<property name="position">6</property>
</packing>
</child>
<child>
@ -407,7 +421,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">6</property>
<property name="position">7</property>
</packing>
</child>
<child>
@ -422,7 +436,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">7</property>
<property name="position">8</property>
</packing>
</child>
</object>