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