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 | /// \param const QString& title title of the window | 174 | /// \param const QString& title title of the window |
| 175 | /// \param const QString& directory directory to start the file browser at | 175 | /// \param const QString& directory directory to start the file browser at |
| 176 | /// \param const QString& nameFilter filter to filter filenames by - see `QFileDialog` | 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` | 177 | void WindowScriptingInterface::browseDir(const QString& title, const QString& directory) { |
| 178 | QScriptValue WindowScriptingInterface::browseDir(const QString& title, const QString& directory) { | ||
| 179 | ensureReticleVisible(); | 178 | ensureReticleVisible(); |
| 180 | QString path = directory; | 179 | QString path = directory; |
| 181 | if (path.isEmpty()) { | 180 | if (path.isEmpty()) { |
| @@ -184,11 +183,19 @@ QScriptValue WindowScriptingInterface::browseDir(const QString& title, const QSt · 2 unmodified lines | |||
| 184 | #ifndef Q_OS_WIN | 183 | #ifndef Q_OS_WIN |
| 185 | path = fixupPathForMac(directory); | 184 | path = fixupPathForMac(directory); |
| 186 | #endif | 185 | #endif |
| 187 | QString result = OffscreenUi::getExistingDirectory(nullptr, title, path); | 186 | auto offscreenUi = DependencyManager::get<OffscreenUi>(); |
| 188 | if (!result.isEmpty()) { | 187 | connect(offscreenUi.data(), &OffscreenUi::fileDialogResponse, |
| 189 | setPreviousBrowseLocation(QFileInfo(result).absolutePath()); | 188 | this, [=] (QString result) { |
| 190 | } | 189 | auto offscreenUi = DependencyManager::get<OffscreenUi>(); |
| 191 | return result.isEmpty() ? QScriptValue::NullValue : QScriptValue(result); | 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 | /// Display an open file dialog. If `directory` is an invalid file or directory the browser will start at the current | 201 | /// Display an open file dialog. If `directory` is an invalid file or directory the browser will start at the current |