Fix issues saving/restoring active tab

Fixes #212
This commit is contained in:
Keith Edmunds 2023-12-08 14:00:59 +00:00
parent 06ef175b46
commit 7ed54f2bab
2 changed files with 23 additions and 1 deletions

View File

@ -239,6 +239,20 @@ class Playlists(Base):
session.add(self)
session.flush()
@staticmethod
def clear_tabs(session: scoped_session, playlist_ids: List[int]) -> None:
"""
Make all tab records NULL
"""
session.execute(
update(Playlists)
.where(
(Playlists.id.in_(playlist_ids))
)
.values(tab=None)
)
def close(self) -> None:
"""Mark playlist as unloaded"""

View File

@ -875,15 +875,23 @@ class Window(QMainWindow, Ui_MainWindow):
def load_last_playlists(self) -> None:
"""Load the playlists that were open when the last session closed"""
playlist_ids = []
with Session() as session:
for playlist in Playlists.get_open(session):
if playlist:
_ = self.create_playlist_tab(playlist)
playlist_ids.append(playlist.id)
# Set active tab
record = Settings.get_int_settings(session, "active_tab")
if record.f_int and record.f_int >= 0:
if record.f_int is not None and record.f_int >= 0:
self.tabPlaylist.setCurrentIndex(record.f_int)
# Tabs may move during use. Rather than track where tabs
# are, we record the tab index when we close the main
# window. To avoid possible duplicate tab entries, we null
# them all out now.
Playlists.clear_tabs(session, playlist_ids)
def lookup_row_in_songfacts(self) -> None:
"""
Display songfacts page for title in highlighted row