Skip to content

Commit

Permalink
Let dialog() with only a question return true if accepted
Browse files Browse the repository at this point in the history
  • Loading branch information
hluk committed May 2, 2024
1 parent 28cc986 commit e914514
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
12 changes: 12 additions & 0 deletions docs/scripting-api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1109,6 +1109,18 @@ unlike in GUI, where row numbers start from 1 by default.
'.label', 'Command <b>successfully</b> 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
Expand Down
2 changes: 2 additions & 0 deletions src/scriptable/scriptableproxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions src/tests/tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit e914514

Please sign in to comment.