diff --git a/docs/scripting-api.rst b/docs/scripting-api.rst index 34c34a3a7..e8ace527d 100644 --- a/docs/scripting-api.rst +++ b/docs/scripting-api.rst @@ -1109,6 +1109,18 @@ unlike in GUI, where row numbers start from 1 by default. '.label', 'Command successfully finished.' ) + Accepting a dialog containing only a question returns ``true`` + (rejecting/cancelling the dialog returns ``undefined``). + + .. code-block:: js + + const remove = dialog( + '.title', 'Remove Items', + '.label', 'Do you really want to remove all items?' + ) + if (!remove) + abort(); + Other arguments are used to get user input. .. code-block:: js diff --git a/src/scriptable/scriptableproxy.cpp b/src/scriptable/scriptableproxy.cpp index e4055dbce..1ba0d5891 100644 --- a/src/scriptable/scriptableproxy.cpp +++ b/src/scriptable/scriptableproxy.cpp @@ -2164,6 +2164,8 @@ int ScriptableProxy::inputDialog(const NamedValueList &values) const QVariant value = w->property(propertyName.toUtf8().constData()); result.items.append( NamedValue(name, value) ); } + if ( widgets.isEmpty() ) + result.items.append( NamedValue(QString(), true) ); } QByteArray bytes; diff --git a/src/tests/tests.cpp b/src/tests/tests.cpp index 01469773f..4e416315b 100644 --- a/src/tests/tests.cpp +++ b/src/tests/tests.cpp @@ -1303,6 +1303,12 @@ void Tests::commandDialog() [&]() { RUN(WITH_TIMEOUT + script, "DEFAULT\n"); }, [&]() { RUN(Args() << "keys" << "focus::QLineEdit in :QDialog" << "ENTER", ""); } ); + + RUN(Args() << "keys" << clipboardBrowserId, ""); + runMultiple( + [&]() { RUN(WITH_TIMEOUT "dialog('.title', 'Remove Items', '.label', 'Remove all items?') === true", "true\n"); }, + [&]() { RUN(Args() << "keys" << "focus::QPushButton in dialog_Remove Items:QDialog" << "ENTER", ""); } + ); } void Tests::commandDialogCloseOnDisconnect()