Fix broken playlist undostack when i.e. removing duplicates and unavailable songs
This commit is contained in:
@@ -2026,7 +2026,7 @@ void MainWindow::ShowInCollection() {
|
||||
}
|
||||
|
||||
void MainWindow::PlaylistRemoveCurrent() {
|
||||
ui_->playlist->view()->RemoveSelected(false);
|
||||
ui_->playlist->view()->RemoveSelected();
|
||||
}
|
||||
|
||||
void MainWindow::PlaylistClearCurrent() {
|
||||
|
||||
@@ -930,7 +930,8 @@ void Playlist::InsertItems(const PlaylistItemList &itemsIn, int pos, bool play_n
|
||||
// Too big to keep in the undo stack. Also clear the stack because it might have been invalidated.
|
||||
InsertItemsWithoutUndo(items, pos, enqueue, enqueue_next);
|
||||
undo_stack_->clear();
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
undo_stack_->push(new PlaylistUndoCommands::InsertItems(this, items, pos, enqueue, enqueue_next));
|
||||
}
|
||||
|
||||
@@ -1384,6 +1385,8 @@ void Playlist::RemoveItemsWithoutUndo(const QList<int> &indicesIn) {
|
||||
|
||||
bool Playlist::removeRows(int row, int count, const QModelIndex &parent) {
|
||||
|
||||
Q_UNUSED(parent);
|
||||
|
||||
if (row < 0 || row >= items_.size() || row + count > items_.size()) {
|
||||
return false;
|
||||
}
|
||||
@@ -1393,9 +1396,6 @@ bool Playlist::removeRows(int row, int count, const QModelIndex &parent) {
|
||||
RemoveItemsWithoutUndo(row, count);
|
||||
undo_stack_->clear();
|
||||
}
|
||||
else if (parent == QModelIndex()) {
|
||||
RemoveItemsWithoutUndo(row, count);
|
||||
}
|
||||
else {
|
||||
undo_stack_->push(new PlaylistUndoCommands::RemoveItems(this, row, count));
|
||||
}
|
||||
|
||||
@@ -543,12 +543,12 @@ void PlaylistView::keyPressEvent(QKeyEvent *event) {
|
||||
QTreeView::keyPressEvent(event);
|
||||
}
|
||||
else if (event == QKeySequence::Delete) {
|
||||
RemoveSelected(false);
|
||||
RemoveSelected();
|
||||
event->accept();
|
||||
#ifdef Q_OS_MACOS
|
||||
}
|
||||
else if (event->key() == Qt::Key_Backspace) {
|
||||
RemoveSelected(false);
|
||||
RemoveSelected();
|
||||
event->accept();
|
||||
#endif
|
||||
}
|
||||
@@ -586,7 +586,7 @@ void PlaylistView::contextMenuEvent(QContextMenuEvent *e) {
|
||||
e->accept();
|
||||
}
|
||||
|
||||
void PlaylistView::RemoveSelected(bool deleting_from_disk) {
|
||||
void PlaylistView::RemoveSelected() {
|
||||
|
||||
int rows_removed = 0;
|
||||
QItemSelection selection(selectionModel()->selection());
|
||||
@@ -603,13 +603,7 @@ void PlaylistView::RemoveSelected(bool deleting_from_disk) {
|
||||
|
||||
for (const QItemSelectionRange &range : selection) {
|
||||
if (range.top() < last_row) rows_removed += range.height();
|
||||
|
||||
if (!deleting_from_disk) {
|
||||
model()->removeRows(range.top(), range.height(), range.topLeft());
|
||||
}
|
||||
else {
|
||||
model()->removeRows(range.top(), range.height(), QModelIndex());
|
||||
}
|
||||
model()->removeRows(range.top(), range.height(), range.parent());
|
||||
}
|
||||
|
||||
int new_row = last_row - rows_removed;
|
||||
|
||||
@@ -101,7 +101,7 @@ class PlaylistView : public QTreeView {
|
||||
void SetApplication(Application *app);
|
||||
void SetItemDelegates(CollectionBackend *backend);
|
||||
void SetPlaylist(Playlist *playlist);
|
||||
void RemoveSelected(bool deleting_from_disk);
|
||||
void RemoveSelected();
|
||||
|
||||
void SetReadOnlySettings(bool read_only) { read_only_settings_ = read_only; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user