Skip to content

Commit 3881a58

Browse files
committed
Allow selection of multiple folders in assets
Allow (hack a) selection of multiple folders (in the same directory) in the assets prompt (with an ugly ui).
1 parent c71f30a commit 3881a58

1 file changed

Lines changed: 30 additions & 10 deletions

File tree

src/widgets/aooptionsdialog.cpp

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <QResource>
1515
#include <QUiLoader>
1616
#include <QVBoxLayout>
17+
#include <qtreeview.h>
1718

1819
AOOptionsDialog::AOOptionsDialog(AOApplication *p_ao_app, QWidget *parent)
1920
: QDialog(parent)
@@ -445,20 +446,39 @@ void AOOptionsDialog::setupUI()
445446

446447
FROM_UI(QPushButton, mount_add);
447448
connect(ui_mount_add, &QPushButton::clicked, this, [this] {
448-
QString path = QFileDialog::getExistingDirectory(this, tr("Select a base folder"), get_app_path(), QFileDialog::ShowDirsOnly);
449-
if (path.isEmpty())
449+
// QString path = QFileDialog::getExistingDirectory(this, tr("Select one or more base folders"), get_app_path(), QFileDialog::ShowDirsOnly);
450+
451+
QFileDialog* _fileddialogue = new QFileDialog(this);
452+
_fileddialogue->setFileMode(QFileDialog::Directory);
453+
//Switches to non-native so the tree is obtainable, otherwise it will crash on varying platforms probably.
454+
_fileddialogue->setOption(QFileDialog::DontUseNativeDialog, true);
455+
_fileddialogue->findChild<QTreeView*>("treeView")->setSelectionMode(QAbstractItemView::MultiSelection);
456+
457+
_fileddialogue->exec();
458+
QStringList _filepaths = _fileddialogue->selectedFiles();
459+
// qInfo() <<"Paths are " << _filepaths;
460+
461+
if (_filepaths.isEmpty())
450462
{
451463
return;
452464
}
453-
QDir dir(get_app_path());
454-
QString relative = dir.relativeFilePath(path);
455-
if (!relative.contains("../"))
456-
{
457-
path = relative;
465+
466+
foreach(QString mountPath, _filepaths) {
467+
if (_filepaths.indexOf(mountPath) == 0) {
468+
continue;
469+
}
470+
QDir dir(get_app_path());
471+
QString relative = dir.relativeFilePath(mountPath);
472+
if (!relative.contains("../"))
473+
{
474+
mountPath = relative;
475+
}
476+
QListWidgetItem *dir_item = new QListWidgetItem(mountPath);
477+
ui_mount_list->addItem(dir_item);
478+
ui_mount_list->setCurrentItem(dir_item);
458479
}
459-
QListWidgetItem *dir_item = new QListWidgetItem(path);
460-
ui_mount_list->addItem(dir_item);
461-
ui_mount_list->setCurrentItem(dir_item);
480+
481+
462482

463483
// quick hack to update buttons
464484
Q_EMIT ui_mount_list->itemSelectionChanged();

0 commit comments

Comments
 (0)