WL 21668 - Make sure all Prompts are correctly emitting a signal on cancel and that cancellations return null
Showing the changes to interface/src/scripting/WindowScriptingInterface.cpp (1 of 2 files). Show all
Unified · Split
| @@ -120,16 +120,19 @@ QScriptValue WindowScriptingInterface::confirm(const QString& message) { · 119 unmodified lines | ||
| 120 | 120 | /// \param const QString& defaultText default text in the text box |
| 121 | 121 | /// \return QScriptValue string text value in text box if the dialog was accepted, `null` otherwise. |
| 122 | 122 | QScriptValue WindowScriptingInterface::prompt(const QString& message, const QString& defaultText) { |
| 123 | − bool ok = false; | |
| 124 | − QString result = OffscreenUi::getText(nullptr, "", message, QLineEdit::Normal, defaultText, &ok); | |
| 125 | − return ok ? QScriptValue(result) : QScriptValue::NullValue; | |
| 123 | + QString result = OffscreenUi::getText(nullptr, "", message, QLineEdit::Normal, defaultText); | |
| 124 | + if (QScriptValue(result).equals("")) { | |
| 125 | + return QScriptValue::NullValue; | |
| 126 | + } | |
| 127 | + return QScriptValue(result); | |
| 126 | 128 | } |
| 127 | 129 | |
| 128 | 130 | /// Display a prompt with a text box |
| 129 | 131 | /// \param const QString& message message to display |
| 130 | 132 | /// \param const QString& defaultText default text in the text box |
| 131 | 133 | void WindowScriptingInterface::promptAsync(const QString& message, const QString& defaultText) { |
| 132 | − ModalDialogListener* dlg = OffscreenUi::getTextAsync(nullptr, "", message, QLineEdit::Normal, defaultText); | |
| 134 | + bool ok = false; | |
| 135 | + ModalDialogListener* dlg = OffscreenUi::getTextAsync(nullptr, "", message, QLineEdit::Normal, defaultText, &ok); | |
| 133 | 136 | connect(dlg, &ModalDialogListener::response, this, [=] (QVariant result) { |
| 134 | 137 | disconnect(dlg, &ModalDialogListener::response, this, nullptr); |
| 135 | 138 | emit promptTextChanged(result.toString()); |