History

Rework all c++ calls

vladest committed 9 years ago

Commit 3ceeb0d1 parent 5b033e07 files · +257 −255Browse files

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

Unified · Split

interface/src/scripting/WindowScriptingInterface.cpp+22−37
@@ -127,16 +127,13 @@ QScriptValue WindowScriptingInterface::prompt(const QString& message, const QStr · 126 unmodified lines
127127 /// \param const QString& message message to display
128128 /// \param const QString& defaultText default text in the text box
129129 void WindowScriptingInterface::promptAsync(const QString& message, const QString& defaultText) {
130− auto offscreenUi = DependencyManager::get<OffscreenUi>();
131− connect(offscreenUi.data(), &OffscreenUi::inputDialogResponse,
132− this, [=] (QVariant result) {
133− auto offscreenUi = DependencyManager::get<OffscreenUi>();
134− disconnect(offscreenUi.data(), &OffscreenUi::inputDialogResponse,
135− this, nullptr);
130+ ModalDialogListener* dlg = OffscreenUi::getTextAsync(nullptr, "", message, QLineEdit::Normal, defaultText);
131+ connect(dlg, &ModalDialogListener::response, this, [=] (QVariant result) {
132+ disconnect(dlg, &ModalDialogListener::response, this, nullptr);
136133 emit promptTextChanged(result.toString());
137134 });
138135
139− OffscreenUi::getTextAsync(nullptr, "", message, QLineEdit::Normal, defaultText);
136+
140137 }
141138
142139 CustomPromptResult WindowScriptingInterface::customPrompt(const QVariant& config) {
@@ -221,19 +218,15 @@ void WindowScriptingInterface::browseDirAsync(const QString& title, const QStrin · 78 unmodified lines
221218 #ifndef Q_OS_WIN
222219 path = fixupPathForMac(directory);
223220 #endif
224− auto offscreenUi = DependencyManager::get<OffscreenUi>();
225− connect(offscreenUi.data(), &OffscreenUi::fileDialogResponse,
226− this, [=] (QString result) {
227− auto offscreenUi = DependencyManager::get<OffscreenUi>();
228− disconnect(offscreenUi.data(), &OffscreenUi::fileDialogResponse,
229− this, nullptr);
221+ ModalDialogListener* dlg = OffscreenUi::getExistingDirectoryAsync(nullptr, title, path);
222+ connect(dlg, &ModalDialogListener::response, this, [=] (QVariant response) {
223+ const QString& result = response.toString();
224+ disconnect(dlg, &ModalDialogListener::response, this, nullptr);
230225 if (!result.isEmpty()) {
231226 setPreviousBrowseLocation(QFileInfo(result).absolutePath());
232227 }
233228 emit browseDirChanged(result);
234229 });
235−
236− OffscreenUi::getExistingDirectoryAsync(nullptr, title, path);
237230 }
238231
239232 /// \param const QString& title title of the window
@@ -270,19 +263,17 @@ void WindowScriptingInterface::browseAsync(const QString& title, const QString& · 30 unmodified lines
270263 #ifndef Q_OS_WIN
271264 path = fixupPathForMac(directory);
272265 #endif
273− auto offscreenUi = DependencyManager::get<OffscreenUi>();
274− connect(offscreenUi.data(), &OffscreenUi::fileDialogResponse,
275− this, [=] (QString result) {
276− auto offscreenUi = DependencyManager::get<OffscreenUi>();
277− disconnect(offscreenUi.data(), &OffscreenUi::fileDialogResponse,
278− this, nullptr);
266+ ModalDialogListener* dlg = OffscreenUi::getOpenFileNameAsync(nullptr, title, path, nameFilter);
267+ connect(dlg, &ModalDialogListener::response, this, [=] (QVariant response) {
268+ const QString& result = response.toString();
269+ disconnect(dlg, &ModalDialogListener::response, this, nullptr);
279270 if (!result.isEmpty()) {
280271 setPreviousBrowseLocation(QFileInfo(result).absolutePath());
281272 }
282273 emit openFileChanged(result);
283274 });
284275
285− OffscreenUi::getOpenFileNameAsync(nullptr, title, path, nameFilter);
276+
286277 }
287278
288279 /// Display a save file dialog. If `directory` is an invalid file or directory the browser will start at the current
@@ -321,19 +312,17 @@ void WindowScriptingInterface::saveAsync(const QString& title, const QString& di · 32 unmodified lines
321312 #ifndef Q_OS_WIN
322313 path = fixupPathForMac(directory);
323314 #endif
324− auto offscreenUi = DependencyManager::get<OffscreenUi>();
325− connect(offscreenUi.data(), &OffscreenUi::fileDialogResponse,
326− this, [=] (QString result) {
327− auto offscreenUi = DependencyManager::get<OffscreenUi>();
328− disconnect(offscreenUi.data(), &OffscreenUi::fileDialogResponse,
329− this, nullptr);
315+ ModalDialogListener* dlg = OffscreenUi::getSaveFileNameAsync(nullptr, title, path, nameFilter);
316+ connect(dlg, &ModalDialogListener::response, this, [=] (QVariant response) {
317+ const QString& result = response.toString();
318+ disconnect(dlg, &ModalDialogListener::response, this, nullptr);
330319 if (!result.isEmpty()) {
331320 setPreviousBrowseLocation(QFileInfo(result).absolutePath());
332321 }
333322 emit saveFileChanged(result);
334323 });
335324
336− OffscreenUi::getSaveFileNameAsync(nullptr, title, path, nameFilter);
325+
337326 }
338327
339328 /// Display a select asset dialog that lets the user select an asset from the Asset Server. If `directory` is an invalid
@@ -379,19 +368,15 @@ void WindowScriptingInterface::browseAssetsAsync(const QString& title, const QSt · 39 unmodified lines
379368 path = path + "/";
380369 }
381370
382− auto offscreenUi = DependencyManager::get<OffscreenUi>();
383− connect(offscreenUi.data(), &OffscreenUi::assetDialogResponse,
384− this, [=] (QString result) {
385− auto offscreenUi = DependencyManager::get<OffscreenUi>();
386− disconnect(offscreenUi.data(), &OffscreenUi::assetDialogResponse,
387− this, nullptr);
371+ ModalDialogListener* dlg = OffscreenUi::getOpenAssetNameAsync(nullptr, title, path, nameFilter);
372+ connect(dlg, &ModalDialogListener::response, this, [=] (QVariant response) {
373+ const QString& result = response.toString();
374+ disconnect(dlg, &ModalDialogListener::response, this, nullptr);
388375 if (!result.isEmpty()) {
389376 setPreviousBrowseAssetLocation(QFileInfo(result).absolutePath());
390377 }
391378 emit assetsDirChanged(result);
392379 });
393−
394− OffscreenUi::getOpenAssetNameAsync(nullptr, title, path, nameFilter);
395380 }
396381
397382 void WindowScriptingInterface::showAssetServer(const QString& upload) {