From 69379334f90bc6c4c7b94f2f0fc8e347d2218c19 Mon Sep 17 00:00:00 2001 From: RickyRister <42636155+RickyRister@users.noreply.github.com> Date: Mon, 23 Dec 2024 17:31:58 -0800 Subject: [PATCH] support multi-select for local replay tab (#5309) --- cockatrice/src/client/tabs/tab_replays.cpp | 47 +++++++++++++--------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/cockatrice/src/client/tabs/tab_replays.cpp b/cockatrice/src/client/tabs/tab_replays.cpp index 3a3655d79..0b979536e 100644 --- a/cockatrice/src/client/tabs/tab_replays.cpp +++ b/cockatrice/src/client/tabs/tab_replays.cpp @@ -36,6 +36,7 @@ TabReplays::TabReplays(TabSupervisor *_tabSupervisor, AbstractClient *_client) : localDirView->setColumnHidden(1, true); localDirView->setRootIndex(localDirModel->index(localDirModel->rootPath(), 0)); localDirView->setSortingEnabled(true); + localDirView->setSelectionMode(QAbstractItemView::ExtendedSelection); localDirView->header()->setSectionResizeMode(QHeaderView::ResizeToContents); localDirView->header()->setSortIndicator(0, Qt::AscendingOrder); @@ -126,35 +127,43 @@ void TabReplays::retranslateUi() void TabReplays::actOpenLocalReplay() { - QModelIndex curLeft = localDirView->selectionModel()->currentIndex(); - if (localDirModel->isDir(curLeft)) - return; - QString filePath = localDirModel->filePath(curLeft); + QModelIndexList curLefts = localDirView->selectionModel()->selectedRows(); + for (const auto &curLeft : curLefts) { + if (localDirModel->isDir(curLeft)) + continue; + QString filePath = localDirModel->filePath(curLeft); - QFile f(filePath); - if (!f.open(QIODevice::ReadOnly)) - return; - QByteArray _data = f.readAll(); - f.close(); + QFile f(filePath); + if (!f.open(QIODevice::ReadOnly)) + continue; + QByteArray _data = f.readAll(); + f.close(); - GameReplay *replay = new GameReplay; - replay->ParseFromArray(_data.data(), _data.size()); + GameReplay *replay = new GameReplay; + replay->ParseFromArray(_data.data(), _data.size()); - emit openReplay(replay); + emit openReplay(replay); + } } void TabReplays::actDeleteLocalReplay() { - QModelIndex curLeft = localDirView->selectionModel()->currentIndex(); - if (!curLeft.isValid()) - return; + QModelIndexList curLefts = localDirView->selectionModel()->selectedRows(); - if (QMessageBox::warning(this, tr("Delete local file"), - tr("Are you sure you want to delete \"%1\"?").arg(localDirModel->fileName(curLeft)), - QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) + if (curLefts.isEmpty()) { return; + } - localDirModel->remove(curLeft); + if (QMessageBox::warning(this, tr("Delete local file"), tr("Are you sure you want to delete the selected files?"), + QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) { + return; + } + + for (const auto &curLeft : curLefts) { + if (curLeft.isValid()) { + localDirModel->remove(curLeft); + } + } } void TabReplays::actOpenRemoteReplay()