Implemented deletion of playlists.
This commit is contained in:
parent
5ecc70e637
commit
96a9985099
3 changed files with 34 additions and 9 deletions
|
@ -128,14 +128,31 @@ class Playlist:
|
||||||
wbz.write(wbz_data)
|
wbz.write(wbz_data)
|
||||||
wbz.close()
|
wbz.close()
|
||||||
|
|
||||||
def delete(self):
|
def rename(self, title: str):
|
||||||
# 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 and delete old playlist.
|
||||||
self.app.utils.unique_names.remove(self.title)
|
|
||||||
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"
|
||||||
|
path = os.path.expanduser(path)
|
||||||
|
|
||||||
if os.path.exists(path):
|
if os.path.exists(path):
|
||||||
os.remove(os.path.expanduser(path))
|
os.remove(os.path.expanduser(path))
|
||||||
|
|
||||||
|
old_title = self.title
|
||||||
|
self.title = self.app.utils.unique_name(title, ignore=old_title)
|
||||||
|
|
||||||
|
if not old_title == self.title: # remove only when the playlist actually has a different name
|
||||||
|
self.app.utils.unique_names.remove(old_title)
|
||||||
|
|
||||||
|
def delete(self):
|
||||||
|
path = f"{self.app.settings.library_path}/playlists/{self.title.replace(" ", "_")}.wbz.m3u"
|
||||||
|
path = os.path.expanduser(path)
|
||||||
|
|
||||||
|
if os.path.exists(path):
|
||||||
|
os.remove(os.path.expanduser(path))
|
||||||
|
|
||||||
|
self.app.utils.unique_names.remove(self.title)
|
||||||
|
self.app.library.playlists.remove(self)
|
||||||
|
|
||||||
def append_track(self, track):
|
def append_track(self, track):
|
||||||
self.tracks.append(track)
|
self.tracks.append(track)
|
||||||
|
|
||||||
|
|
|
@ -13,17 +13,28 @@ class PlaylistContextMenu(QMenu):
|
||||||
|
|
||||||
self.playlist_title = None
|
self.playlist_title = None
|
||||||
|
|
||||||
self.rename_action = QAction("Rename")
|
self.title = self.addSection("Playlist Actions")
|
||||||
|
|
||||||
|
self.rename_action = QAction("Rename")
|
||||||
self.addAction(self.rename_action)
|
self.addAction(self.rename_action)
|
||||||
|
|
||||||
|
self.delete_action = QAction("Delete")
|
||||||
|
self.addAction(self.delete_action)
|
||||||
|
|
||||||
self.rename_action.triggered.connect(self.rename)
|
self.rename_action.triggered.connect(self.rename)
|
||||||
|
self.delete_action.triggered.connect(self.delete)
|
||||||
|
|
||||||
def exec(self, pos: QPoint, title):
|
def exec(self, pos: QPoint, title):
|
||||||
self.playlist_title = title
|
self.playlist_title = title
|
||||||
|
|
||||||
|
self.title.setText(title.text()) # set section title
|
||||||
|
|
||||||
super().exec(pos)
|
super().exec(pos)
|
||||||
|
|
||||||
def rename(self):
|
def rename(self):
|
||||||
self.playlist_title.setFocus()
|
self.playlist_title.setFocus()
|
||||||
|
|
||||||
|
def delete(self):
|
||||||
|
self.playlist_title.playlist_view.playlist.delete()
|
||||||
|
self.playlist_title.playlist_view.deleteLater()
|
||||||
|
|
||||||
|
|
|
@ -35,10 +35,7 @@ class TabTitle(QLineEdit):
|
||||||
def on_edit(self):
|
def on_edit(self):
|
||||||
self.clearFocus()
|
self.clearFocus()
|
||||||
|
|
||||||
self.playlist_view.playlist.delete()
|
self.playlist_view.playlist.rename(self.text())
|
||||||
|
|
||||||
name = self.app.utils.unique_name(self.text(), ignore=self.playlist_view.playlist.title)
|
self.setText(self.playlist_view.playlist.title)
|
||||||
self.setText(name)
|
|
||||||
|
|
||||||
self.playlist_view.playlist.title = name
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue