History

Stub desktop dialog to select recording to play from ATP assets

David Rowe committed 9 years ago

Commit dae6d6f1 parent f9201929 files · +291 −2Browse files

Showing the changes to interface/src/scripting/WindowScriptingInterface.cpp (1 of 9 files). Show all

Unified · Split

interface/src/scripting/WindowScriptingInterface.cpp+29−0
@@ -28,6 +28,7 @@ · 27 unmodified lines
2828
2929 static const QString DESKTOP_LOCATION = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
3030 static const QString LAST_BROWSE_LOCATION_SETTING = "LastBrowseLocation";
31+static const QString LAST_BROWSE_ASSETS_LOCATION_SETTING = "LastBrowseAssetsLocation";
3132
3233
3334 QScriptValue CustomPromptResultToScriptValue(QScriptEngine* engine, const CustomPromptResult& result) {
@@ -149,6 +150,15 @@ void WindowScriptingInterface::setPreviousBrowseLocation(const QString& location · 115 unmodified lines
149150 Setting::Handle<QVariant>(LAST_BROWSE_LOCATION_SETTING).set(location);
150151 }
151152
153+QString WindowScriptingInterface::getPreviousBrowseAssetLocation() const {
154+ QString ASSETS_ROOT_PATH = "/";
155+ return Setting::Handle<QString>(LAST_BROWSE_ASSETS_LOCATION_SETTING, ASSETS_ROOT_PATH).get();
156+}
157+
158+void WindowScriptingInterface::setPreviousBrowseAssetLocation(const QString& location) {
159+ Setting::Handle<QVariant>(LAST_BROWSE_ASSETS_LOCATION_SETTING).set(location);
160+}
161+
152162 /// Makes sure that the reticle is visible, use this in blocking forms that require a reticle and
153163 /// might be in same thread as a script that sets the reticle to invisible
154164 void WindowScriptingInterface::ensureReticleVisible() const {
@@ -202,6 +212,25 @@ QScriptValue WindowScriptingInterface::save(const QString& title, const QString& · 47 unmodified lines
202212 return result.isEmpty() ? QScriptValue::NullValue : QScriptValue(result);
203213 }
204214
215+/// Display a select asset dialog that lets the user select an asset from the Asset Server. If `directory` is an invalid
216+/// directory the browser will start at the root directory.
217+/// \param const QString& title title of the window
218+/// \param const QString& directory directory to start the asset browser at
219+/// \param const QString& nameFilter filter to filter asset names by - see `QFileDialog`
220+/// \return QScriptValue asset path as a string if one was selected, otherwise `QScriptValue::NullValue`
221+QScriptValue WindowScriptingInterface::browseAssets(const QString& title, const QString& directory, const QString& nameFilter) {
222+ ensureReticleVisible();
223+ QString path = directory;
224+ if (path.isEmpty()) {
225+ path = getPreviousBrowseAssetLocation();
226+ }
227+ QString result = OffscreenUi::getOpenAssetName(nullptr, title, path, nameFilter);
228+ if (!result.isEmpty()) {
229+ setPreviousBrowseAssetLocation(QFileInfo(result).absolutePath());
230+ }
231+ return result.isEmpty() ? QScriptValue::NullValue : QScriptValue(result);
232+}
233+
205234 void WindowScriptingInterface::showAssetServer(const QString& upload) {
206235 QMetaObject::invokeMethod(qApp, "showAssetServerWidget", Qt::QueuedConnection, Q_ARG(QString, upload));
207236 }