Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add possibility to select several files in FileSelector widget #5683

Merged
merged 1 commit into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Modules/jaspTestModule
3 changes: 2 additions & 1 deletion QMLComponents/components/JASP/Controls/FileSelector.qml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ TextField
property string filter : "*"
property alias buttonText : button.text
property bool directory : false
property bool multiple : false

implicitWidth : button.x + button.width

Expand All @@ -36,7 +37,7 @@ TextField
else if (selector.save)
browsedFile = messages.browseSaveFileDocumentsQML(selector.caption, selector.filter)
else
browsedFile = messages.browseOpenFileDocumentsQML(selector.caption, selector.filter)
browsedFile = messages.browseOpenFileDocumentsQML(selector.caption, selector.filter, multiple)

selector.value = browsedFile;
selector.doEditingFinished();
Expand Down
12 changes: 7 additions & 5 deletions QMLComponents/utilities/messageforwarder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,17 @@ QString MessageForwarder::askPassword(QString title, QString message)
return QInputDialog::getText(nullptr, title, message, QLineEdit::Password);
}

QString MessageForwarder::browseOpenFile(QString caption, QString browsePath, QString filter)
QString MessageForwarder::browseOpenFile(QString caption, QString browsePath, QString filter, bool multiple)
{
if(useNativeFileDialogs()) return QFileDialog::getOpenFileName(nullptr, caption, browsePath, filter);
else return QFileDialog::getOpenFileName(nullptr, caption, browsePath, filter, nullptr, QFileDialog::DontUseNativeDialog);
QFileDialog::Options options = useNativeFileDialogs() ? QFileDialog::Options() : QFileDialog::DontUseNativeDialog;

if (multiple) return QFileDialog::getOpenFileNames(nullptr, caption, browsePath, filter, nullptr, options).join(';');
else return QFileDialog::getOpenFileName(nullptr, caption, browsePath, filter, nullptr, options);
}

QString MessageForwarder::browseOpenFileDocuments(QString caption, QString filter)
QString MessageForwarder::browseOpenFileDocuments(QString caption, QString filter, bool multiple)
{
return browseOpenFile(caption, AppDirs::documents(), filter);
return browseOpenFile(caption, AppDirs::documents(), filter, multiple);
}

QString MessageForwarder::browseSaveFileDocuments(QString caption, QString filter)
Expand Down
9 changes: 4 additions & 5 deletions QMLComponents/utilities/messageforwarder.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ class MessageForwarder : public QQuickItem
static DialogResponse showSaveDiscardCancel(QString title, QString message, QString saveTxt = "", QString discardText = "", QString cancelText = "");
static DialogResponse showYesNoCancel( QString title, QString message, QString YesButtonText = "", QString NoButtonText = "", QString CancelButtonText = "");

static QString browseOpenFile( QString caption, QString browsePath, QString filter);
static QString browseOpenFile( QString caption, QString browsePath, QString filter, bool multiple = false);
static QString browseSaveFile( QString caption, QString browsePath, QString filter, QString * selectedExtension = nullptr);
static QString browseOpenFolder( QString caption, QString browsePath);
static QString browseOpenFolder( QString caption);
static QString browseOpenFileDocuments( QString caption, QString filter);
static QString browseOpenFileDocuments( QString caption, QString filter, bool multiple = false);
static QString browseSaveFileDocuments( QString caption, QString filter);

static QString askPassword(QString title, QString message);
Expand All @@ -50,15 +50,14 @@ class MessageForwarder : public QQuickItem
public slots:
DialogResponse showSaveDiscardCancelQML(QString title, QString message, QString saveTxt = "", QString discardText = "", QString cancelText = "") { return showSaveDiscardCancel(title, message, saveTxt, discardText, cancelText); }
void showWarningQML(QString title, QString message) { showWarning(title, message); }
QString browseOpenFileQML(QString caption, QString browsePath, QString filter) { return browseOpenFile(caption, browsePath, filter); }
QString browseOpenFileDocumentsQML(QString caption, QString filter) { return browseOpenFileDocuments(caption, filter); }
QString browseOpenFileQML(QString caption, QString browsePath, QString filter, bool multiple = false) { return browseOpenFile(caption, browsePath, filter, multiple); }
QString browseOpenFileDocumentsQML(QString caption, QString filter, bool multiple = false) { return browseOpenFileDocuments(caption, filter, multiple); }

QString browseSaveFileQML(QString caption, QString browsePath, QString filter) { return browseSaveFile(caption, browsePath, filter); }
QString browseSaveFileDocumentsQML(QString caption, QString filter) { return browseSaveFileDocuments(caption, filter); }
QString browseOpenFolderQML(QString caption, QString browsePath) { return browseOpenFolder(caption, browsePath);}
QString browseOpenFolderQML(QString caption) { return browseOpenFolder(caption);}


void log(QString msg);

private:
Expand Down
Loading