The commands skill
commands lets the assistant press the buttons of the form the user is working on. Two actions:
| Action | Asks first | What it does |
|---|---|---|
list_commands | no | Lists the buttons the user could press now: id, caption, shortcut, what each does |
press_command | yes | Presses one, as if the user clicked it |
Its point is the answer that used to end with "now press Calculate": the assistant can press it, and the model is told so in so many words - you CAN press the buttons with this action, never ask the user to do it.
What a command is
The skill walks the form and keeps every button that is visible and enabled, with its parents - a button the user cannot press now is not offered:
TButtonandTBitBtn;TSpeedButton;TToolButton, separators and dividers apart;- each button of a
TDBNavigator(first, prior, next, last, insert, delete, edit, cancel, refresh...), with an id of its own:DBNavigator1.next; - in FireMonkey, every button -
TButton,TSpeedButton,TCornerButton- its caption being itsText. The buttons of aTBindNavigatorare offered too, named by their hint: they have no name of their own, so their ids arebutton,button_2...
For each one the model reads:
| From | |
|---|---|
| id | the name of the control (btnCalc) |
| caption | its caption, without the hot-key mark; else the short part of its hint; else the caption of its action; else its name - a glyph-only speed button is named by its hint |
| shortcut | the ShortCut of its action, when it has one (Ctrl+F9) |
| what it does | the long part of its hint |
Buttons of "Proposal" the assistant may press now (id | caption | shortcut), then what each does:
- btnCalc | Calculate | Ctrl+F9
Computes the discount and the total from the line items.
- btnPreview | Preview | -
- DBNavigator1.next | Next record | -
Saving or confirming is never among them: the user does it. press_command presses one;
never mention buttons, keys or menus that are not listed.The last line matters as much as the list: a model asked how to do something on a screen is tempted to invent a key or a menu that sounds plausible. Here it has the real ones.
What it never offers
Saving belongs to the user, so a button that looks like it saves or confirms is left out:
- its action is a
TDataSetPost, or a post action of LiveBindings; - it is the Post (or Apply updates) button of a navigator;
- its
ModalResultis OK, Yes, All or Yes to all - the button that closes a dialog accepting what it shows; - its caption is one of the words that save or confirm, in the languages of the library: Save, OK, Post, Apply, Submit, Confirm, Salva, Registra, Conferma, Invia, Speichern, Übernehmen, Enregistrer, Valider, Guardar, Salvar, Gravar...;
- its name says so (
btnSave,btnConferma).
And while a record is being edited, what moves, inserts or reloads is left out too - the buttons of a navigator and the buttons with a standard data set action (TDataSetNext, TDataSetInsert, the bind navigator actions...): on a data set in edit, Next posts the record before moving. A button of a TBindNavigator, VCL or FireMonkey, is recognised by what it is, not by its hint, which the RTL translates.
The words are a guess, and a guess can be wrong both ways - a Confirm order button that only opens a summary, a Close that does save. OnCommand settles it: it receives every button, with AAccept already False for the ones taken for a save.
procedure TMainForm.SkillCommand(Sender: TObject; const ACommand: THelpChatVclCommand;
var AAccept: Boolean);
begin
if ACommand.Id = 'btnConfirmOrder' then
AAccept := True // opens the summary, saves nothing
else if ACommand.Id = 'btnPurge' then
AAccept := False; // never by the assistant
end;Pressing
press_command takes the id or the caption from the list (the same text, case apart, else the only caption that contains it) and goes through the confirmation of the component:
The assistant wants to press "Calculate" on "Proposal".The click itself happens right after the action has answered, not inside it. A button may open a modal window, and a modal window keeps its caller waiting until the user closes it: pressed inside the action, the model would wait for the user - up to the timeout of the actions - and report a failure. So the model is told the button was pressed, the click follows a moment later, and the next step of the model - describe_form, list_commands - runs after it, on what the button left on the screen: the same form changed, or the window it opened, which is now the form the user is working on.
The button is looked up again at that moment, by its id: if it vanished in between, nothing is pressed. What it does is entirely the form's - the same OnClick, the same action, the same rights and confirmations as a click of the user.