From b4ad7fe396285546487b37014f182a26779f9abb Mon Sep 17 00:00:00 2001 From: ozxybox Date: Mon, 30 Sep 2024 01:10:48 -0500 Subject: [PATCH] feat: add support for adding multiple files to a pack at once without using add folder --- src/gui/EntryContextMenuData.h | 4 ++-- src/gui/EntryTree.cpp | 4 ++-- src/gui/Window.cpp | 13 +++++++++++-- src/gui/Window.h | 2 ++ src/gui/previews/DirPreview.cpp | 2 +- 5 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/gui/EntryContextMenuData.h b/src/gui/EntryContextMenuData.h index 1e9d3be..2a287e6 100644 --- a/src/gui/EntryContextMenuData.h +++ b/src/gui/EntryContextMenuData.h @@ -19,7 +19,7 @@ struct EntryContextMenuData { this->contextMenuDir = new QMenu(parent); this->extractDirAction = this->contextMenuDir->addAction(parent->style()->standardIcon(QStyle::SP_DialogSaveButton), QObject::tr("Extract Folder...")); this->contextMenuDir->addSeparator(); - this->addFileToDirAction = this->contextMenuDir->addAction(parent->style()->standardIcon(QStyle::SP_FileLinkIcon), QObject::tr("Add File...")); + this->addFileToDirAction = this->contextMenuDir->addAction(parent->style()->standardIcon(QStyle::SP_FileLinkIcon), QObject::tr("Add Files...")); this->addDirToDirAction = this->contextMenuDir->addAction(parent->style()->standardIcon(QStyle::SP_DirLinkIcon), QObject::tr("Add Folder...")); this->contextMenuDir->addSeparator(); this->renameDirAction = this->contextMenuDir->addAction(parent->style()->standardIcon(QStyle::SP_DialogResetButton), QObject::tr("Rename/Move Folder...")); @@ -36,7 +36,7 @@ struct EntryContextMenuData { this->contextMenuAll = new QMenu(parent); this->extractAllAction = this->contextMenuAll->addAction(parent->style()->standardIcon(QStyle::SP_DialogSaveButton), QObject::tr("Extract All...")); this->contextMenuAll->addSeparator(); - this->addFileToRootAction = this->contextMenuAll->addAction(parent->style()->standardIcon(QStyle::SP_FileLinkIcon), QObject::tr("Add File...")); + this->addFileToRootAction = this->contextMenuAll->addAction(parent->style()->standardIcon(QStyle::SP_FileLinkIcon), QObject::tr("Add Files...")); this->addDirToRootAction = this->contextMenuAll->addAction(parent->style()->standardIcon(QStyle::SP_DirLinkIcon), QObject::tr("Add Folder...")); } } diff --git a/src/gui/EntryTree.cpp b/src/gui/EntryTree.cpp index 9707bff..cab9daf 100644 --- a/src/gui/EntryTree.cpp +++ b/src/gui/EntryTree.cpp @@ -169,7 +169,7 @@ EntryTree::EntryTree(Window* window_, QWidget* parent) if (selectedAllAction == contextMenuData.extractAllAction) { this->window->extractAll(); } else if (selectedAllAction == contextMenuData.addFileToRootAction) { - this->window->addFile(false); + this->window->addFiles(false); } else if (selectedAllAction == contextMenuData.addDirToRootAction) { this->window->addDir(false); } @@ -181,7 +181,7 @@ EntryTree::EntryTree(Window* window_, QWidget* parent) if (selectedDirAction == contextMenuData.extractDirAction) { this->window->extractDir(path); } else if (selectedDirAction == contextMenuData.addFileToDirAction) { - this->window->addFile(false, path); + this->window->addFiles(false, path); } else if (selectedDirAction == contextMenuData.addDirToDirAction) { this->window->addDir(false, path); } else if (selectedDirAction == contextMenuData.renameDirAction) { diff --git a/src/gui/Window.cpp b/src/gui/Window.cpp index 7a2e9f5..04fafc7 100644 --- a/src/gui/Window.cpp +++ b/src/gui/Window.cpp @@ -165,8 +165,8 @@ Window::Window(QWidget* parent) this->extractAllAction->setDisabled(true); editMenu->addSeparator(); - this->addFileAction = editMenu->addAction(this->style()->standardIcon(QStyle::SP_FileLinkIcon), tr("Add File..."), Qt::CTRL | Qt::Key_A, [this] { - this->addFile(true); + this->addFileAction = editMenu->addAction(this->style()->standardIcon(QStyle::SP_FileLinkIcon), tr("Add Files..."), Qt::CTRL | Qt::Key_A, [this] { + this->addFiles(true); }); this->addFileAction->setDisabled(true); @@ -873,6 +873,15 @@ void Window::addFile(bool showOptions, const QString& startDir, const QString& f this->markModified(true); } + +void Window::addFiles(bool showOptions, const QString &startDir) { + // Add multiple files using the multiple file selector + QStringList files = QFileDialog::getOpenFileNames(this, tr("Open Files")); + for (const QString& path : files) { + this->addFile(showOptions, startDir, path); + } +} + void Window::addDir(bool showOptions, const QString& startDir, const QString& dirPath) { auto dirpath = dirPath; if (dirpath.isEmpty()) { diff --git a/src/gui/Window.h b/src/gui/Window.h index 370a002..182d1c3 100644 --- a/src/gui/Window.h +++ b/src/gui/Window.h @@ -64,6 +64,8 @@ class Window : public QMainWindow { void addFile(bool showOptions, const QString& startDir = QString(), const QString& filePath = QString()); + void addFiles(bool showOptions, const QString& startDir = QString()); + void addDir(bool showOptions, const QString& startDir = QString(), const QString& dirPath = QString()); bool removeFile(const QString& path); diff --git a/src/gui/previews/DirPreview.cpp b/src/gui/previews/DirPreview.cpp index 67d4370..71d16d6 100644 --- a/src/gui/previews/DirPreview.cpp +++ b/src/gui/previews/DirPreview.cpp @@ -138,7 +138,7 @@ DirPreview::DirPreview(FileViewer* fileViewer_, Window* window_, QWidget* parent if (selectedDirAction == contextMenuData.extractDirAction) { this->window->extractDir(path); } else if (selectedDirAction == contextMenuData.addFileToDirAction) { - this->window->addFile(false, path); + this->window->addFiles(false, path); } else if (selectedDirAction == contextMenuData.addDirToDirAction) { this->window->addDir(false, path); } else if (selectedDirAction == contextMenuData.renameDirAction) {