Showing the changes to interface/src/scripting/WindowScriptingInterface.cpp (1 of 3 files). Show all
Unified · Split
| @@ -203,8 +203,7 @@ void WindowScriptingInterface::browseDir(const QString& title, const QString& di · 202 unmodified lines | ||
| 203 | 203 | /// \param const QString& title title of the window |
| 204 | 204 | /// \param const QString& directory directory to start the file browser at |
| 205 | 205 | /// \param const QString& nameFilter filter to filter filenames by - see `QFileDialog` |
| 206 | −/// \return QScriptValue file path as a string if one was selected, otherwise `QScriptValue::NullValue` | |
| 207 | −QScriptValue WindowScriptingInterface::browse(const QString& title, const QString& directory, const QString& nameFilter) { | |
| 206 | +void WindowScriptingInterface::browse(const QString& title, const QString& directory, const QString& nameFilter) { | |
| 208 | 207 | ensureReticleVisible(); |
| 209 | 208 | QString path = directory; |
| 210 | 209 | if (path.isEmpty()) { |
| @@ -213,11 +212,19 @@ QScriptValue WindowScriptingInterface::browse(const QString& title, const QStrin · 2 unmodified lines | ||
| 213 | 212 | #ifndef Q_OS_WIN |
| 214 | 213 | path = fixupPathForMac(directory); |
| 215 | 214 | #endif |
| 216 | − QString result = OffscreenUi::getOpenFileName(nullptr, title, path, nameFilter); | |
| 217 | − if (!result.isEmpty()) { | |
| 218 | − setPreviousBrowseLocation(QFileInfo(result).absolutePath()); | |
| 219 | − } | |
| 220 | − return result.isEmpty() ? QScriptValue::NullValue : QScriptValue(result); | |
| 215 | + auto offscreenUi = DependencyManager::get<OffscreenUi>(); | |
| 216 | + connect(offscreenUi.data(), &OffscreenUi::fileDialogResponse, | |
| 217 | + this, [=] (QString result) { | |
| 218 | + auto offscreenUi = DependencyManager::get<OffscreenUi>(); | |
| 219 | + disconnect(offscreenUi.data(), &OffscreenUi::fileDialogResponse, | |
| 220 | + this, nullptr); | |
| 221 | + if (!result.isEmpty()) { | |
| 222 | + setPreviousBrowseLocation(QFileInfo(result).absolutePath()); | |
| 223 | + } | |
| 224 | + emit openFileChanged(result); | |
| 225 | + }); | |
| 226 | + | |
| 227 | + OffscreenUi::getOpenFileNameAsync(nullptr, title, path, nameFilter); | |
| 221 | 228 | } |
| 222 | 229 | |
| 223 | 230 | /// Display a save file dialog. If `directory` is an invalid file or directory the browser will start at the current |