Added unique names on playlist rename.

This commit is contained in:
The Wobbler 2025-01-27 18:32:41 +01:00
parent b95081e840
commit a8560add65
3 changed files with 12 additions and 5 deletions

View file

@ -124,6 +124,8 @@ class Playlist:
wbz.close() wbz.close()
def delete(self): def delete(self):
self.app.utils.unique_names.pop(self.title) # remove from unique names so a new playlist can have the old name
path = f"{self.app.settings.library_path}/playlists/{self.title.replace(" ", "_")}.wbz.m3u" path = f"{self.app.settings.library_path}/playlists/{self.title.replace(" ", "_")}.wbz.m3u"
if os.path.exists(path): if os.path.exists(path):

View file

@ -8,9 +8,10 @@ from .tab_bar import PlaylistTabBar
class TabTitle(QLineEdit): class TabTitle(QLineEdit):
def __init__(self, label, parent, index: int, playlist_view): def __init__(self, app, label, parent, index: int, playlist_view):
super().__init__(label, parent) super().__init__(label, parent)
self.app = app
self.tab_bar: PlaylistTabBar = parent self.tab_bar: PlaylistTabBar = parent
self.index = index self.index = index
self.playlist_view = playlist_view self.playlist_view = playlist_view
@ -36,5 +37,8 @@ class TabTitle(QLineEdit):
self.playlist_view.playlist.delete() self.playlist_view.playlist.delete()
self.playlist_view.playlist.title = self.text() name = self.app.utils.unique_name(self.text())
self.setText(name)
self.playlist_view.playlist.title = name

View file

@ -8,10 +8,11 @@ from .tab_title import TabTitle
class PlaylistTabs(QTabWidget): class PlaylistTabs(QTabWidget):
def __init__(self, library, parent=None): def __init__(self, library, parent=None):
self.library = library
super().__init__(parent) super().__init__(parent)
self.library = library
self.app = library.app
self.tab_bar = PlaylistTabBar(self) self.tab_bar = PlaylistTabBar(self)
self.setTabBar(self.tab_bar) self.setTabBar(self.tab_bar)
self.setDocumentMode(True) self.setDocumentMode(True)
@ -24,7 +25,7 @@ class PlaylistTabs(QTabWidget):
index = self.tab_bar.count() - 1 index = self.tab_bar.count() - 1
title = TabTitle(label, self.tab_bar, index, widget) title = TabTitle(self.app, label, self.tab_bar, index, widget)
self.tab_bar.setTabButton(index, QTabBar.ButtonPosition.RightSide, title) self.tab_bar.setTabButton(index, QTabBar.ButtonPosition.RightSide, title)