Order sources by number of games
This commit is contained in:
@@ -81,17 +81,18 @@ class CartridgesWindow(Adw.ApplicationWindow):
|
|||||||
|
|
||||||
def create_source_rows(self):
|
def create_source_rows(self):
|
||||||
def get_removed(source_id):
|
def get_removed(source_id):
|
||||||
if all(
|
removed = tuple(
|
||||||
game.removed or game.hidden or game.blacklisted
|
game.removed or game.hidden or game.blacklisted
|
||||||
for game in shared.store.source_games[source_id].values()
|
for game in shared.store.source_games[source_id].values()
|
||||||
):
|
)
|
||||||
return True
|
return (
|
||||||
return False
|
(count,) if (count := sum(removed)) != len(removed) else False
|
||||||
|
) # Return a tuple because 0 == False and 1 == True
|
||||||
|
|
||||||
restored = False
|
restored = False
|
||||||
|
|
||||||
selected_id = (
|
selected_id = (
|
||||||
self.source_rows[selected_row]
|
self.source_rows[selected_row][0]
|
||||||
if (selected_row := self.sidebar.get_selected_row()) in self.source_rows
|
if (selected_row := self.sidebar.get_selected_row()) in self.source_rows
|
||||||
else None
|
else None
|
||||||
)
|
)
|
||||||
@@ -101,7 +102,7 @@ class CartridgesWindow(Adw.ApplicationWindow):
|
|||||||
restored = True
|
restored = True
|
||||||
|
|
||||||
if added_missing := (
|
if added_missing := (
|
||||||
not shared.store.source_games.get("imported") or get_removed("imported")
|
not shared.store.source_games.get("imported") or not get_removed("imported")
|
||||||
):
|
):
|
||||||
self.sidebar.select_row(self.all_games_row_box.get_parent())
|
self.sidebar.select_row(self.all_games_row_box.get_parent())
|
||||||
self.added_row_box.get_parent().set_visible(not added_missing)
|
self.added_row_box.get_parent().set_visible(not added_missing)
|
||||||
@@ -114,20 +115,48 @@ class CartridgesWindow(Adw.ApplicationWindow):
|
|||||||
for source_id in shared.store.source_games:
|
for source_id in shared.store.source_games:
|
||||||
if source_id == "imported":
|
if source_id == "imported":
|
||||||
continue
|
continue
|
||||||
if get_removed(source_id):
|
if not (removed := get_removed(source_id)):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
row = Gtk.Label(
|
row = Gtk.Box()
|
||||||
label=self.get_application().get_source_name(source_id),
|
games_no = len(shared.store.source_games[source_id]) - removed[0]
|
||||||
halign=Gtk.Align.START,
|
|
||||||
margin_top=12,
|
row.append(
|
||||||
margin_bottom=12,
|
Gtk.Label(
|
||||||
margin_start=6,
|
label=self.get_application().get_source_name(source_id),
|
||||||
margin_end=6,
|
halign=Gtk.Align.START,
|
||||||
|
margin_top=12,
|
||||||
|
margin_bottom=12,
|
||||||
|
margin_start=6,
|
||||||
|
margin_end=6,
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
self.sidebar.append(row)
|
row.append(
|
||||||
self.source_rows[row.get_parent()] = source_id
|
Gtk.Label(
|
||||||
|
label=games_no,
|
||||||
|
hexpand=True,
|
||||||
|
halign=Gtk.Align.END,
|
||||||
|
margin_top=12,
|
||||||
|
margin_bottom=12,
|
||||||
|
margin_end=12,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
# Order rows based on the number of games in them
|
||||||
|
index = 3
|
||||||
|
while source_row := self.sidebar.get_row_at_index(index):
|
||||||
|
if self.source_rows[source_row][1] < games_no:
|
||||||
|
self.sidebar.insert(row, index)
|
||||||
|
break
|
||||||
|
index += 1
|
||||||
|
if not row.get_parent():
|
||||||
|
self.sidebar.append(row)
|
||||||
|
|
||||||
|
self.source_rows[row.get_parent()] = (
|
||||||
|
source_id,
|
||||||
|
games_no,
|
||||||
|
)
|
||||||
|
|
||||||
if source_id == selected_id:
|
if source_id == selected_id:
|
||||||
self.sidebar.select_row(row.get_parent())
|
self.sidebar.select_row(row.get_parent())
|
||||||
@@ -147,7 +176,7 @@ class CartridgesWindow(Adw.ApplicationWindow):
|
|||||||
case self.added_row_box:
|
case self.added_row_box:
|
||||||
value = "imported"
|
value = "imported"
|
||||||
case _default:
|
case _default:
|
||||||
value = self.source_rows[row]
|
value = self.source_rows[row][0]
|
||||||
|
|
||||||
self.filter_state = value
|
self.filter_state = value
|
||||||
self.library.invalidate_filter()
|
self.library.invalidate_filter()
|
||||||
|
|||||||
Reference in New Issue
Block a user