Showing the changes to interface/src/scripting/WindowScriptingInterface.cpp (1 of 3 files). Show all
Unified · Split
| @@ -174,8 +174,7 @@ void WindowScriptingInterface::ensureReticleVisible() const { · 173 unmodified lines | ||
| 174 | 174 | /// \param const QString& title title of the window |
| 175 | 175 | /// \param const QString& directory directory to start the file browser at |
| 176 | 176 | /// \param const QString& nameFilter filter to filter filenames by - see `QFileDialog` |
| 177 | −/// \return QScriptValue file path as a string if one was selected, otherwise `QScriptValue::NullValue` | |
| 178 | −QScriptValue WindowScriptingInterface::browseDir(const QString& title, const QString& directory) { | |
| 177 | +void WindowScriptingInterface::browseDir(const QString& title, const QString& directory) { | |
| 179 | 178 | ensureReticleVisible(); |
| 180 | 179 | QString path = directory; |
| 181 | 180 | if (path.isEmpty()) { |
| @@ -184,11 +183,19 @@ QScriptValue WindowScriptingInterface::browseDir(const QString& title, const QSt · 2 unmodified lines | ||
| 184 | 183 | #ifndef Q_OS_WIN |
| 185 | 184 | path = fixupPathForMac(directory); |
| 186 | 185 | #endif |
| 187 | − QString result = OffscreenUi::getExistingDirectory(nullptr, title, path); | |
| 188 | − if (!result.isEmpty()) { | |
| 189 | − setPreviousBrowseLocation(QFileInfo(result).absolutePath()); | |
| 190 | − } | |
| 191 | − return result.isEmpty() ? QScriptValue::NullValue : QScriptValue(result); | |
| 186 | + auto offscreenUi = DependencyManager::get<OffscreenUi>(); | |
| 187 | + connect(offscreenUi.data(), &OffscreenUi::fileDialogResponse, | |
| 188 | + this, [=] (QString result) { | |
| 189 | + auto offscreenUi = DependencyManager::get<OffscreenUi>(); | |
| 190 | + disconnect(offscreenUi.data(), &OffscreenUi::fileDialogResponse, | |
| 191 | + this, nullptr); | |
| 192 | + if (!result.isEmpty()) { | |
| 193 | + setPreviousBrowseLocation(QFileInfo(result).absolutePath()); | |
| 194 | + } | |
| 195 | + emit browseDirChanged(result); | |
| 196 | + }); | |
| 197 | + | |
| 198 | + OffscreenUi::getExistingDirectoryAsync(nullptr, title, path); | |
| 192 | 199 | } |
| 193 | 200 | |
| 194 | 201 | /// Display an open file dialog. If `directory` is an invalid file or directory the browser will start at the current |