Fix row_selected logic

This commit is contained in:
kramo
2023-07-07 22:00:24 +02:00
parent e7d27cc1c4
commit fe5b85c79c

View File

@@ -80,17 +80,25 @@ class CartridgesWindow(Adw.ApplicationWindow):
source_rows = {} source_rows = {}
def create_source_rows(self): def create_source_rows(self):
selected_id = (
self.source_rows[selected_row]
if (selected_row := self.sidebar.get_selected_row()) in self.source_rows
else None
)
self.sidebar.get_row_at_index(2).set_visible(False) self.sidebar.get_row_at_index(2).set_visible(False)
while row := self.sidebar.get_row_at_index(3): while row := self.sidebar.get_row_at_index(3):
self.sidebar.remove(row) self.sidebar.remove(row)
def get_removed(source_id): def get_removed(source_id):
for game in shared.store.source_games[source_id].values(): if all(
if game.removed: game.removed for game in shared.store.source_games[source_id].values()
return True ):
return True
return False return False
restored = False
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
@@ -108,19 +116,26 @@ class CartridgesWindow(Adw.ApplicationWindow):
self.sidebar.append(row) self.sidebar.append(row)
self.source_rows[row.get_parent()] = source_id self.source_rows[row.get_parent()] = source_id
if source_id == selected_id:
self.sidebar.select_row(row.get_parent())
restored = True
self.sidebar.get_row_at_index(2).set_visible(True) self.sidebar.get_row_at_index(2).set_visible(True)
def row_selected(self, widget, row): if not restored:
self.sidebar.select_row(self.all_games_row_box.get_parent())
def row_selected(self, _widget, row):
if not row: if not row:
widget.select_row(self.all_games_row_box.get_parent()) return
try: match row.get_child():
value = self.source_rows[row] case self.all_games_row_box:
except KeyError: value = "all"
match row.get_child(): case self.added_row_box:
case self.all_games_row_box: value = "imported"
value = "all" case _default:
case self.added_row_box: value = self.source_rows[row]
value = "imported"
self.filter_state = value self.filter_state = value
self.library.invalidate_filter() self.library.invalidate_filter()