support multi-select for local decks in deck storage tab (#5314)

* allow multi-select

* support multi upload

* support multi open deck

* support multi delete deck
This commit is contained in:
RickyRister 2024-12-23 17:41:15 -08:00 committed by GitHub
parent 0234a70bfd
commit a40d8092ce
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 42 additions and 17 deletions

View file

@ -41,6 +41,7 @@ TabDeckStorage::TabDeckStorage(TabSupervisor *_tabSupervisor, AbstractClient *_c
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);
@ -149,30 +150,45 @@ QString TabDeckStorage::getTargetPath() const
void TabDeckStorage::actOpenLocalDeck() void TabDeckStorage::actOpenLocalDeck()
{ {
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); return;
QString filePath = localDirModel->filePath(curLeft);
DeckLoader deckLoader; DeckLoader deckLoader;
if (!deckLoader.loadFromFile(filePath, DeckLoader::CockatriceFormat)) if (!deckLoader.loadFromFile(filePath, DeckLoader::CockatriceFormat))
return; return;
emit openDeckEditor(&deckLoader); emit openDeckEditor(&deckLoader);
}
} }
void TabDeckStorage::actUpload() void TabDeckStorage::actUpload()
{ {
QModelIndex curLeft = localDirView->selectionModel()->currentIndex(); QModelIndexList curLefts = localDirView->selectionModel()->selectedRows();
if (localDirModel->isDir(curLeft)) if (curLefts.isEmpty()) {
return; return;
}
QString targetPath = getTargetPath(); QString targetPath = getTargetPath();
if (targetPath.length() > MAX_NAME_LENGTH) { if (targetPath.length() > MAX_NAME_LENGTH) {
qCritical() << "target path to upload to is too long" << targetPath; qCritical() << "target path to upload to is too long" << targetPath;
return; return;
} }
QString filePath = localDirModel->filePath(curLeft); for (const auto &curLeft : curLefts) {
if (localDirModel->isDir(curLeft)) {
continue;
}
QString filePath = localDirModel->filePath(curLeft);
uploadDeck(filePath, targetPath);
}
}
void TabDeckStorage::uploadDeck(const QString &filePath, const QString &targetPath)
{
QFile deckFile(filePath); QFile deckFile(filePath);
QFileInfo deckFileInfo(deckFile); QFileInfo deckFileInfo(deckFile);
@ -228,16 +244,22 @@ void TabDeckStorage::uploadFinished(const Response &r, const CommandContainer &c
void TabDeckStorage::actDeleteLocalDeck() void TabDeckStorage::actDeleteLocalDeck()
{ {
QModelIndex curLeft = localDirView->selectionModel()->currentIndex(); const QModelIndexList curLefts = localDirView->selectionModel()->selectedRows();
if (localDirModel->isDir(curLeft))
return;
if (QMessageBox::warning(this, tr("Delete local file"), auto isDir = [&](const auto &curLeft) { return localDirModel->isDir(curLeft); };
tr("Are you sure you want to delete \"%1\"?").arg(localDirModel->fileName(curLeft)), if (curLefts.isEmpty() || std::all_of(curLefts.begin(), curLefts.end(), isDir)) {
return;
}
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) QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes)
return; return;
localDirModel->remove(curLeft); for (const auto &curLeft : curLefts) {
if (!localDirModel->isDir(curLeft)) {
localDirModel->remove(curLeft);
}
}
} }
void TabDeckStorage::actOpenRemoteDeck() void TabDeckStorage::actOpenRemoteDeck()

View file

@ -28,6 +28,9 @@ private:
QAction *aOpenLocalDeck, *aUpload, *aDeleteLocalDeck, *aOpenRemoteDeck, *aDownload, *aNewFolder, *aDeleteRemoteDeck; QAction *aOpenLocalDeck, *aUpload, *aDeleteLocalDeck, *aOpenRemoteDeck, *aDownload, *aNewFolder, *aDeleteRemoteDeck;
QString getTargetPath() const; QString getTargetPath() const;
void uploadDeck(const QString &filePath, const QString &targetPath);
private slots: private slots:
void actOpenLocalDeck(); void actOpenLocalDeck();