Fix deleting multiple rows
Also allow mass delete to be cancelled. Fixes #115
This commit is contained in:
parent
a8395d8c97
commit
fbe9c2ba94
@ -341,6 +341,9 @@ class Playlists(Base):
|
|||||||
def remove_track(self, session: Session, row: int) -> None:
|
def remove_track(self, session: Session, row: int) -> None:
|
||||||
DEBUG(f"Playlist.remove_track({self.id=}, {row=})")
|
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
|
# Get tracks collection for this playlist
|
||||||
# Tracks are a dictionary of tracks keyed on row
|
# Tracks are a dictionary of tracks keyed on row
|
||||||
# number. Remove the relevant row.
|
# number. Remove the relevant row.
|
||||||
|
|||||||
@ -1033,7 +1033,7 @@ class PlaylistTab(QTableWidget):
|
|||||||
|
|
||||||
DEBUG("playlist._delete_rows()")
|
DEBUG("playlist._delete_rows()")
|
||||||
|
|
||||||
rows: List[int] = sorted(
|
selected_rows: List[int] = sorted(
|
||||||
set(item.row() for item in self.selectedItems())
|
set(item.row() for item in self.selectedItems())
|
||||||
)
|
)
|
||||||
rows_to_delete: List[int] = []
|
rows_to_delete: List[int] = []
|
||||||
@ -1042,17 +1042,22 @@ class PlaylistTab(QTableWidget):
|
|||||||
row_object: Union[Tracks, Notes]
|
row_object: Union[Tracks, Notes]
|
||||||
|
|
||||||
with Session() as session:
|
with Session() as session:
|
||||||
for row in rows:
|
for row in selected_rows:
|
||||||
title = self.item(row, self.COL_TITLE).text()
|
title = self.item(row, self.COL_TITLE).text()
|
||||||
msg = QMessageBox(self)
|
msg = QMessageBox(self)
|
||||||
msg.setIcon(QMessageBox.Warning)
|
msg.setIcon(QMessageBox.Warning)
|
||||||
msg.setText(f"Delete '{title}'?")
|
msg.setText(f"Delete '{title}'?")
|
||||||
msg.setStandardButtons(QMessageBox.Yes | QMessageBox.Cancel)
|
msg.setStandardButtons(
|
||||||
msg.setDefaultButton(QMessageBox.Cancel)
|
QMessageBox.Yes | QMessageBox.No | QMessageBox.Cancel
|
||||||
|
)
|
||||||
|
msg.setDefaultButton(QMessageBox.No)
|
||||||
msg.setWindowTitle("Delete row")
|
msg.setWindowTitle("Delete row")
|
||||||
# Store list of rows to delete
|
# Store list of rows to delete
|
||||||
if msg.exec() == QMessageBox.Yes:
|
response = msg.exec()
|
||||||
|
if response == QMessageBox.Yes:
|
||||||
rows_to_delete.append(row)
|
rows_to_delete.append(row)
|
||||||
|
elif response == QMessageBox.Cancel:
|
||||||
|
return
|
||||||
|
|
||||||
# delete in reverse row order so row numbers don't
|
# delete in reverse row order so row numbers don't
|
||||||
# change
|
# change
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user