support multi-select for local replay tab (#5309)

This commit is contained in:
RickyRister 2024-12-23 17:31:58 -08:00 committed by GitHub
parent 12e50a1f2f
commit 69379334f9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -36,6 +36,7 @@ TabReplays::TabReplays(TabSupervisor *_tabSupervisor, AbstractClient *_client) :
localDirView->setColumnHidden(1, true); localDirView->setColumnHidden(1, true);
localDirView->setRootIndex(localDirModel->index(localDirModel->rootPath(), 0)); localDirView->setRootIndex(localDirModel->index(localDirModel->rootPath(), 0));
localDirView->setSortingEnabled(true); localDirView->setSortingEnabled(true);
localDirView->setSelectionMode(QAbstractItemView::ExtendedSelection);
localDirView->header()->setSectionResizeMode(QHeaderView::ResizeToContents); localDirView->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
localDirView->header()->setSortIndicator(0, Qt::AscendingOrder); localDirView->header()->setSortIndicator(0, Qt::AscendingOrder);
@ -126,35 +127,43 @@ void TabReplays::retranslateUi()
void TabReplays::actOpenLocalReplay() void TabReplays::actOpenLocalReplay()
{ {
QModelIndex curLeft = localDirView->selectionModel()->currentIndex(); QModelIndexList curLefts = localDirView->selectionModel()->selectedRows();
if (localDirModel->isDir(curLeft)) for (const auto &curLeft : curLefts) {
return; if (localDirModel->isDir(curLeft))
QString filePath = localDirModel->filePath(curLeft); continue;
QString filePath = localDirModel->filePath(curLeft);
QFile f(filePath); QFile f(filePath);
if (!f.open(QIODevice::ReadOnly)) if (!f.open(QIODevice::ReadOnly))
return; continue;
QByteArray _data = f.readAll(); QByteArray _data = f.readAll();
f.close(); f.close();
GameReplay *replay = new GameReplay; GameReplay *replay = new GameReplay;
replay->ParseFromArray(_data.data(), _data.size()); replay->ParseFromArray(_data.data(), _data.size());
emit openReplay(replay); emit openReplay(replay);
}
} }
void TabReplays::actDeleteLocalReplay() void TabReplays::actDeleteLocalReplay()
{ {
QModelIndex curLeft = localDirView->selectionModel()->currentIndex(); QModelIndexList curLefts = localDirView->selectionModel()->selectedRows();
if (!curLeft.isValid())
return;
if (QMessageBox::warning(this, tr("Delete local file"), if (curLefts.isEmpty()) {
tr("Are you sure you want to delete \"%1\"?").arg(localDirModel->fileName(curLeft)),
QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes)
return; 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() void TabReplays::actOpenRemoteReplay()