diff --git a/app/infotabs.py b/app/infotabs.py index c8b0a9a..8585467 100644 --- a/app/infotabs.py +++ b/app/infotabs.py @@ -20,6 +20,7 @@ class InfoTabs(QTabWidget): # Dictionary to record when tabs were last updated (so we can # re-use the oldest one later) self.last_update: Dict[QWebEngineView, datetime] = {} + self.tabtitles: Dict[int, str] = {} def open_in_songfacts(self, title): """Search Songfacts for title""" @@ -39,10 +40,19 @@ class InfoTabs(QTabWidget): def open_tab(self, url: str, title: str) -> None: """ - Open passed URL. Create new tab if we're below the maximum + Open passed URL. If URL currently displayed, switch to that tab. + Create new tab if we're below the maximum number otherwise reuse oldest content tab. """ + if url in self.tabtitles.values(): + self.setCurrentIndex( + list(self.tabtitles.keys())[ + list(self.tabtitles.values()).index(url) + ] + ) + return + short_title = title[:Config.INFO_TAB_TITLE_LENGTH] if self.count() < Config.MAX_INFO_TABS: @@ -61,6 +71,7 @@ class InfoTabs(QTabWidget): widget.setUrl(QUrl(url)) self.last_update[widget] = datetime.now() + self.tabtitles[tab_index] = url # Show newly updated tab self.setCurrentIndex(tab_index)