Skip to content

Commit

Permalink
feat: add support for adding multiple files to a pack at once
Browse files Browse the repository at this point in the history
without using add folder
  • Loading branch information
ozxybox authored and craftablescience committed Sep 30, 2024
1 parent b12d68a commit 1eca90d
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/gui/EntryContextMenuData.h
Original file line number Diff line number Diff line change
Expand Up @@ -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..."));
Expand All @@ -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..."));
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/gui/EntryTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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) {
Expand Down
13 changes: 11 additions & 2 deletions src/gui/Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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()) {
Expand Down
2 changes: 2 additions & 0 deletions src/gui/Window.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/gui/previews/DirPreview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 1eca90d

Please sign in to comment.