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 | /// \param const QString& defaultText default text in the text box | 120 | /// \param const QString& defaultText default text in the text box |
| 121 | /// \return QScriptValue string text value in text box if the dialog was accepted, `null` otherwise. | 121 | /// \return QScriptValue string text value in text box if the dialog was accepted, `null` otherwise. |
| 122 | QScriptValue WindowScriptingInterface::prompt(const QString& message, const QString& defaultText) { | 122 | QScriptValue WindowScriptingInterface::prompt(const QString& message, const QString& defaultText) { |
| 123 | bool ok = false; | 123 | QString result = OffscreenUi::getText(nullptr, "", message, QLineEdit::Normal, defaultText); |
| 124 | QString result = OffscreenUi::getText(nullptr, "", message, QLineEdit::Normal, defaultText, &ok); | 124 | if (QScriptValue(result).equals("")) { |
| 125 | return ok ? QScriptValue(result) : QScriptValue::NullValue; | 125 | return QScriptValue::NullValue; |
| 126 | } | ||
| 127 | return QScriptValue(result); | ||
| 126 | } | 128 | } |
| 127 | 129 | ||
| 128 | /// Display a prompt with a text box | 130 | /// Display a prompt with a text box |
| 129 | /// \param const QString& message message to display | 131 | /// \param const QString& message message to display |
| 130 | /// \param const QString& defaultText default text in the text box | 132 | /// \param const QString& defaultText default text in the text box |
| 131 | void WindowScriptingInterface::promptAsync(const QString& message, const QString& defaultText) { | 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 | connect(dlg, &ModalDialogListener::response, this, [=] (QVariant result) { | 136 | connect(dlg, &ModalDialogListener::response, this, [=] (QVariant result) { |
| 134 | disconnect(dlg, &ModalDialogListener::response, this, nullptr); | 137 | disconnect(dlg, &ModalDialogListener::response, this, nullptr); |
| 135 | emit promptTextChanged(result.toString()); | 138 | emit promptTextChanged(result.toString()); |