History

Reworked WindowScriptingInterface browse method for async methods

vladest committed 9 years ago

Commit 273261e1 parent 8afdb273 files · +42 −32Browse files

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

Unified · Split

interface/src/scripting/WindowScriptingInterface.cpp+14−7
@@ -203,8 +203,7 @@ void WindowScriptingInterface::browseDir(const QString& title, const QString& di · 202 unmodified lines
203/// \param const QString& title title of the window203/// \param const QString& title title of the window
204/// \param const QString& directory directory to start the file browser at204/// \param const QString& directory directory to start the file browser at
205/// \param const QString& nameFilter filter to filter filenames by - see `QFileDialog`205/// \param const QString& nameFilter filter to filter filenames by - see `QFileDialog`
206/// \return QScriptValue file path as a string if one was selected, otherwise `QScriptValue::NullValue`206void WindowScriptingInterface::browse(const QString& title, const QString& directory, const QString& nameFilter) {
207QScriptValue WindowScriptingInterface::browse(const QString& title, const QString& directory, const QString& nameFilter) {
208 ensureReticleVisible();207 ensureReticleVisible();
209 QString path = directory;208 QString path = directory;
210 if (path.isEmpty()) {209 if (path.isEmpty()) {
@@ -213,11 +212,19 @@ QScriptValue WindowScriptingInterface::browse(const QString& title, const QStrin · 2 unmodified lines
213#ifndef Q_OS_WIN212#ifndef Q_OS_WIN
214 path = fixupPathForMac(directory);213 path = fixupPathForMac(directory);
215#endif214#endif
216 QString result = OffscreenUi::getOpenFileName(nullptr, title, path, nameFilter);215 auto offscreenUi = DependencyManager::get<OffscreenUi>();
217 if (!result.isEmpty()) {216 connect(offscreenUi.data(), &OffscreenUi::fileDialogResponse,
218 setPreviousBrowseLocation(QFileInfo(result).absolutePath());217 this, [=] (QString result) {
219 }218 auto offscreenUi = DependencyManager::get<OffscreenUi>();
220 return result.isEmpty() ? QScriptValue::NullValue : QScriptValue(result);219 disconnect(offscreenUi.data(), &OffscreenUi::fileDialogResponse,
220 this, nullptr);
221 if (!result.isEmpty()) {
222 setPreviousBrowseLocation(QFileInfo(result).absolutePath());
223 }
224 emit openFileChanged(result);
225 });
226
227 OffscreenUi::getOpenFileNameAsync(nullptr, title, path, nameFilter);
221}228}
222 229
223/// Display a save file dialog. If `directory` is an invalid file or directory the browser will start at the current230/// Display a save file dialog. If `directory` is an invalid file or directory the browser will start at the current