Skip to content
Closed
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
78 changes: 78 additions & 0 deletions src/Plugins/Qt/qt_chooser_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,14 +197,91 @@ qt_chooser_widget_rep::set_type (const string& _type)
return true;
}

/*!
* WASM build freezes when calling QDialog::exec(), so instead to use QDialog::open()
*/
void
qt_chooser_widget_rep::open_dialog (){
QString caption = to_qstring (win_title);
c_string tmp (directory * "/" * file);
QString path = QString::fromUtf8 (tmp, -1);
QTMFileDialog* dialog;
QTMImageDialog* imgdialog = 0; // to avoid a dynamic_cast

if (type == "image")
dialog = imgdialog = new QTMImageDialog (NULL, caption, path);
else
dialog = new QTMFileDialog (NULL, caption, path);
dialog->setViewMode (QFileDialog::Detail);
if (type == "directory")
dialog->setFileMode (QFileDialog::Directory);
else if (type == "image" && prompt == "")
// check non saving mode just in case we support it
dialog->setFileMode (QFileDialog::ExistingFile);
else
dialog->setFileMode (QFileDialog::AnyFile);
if (prompt != "") {
string text= prompt;
if (ends (text, ":")) text= text (0, N(text) - 1);
if (ends (text, " as")) text= text (0, N(text) - 3);
dialog->setDefaultSuffix (defaultSuffix);
dialog->setAcceptMode (QFileDialog::AcceptSave);
dialog->setLabelText (QFileDialog::Accept, to_qstring (translate (text)));
}

if (type != "directory") {
QStringList filters;
if (nameFilter != "")
filters << nameFilter;
filters << to_qstring (translate ("All files (*)"));
dialog->setNameFilters (filters);
}

dialog->updateGeometry();
QSize sz = dialog->sizeHint();
QPoint pos = to_qpoint (position);
QRect r;

r.setSize (sz);
r.moveCenter (pos);
dialog->setGeometry (r);

file = "#f";
dialog->open();
QObject::connect(
dialog, &QDialog::finished,
[dialog, imgdialog, this]( int result ) {
if ( result ) {
QStringList fileNames = dialog->selectedFiles();
if (fileNames.count() > 0) {
QString imqstring = fileNames.first();
// QTBUG-59401: QFileDialog::setDefaultSuffix doesn't work when file path contains a dot
if (!defaultSuffix.isEmpty() && imqstring.contains(QLatin1Char('/'))
&& !imqstring.endsWith(QLatin1Char('/'))
&& imqstring.indexOf(QLatin1Char('.'), imqstring.lastIndexOf(QLatin1Char('/'))) == -1) {
imqstring = imqstring + QLatin1Char('.') + defaultSuffix;
}
string imname = from_qstring_utf8 (imqstring);
file = "(system->url " * scm_quote (imname) * ")";
if (type == "image") {
file = "(list " * file * imgdialog->getParamsAsString () * ")"; //set image size from preview
}
dialog->deleteLater();
cmd ();
if (!is_nil (quit)) quit ();
}}}
);
}

/*! Actually displays the dialog with all the options set.
* Uses a native dialog on Mac/Win and opens a custom dialog with image preview
* for other platforms.
*/
void
qt_chooser_widget_rep::perform_dialog () {
#if (defined(OS_WASM))
open_dialog();
#else
QString caption = to_qstring (win_title);
c_string tmp (directory * "/" * file);
QString path = QString::fromUtf8 (tmp, -1);
Expand Down Expand Up @@ -321,4 +398,5 @@ qt_chooser_widget_rep::perform_dialog () {

cmd ();
if (!is_nil (quit)) quit ();
#endif
}
1 change: 1 addition & 0 deletions src/Plugins/Qt/qt_chooser_widget.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class qt_chooser_widget_rep: public qt_widget_rep {

QString nameFilter; //!< For use in QFileDialog::setNameFilter()
QString defaultSuffix; //!< For use in QFileDialog::setDefaultSuffix()
void open_dialog();

public:
qt_chooser_widget_rep (command, string, string);
Expand Down
8 changes: 8 additions & 0 deletions src/Plugins/Qt/qt_tm_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,15 @@ replaceActions (QWidget* dest, QList<QAction*>* src) {
}
for (int i = 0; i < src->count(); i++) {
QAction* a = (*src)[i];
#if (defined(OS_WASM))
if(! a->menu()){
//QToolButton::showMenu() cause WASM to freeze, so we don't show those buttons until QT fixes this problem
//A walkaround is to subclass QToolButton and override showMenu to use popup() instead of exec()
dest->addAction(a);
}
#else
dest->addAction(a);
#endif
}
dest->setUpdatesEnabled (true);
}
Expand Down