Showing the changes to interface/src/scripting/WindowScriptingInterface.cpp (1 of 5 files). Show all
Unified · Split
| @@ -168,6 +168,28 @@ void WindowScriptingInterface::ensureReticleVisible() const { · 167 unmodified lines | |||
| 168 | } | 168 | } |
| 169 | } | 169 | } |
| 170 | 170 | ||
| 171 | /// Display a "browse to directory" dialog. If `directory` is an invalid file or directory the browser will start at the current | ||
| 172 | /// working directory. | ||
| 173 | /// \param const QString& title title of the window | ||
| 174 | /// \param const QString& directory directory to start the file browser at | ||
| 175 | /// \param const QString& nameFilter filter to filter filenames by - see `QFileDialog` | ||
| 176 | /// \return QScriptValue file path as a string if one was selected, otherwise `QScriptValue::NullValue` | ||
| 177 | QScriptValue WindowScriptingInterface::browseDir(const QString& title, const QString& directory) { | ||
| 178 | ensureReticleVisible(); | ||
| 179 | QString path = directory; | ||
| 180 | if (path.isEmpty()) { | ||
| 181 | path = getPreviousBrowseLocation(); | ||
| 182 | } | ||
| 183 | #ifndef Q_OS_WIN | ||
| 184 | path = fixupPathForMac(directory); | ||
| 185 | #endif | ||
| 186 | QString result = OffscreenUi::getExistingDirectory(nullptr, title, path); | ||
| 187 | if (!result.isEmpty()) { | ||
| 188 | setPreviousBrowseLocation(QFileInfo(result).absolutePath()); | ||
| 189 | } | ||
| 190 | return result.isEmpty() ? QScriptValue::NullValue : QScriptValue(result); | ||
| 191 | } | ||
| 192 | |||
| 171 | /// Display an open file dialog. If `directory` is an invalid file or directory the browser will start at the current | 193 | /// Display an open file dialog. If `directory` is an invalid file or directory the browser will start at the current |
| 172 | /// working directory. | 194 | /// working directory. |
| 173 | /// \param const QString& title title of the window | 195 | /// \param const QString& title title of the window |