History

Keep old function names for compatibility

vladest committed 9 years ago

Commit 15f8bc01 parent 4e5c6506 files · +121 −17Browse files

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

Unified · Split

interface/src/scripting/WindowScriptingInterface.cpp+104−5
@@ -116,7 +116,17 @@ QScriptValue WindowScriptingInterface::confirm(const QString& message) { · 115 unmodified lines
116116 /// Display a prompt with a text box
117117 /// \param const QString& message message to display
118118 /// \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) {
120130 auto offscreenUi = DependencyManager::get<OffscreenUi>();
121131 connect(offscreenUi.data(), &OffscreenUi::inputDialogResponse,
122132 this, [=] (QVariant result) {
@@ -180,7 +190,29 @@ void WindowScriptingInterface::ensureReticleVisible() const { · 57 unmodified lines
180190 /// \param const QString& title title of the window
181191 /// \param const QString& directory directory to start the file browser at
182192 /// \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) {
184216 ensureReticleVisible();
185217 QString path = directory;
186218 if (path.isEmpty()) {
@@ -204,12 +236,32 @@ void WindowScriptingInterface::browseDir(const QString& title, const QString& di · 17 unmodified lines
204236 OffscreenUi::getExistingDirectoryAsync(nullptr, title, path);
205237 }
206238
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+
207259 /// Display an open file dialog. If `directory` is an invalid file or directory the browser will start at the current
208260 /// working directory.
209261 /// \param const QString& title title of the window
210262 /// \param const QString& directory directory to start the file browser at
211263 /// \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) {
213265 ensureReticleVisible();
214266 QString path = directory;
215267 if (path.isEmpty()) {
@@ -238,7 +290,29 @@ void WindowScriptingInterface::browse(const QString& title, const QString& direc · 22 unmodified lines
238290 /// \param const QString& title title of the window
239291 /// \param const QString& directory directory to start the file browser at
240292 /// \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) {
242316 ensureReticleVisible();
243317 QString path = directory;
244318 if (path.isEmpty()) {
@@ -262,12 +336,37 @@ void WindowScriptingInterface::save(const QString& title, const QString& directo · 17 unmodified lines
262336 OffscreenUi::getSaveFileNameAsync(nullptr, title, path, nameFilter);
263337 }
264338
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+
265364 /// Display a select asset dialog that lets the user select an asset from the Asset Server. If `directory` is an invalid
266365 /// directory the browser will start at the root directory.
267366 /// \param const QString& title title of the window
268367 /// \param const QString& directory directory to start the asset browser at
269368 /// \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) {
271370 ensureReticleVisible();
272371 QString path = directory;
273372 if (path.isEmpty()) {