diff --git a/app/models.py b/app/models.py index 589fca5..fd81f00 100644 --- a/app/models.py +++ b/app/models.py @@ -341,6 +341,9 @@ class Playlists(Base): def remove_track(self, session: Session, row: int) -> None: DEBUG(f"Playlist.remove_track({self.id=}, {row=})") + # Refresh self first (this is necessary when calling remove_track + # multiple times before session.commit()) + session.refresh(self) # Get tracks collection for this playlist # Tracks are a dictionary of tracks keyed on row # number. Remove the relevant row. diff --git a/app/playlists.py b/app/playlists.py index 7ddeed9..5c956e8 100644 --- a/app/playlists.py +++ b/app/playlists.py @@ -1033,7 +1033,7 @@ class PlaylistTab(QTableWidget): DEBUG("playlist._delete_rows()") - rows: List[int] = sorted( + selected_rows: List[int] = sorted( set(item.row() for item in self.selectedItems()) ) rows_to_delete: List[int] = [] @@ -1042,17 +1042,22 @@ class PlaylistTab(QTableWidget): row_object: Union[Tracks, Notes] with Session() as session: - for row in rows: + for row in selected_rows: title = self.item(row, self.COL_TITLE).text() msg = QMessageBox(self) msg.setIcon(QMessageBox.Warning) msg.setText(f"Delete '{title}'?") - msg.setStandardButtons(QMessageBox.Yes | QMessageBox.Cancel) - msg.setDefaultButton(QMessageBox.Cancel) + msg.setStandardButtons( + QMessageBox.Yes | QMessageBox.No | QMessageBox.Cancel + ) + msg.setDefaultButton(QMessageBox.No) msg.setWindowTitle("Delete row") # Store list of rows to delete - if msg.exec() == QMessageBox.Yes: + response = msg.exec() + if response == QMessageBox.Yes: rows_to_delete.append(row) + elif response == QMessageBox.Cancel: + return # delete in reverse row order so row numbers don't # change