Improved unique name system.

This commit is contained in:
The Wobbler 2025-01-28 17:42:39 +01:00
parent a8560add65
commit e5cc7c0cdb
3 changed files with 24 additions and 12 deletions

View file

@ -9,6 +9,11 @@ class Playlist:
def __init__(self, app, title: str):
self.app = app
self.title = title # playlist title
# add to unique names so if the playlist is loaded from disk,
# no other playlist can be created using the same name
self.app.utils.unique_names.append(self.title)
self.sorting: list[Qt.SortOrder] | None = None # Custom sort order if None
self.tracks: list[Track] = []
self.current_track_index = 0
@ -124,8 +129,8 @@ class Playlist:
wbz.close()
def delete(self):
self.app.utils.unique_names.pop(self.title) # remove from unique names so a new playlist can have the old name
# remove from unique names so a new playlist can have the old name
self.app.utils.unique_names.remove(self.title)
path = f"{self.app.settings.library_path}/playlists/{self.title.replace(" ", "_")}.wbz.m3u"
if os.path.exists(path):