Showing the changes to interface/src/scripting/WindowScriptingInterface.cpp (1 of 6 files). Show all
Unified · Split
| @@ -116,7 +116,17 @@ QScriptValue WindowScriptingInterface::confirm(const QString& message) { · 115 unmodified lines | ||
| 116 | 116 | /// Display a prompt with a text box |
| 117 | 117 | /// \param const QString& message message to display |
| 118 | 118 | /// \param const QString& defaultText default text in the text box |
| 119 | −void WindowScriptingInterface::prompt(const QString& message, const QString& defaultText) { | |
| 119 | +/// \return QScriptValue string text value in text box if the dialog was accepted, `null` otherwise. | |
| 120 | +QScriptValue WindowScriptingInterface::prompt(const QString& message, const QString& defaultText) { | |
| 121 | + bool ok = false; | |
| 122 | + QString result = OffscreenUi::getText(nullptr, "", message, QLineEdit::Normal, defaultText, &ok); | |
| 123 | + return ok ? QScriptValue(result) : QScriptValue::NullValue; | |
| 124 | +} | |
| 125 | + | |
| 126 | +/// Display a prompt with a text box | |
| 127 | +/// \param const QString& message message to display | |
| 128 | +/// \param const QString& defaultText default text in the text box | |
| 129 | +void WindowScriptingInterface::promptAsync(const QString& message, const QString& defaultText) { | |
| 120 | 130 | auto offscreenUi = DependencyManager::get<OffscreenUi>(); |
| 121 | 131 | connect(offscreenUi.data(), &OffscreenUi::inputDialogResponse, |
| 122 | 132 | this, [=] (QVariant result) { |
| @@ -180,7 +190,29 @@ void WindowScriptingInterface::ensureReticleVisible() const { · 57 unmodified lines | ||
| 180 | 190 | /// \param const QString& title title of the window |
| 181 | 191 | /// \param const QString& directory directory to start the file browser at |
| 182 | 192 | /// \param const QString& nameFilter filter to filter filenames by - see `QFileDialog` |
| 183 | −void WindowScriptingInterface::browseDir(const QString& title, const QString& directory) { | |
| 193 | +/// \return QScriptValue file path as a string if one was selected, otherwise `QScriptValue::NullValue` | |
| 194 | +QScriptValue WindowScriptingInterface::browseDir(const QString& title, const QString& directory) { | |
| 195 | + ensureReticleVisible(); | |
| 196 | + QString path = directory; | |
| 197 | + if (path.isEmpty()) { | |
| 198 | + path = getPreviousBrowseLocation(); | |
| 199 | + } | |
| 200 | +#ifndef Q_OS_WIN | |
| 201 | + path = fixupPathForMac(directory); | |
| 202 | +#endif | |
| 203 | + QString result = OffscreenUi::getExistingDirectory(nullptr, title, path); | |
| 204 | + if (!result.isEmpty()) { | |
| 205 | + setPreviousBrowseLocation(QFileInfo(result).absolutePath()); | |
| 206 | + } | |
| 207 | + return result.isEmpty() ? QScriptValue::NullValue : QScriptValue(result); | |
| 208 | +} | |
| 209 | + | |
| 210 | +/// Display a "browse to directory" dialog. If `directory` is an invalid file or directory the browser will start at the current | |
| 211 | +/// working directory. | |
| 212 | +/// \param const QString& title title of the window | |
| 213 | +/// \param const QString& directory directory to start the file browser at | |
| 214 | +/// \param const QString& nameFilter filter to filter filenames by - see `QFileDialog` | |
| 215 | +void WindowScriptingInterface::browseDirAsync(const QString& title, const QString& directory) { | |
| 184 | 216 | ensureReticleVisible(); |
| 185 | 217 | QString path = directory; |
| 186 | 218 | if (path.isEmpty()) { |
| @@ -204,12 +236,32 @@ void WindowScriptingInterface::browseDir(const QString& title, const QString& di · 17 unmodified lines | ||
| 204 | 236 | OffscreenUi::getExistingDirectoryAsync(nullptr, title, path); |
| 205 | 237 | } |
| 206 | 238 | |
| 239 | +/// \param const QString& title title of the window | |
| 240 | +/// \param const QString& directory directory to start the file browser at | |
| 241 | +/// \param const QString& nameFilter filter to filter filenames by - see `QFileDialog` | |
| 242 | +/// \return QScriptValue file path as a string if one was selected, otherwise `QScriptValue::NullValue` | |
| 243 | +QScriptValue WindowScriptingInterface::browse(const QString& title, const QString& directory, const QString& nameFilter) { | |
| 244 | + ensureReticleVisible(); | |
| 245 | + QString path = directory; | |
| 246 | + if (path.isEmpty()) { | |
| 247 | + path = getPreviousBrowseLocation(); | |
| 248 | + } | |
| 249 | +#ifndef Q_OS_WIN | |
| 250 | + path = fixupPathForMac(directory); | |
| 251 | +#endif | |
| 252 | + QString result = OffscreenUi::getOpenFileName(nullptr, title, path, nameFilter); | |
| 253 | + if (!result.isEmpty()) { | |
| 254 | + setPreviousBrowseLocation(QFileInfo(result).absolutePath()); | |
| 255 | + } | |
| 256 | + return result.isEmpty() ? QScriptValue::NullValue : QScriptValue(result); | |
| 257 | +} | |
| 258 | + | |
| 207 | 259 | /// Display an open file dialog. If `directory` is an invalid file or directory the browser will start at the current |
| 208 | 260 | /// working directory. |
| 209 | 261 | /// \param const QString& title title of the window |
| 210 | 262 | /// \param const QString& directory directory to start the file browser at |
| 211 | 263 | /// \param const QString& nameFilter filter to filter filenames by - see `QFileDialog` |
| 212 | −void WindowScriptingInterface::browse(const QString& title, const QString& directory, const QString& nameFilter) { | |
| 264 | +void WindowScriptingInterface::browseAsync(const QString& title, const QString& directory, const QString& nameFilter) { | |
| 213 | 265 | ensureReticleVisible(); |
| 214 | 266 | QString path = directory; |
| 215 | 267 | if (path.isEmpty()) { |
| @@ -238,7 +290,29 @@ void WindowScriptingInterface::browse(const QString& title, const QString& direc · 22 unmodified lines | ||
| 238 | 290 | /// \param const QString& title title of the window |
| 239 | 291 | /// \param const QString& directory directory to start the file browser at |
| 240 | 292 | /// \param const QString& nameFilter filter to filter filenames by - see `QFileDialog` |
| 241 | −void WindowScriptingInterface::save(const QString& title, const QString& directory, const QString& nameFilter) { | |
| 293 | +/// \return QScriptValue file path as a string if one was selected, otherwise `QScriptValue::NullValue` | |
| 294 | +QScriptValue WindowScriptingInterface::save(const QString& title, const QString& directory, const QString& nameFilter) { | |
| 295 | + ensureReticleVisible(); | |
| 296 | + QString path = directory; | |
| 297 | + if (path.isEmpty()) { | |
| 298 | + path = getPreviousBrowseLocation(); | |
| 299 | + } | |
| 300 | +#ifndef Q_OS_WIN | |
| 301 | + path = fixupPathForMac(directory); | |
| 302 | +#endif | |
| 303 | + QString result = OffscreenUi::getSaveFileName(nullptr, title, path, nameFilter); | |
| 304 | + if (!result.isEmpty()) { | |
| 305 | + setPreviousBrowseLocation(QFileInfo(result).absolutePath()); | |
| 306 | + } | |
| 307 | + return result.isEmpty() ? QScriptValue::NullValue : QScriptValue(result); | |
| 308 | +} | |
| 309 | + | |
| 310 | +/// Display a save file dialog. If `directory` is an invalid file or directory the browser will start at the current | |
| 311 | +/// working directory. | |
| 312 | +/// \param const QString& title title of the window | |
| 313 | +/// \param const QString& directory directory to start the file browser at | |
| 314 | +/// \param const QString& nameFilter filter to filter filenames by - see `QFileDialog` | |
| 315 | +void WindowScriptingInterface::saveAsync(const QString& title, const QString& directory, const QString& nameFilter) { | |
| 242 | 316 | ensureReticleVisible(); |
| 243 | 317 | QString path = directory; |
| 244 | 318 | if (path.isEmpty()) { |
| @@ -262,12 +336,37 @@ void WindowScriptingInterface::save(const QString& title, const QString& directo · 17 unmodified lines | ||
| 262 | 336 | OffscreenUi::getSaveFileNameAsync(nullptr, title, path, nameFilter); |
| 263 | 337 | } |
| 264 | 338 | |
| 339 | +/// Display a select asset dialog that lets the user select an asset from the Asset Server. If `directory` is an invalid | |
| 340 | +/// directory the browser will start at the root directory. | |
| 341 | +/// \param const QString& title title of the window | |
| 342 | +/// \param const QString& directory directory to start the asset browser at | |
| 343 | +/// \param const QString& nameFilter filter to filter asset names by - see `QFileDialog` | |
| 344 | +/// \return QScriptValue asset path as a string if one was selected, otherwise `QScriptValue::NullValue` | |
| 345 | +QScriptValue WindowScriptingInterface::browseAssets(const QString& title, const QString& directory, const QString& nameFilter) { | |
| 346 | + ensureReticleVisible(); | |
| 347 | + QString path = directory; | |
| 348 | + if (path.isEmpty()) { | |
| 349 | + path = getPreviousBrowseAssetLocation(); | |
| 350 | + } | |
| 351 | + if (path.left(1) != "/") { | |
| 352 | + path = "/" + path; | |
| 353 | + } | |
| 354 | + if (path.right(1) != "/") { | |
| 355 | + path = path + "/"; | |
| 356 | + } | |
| 357 | + QString result = OffscreenUi::getOpenAssetName(nullptr, title, path, nameFilter); | |
| 358 | + if (!result.isEmpty()) { | |
| 359 | + setPreviousBrowseAssetLocation(QFileInfo(result).absolutePath()); | |
| 360 | + } | |
| 361 | + return result.isEmpty() ? QScriptValue::NullValue : QScriptValue(result); | |
| 362 | +} | |
| 363 | + | |
| 265 | 364 | /// Display a select asset dialog that lets the user select an asset from the Asset Server. If `directory` is an invalid |
| 266 | 365 | /// directory the browser will start at the root directory. |
| 267 | 366 | /// \param const QString& title title of the window |
| 268 | 367 | /// \param const QString& directory directory to start the asset browser at |
| 269 | 368 | /// \param const QString& nameFilter filter to filter asset names by - see `QFileDialog` |
| 270 | −void WindowScriptingInterface::browseAssets(const QString& title, const QString& directory, const QString& nameFilter) { | |
| 369 | +void WindowScriptingInterface::browseAssetsAsync(const QString& title, const QString& directory, const QString& nameFilter) { | |
| 271 | 370 | ensureReticleVisible(); |
| 272 | 371 | QString path = directory; |
| 273 | 372 | if (path.isEmpty()) { |