How to force standard actions (e.g. TEditCopy) to recognize additional controls (e.g. TEmbeddedWB)?

I usually staffed functionality TEditCut, TEditCopy, TEditPasteand TEditSelectAll, except for the fact that they do not work on any controls that are not standard.

For example, they can work normally on controls TEditor TMemo, but not on TEmbeddedWB, standard actions are always disabled with it, regardless of whether the text is selected, although it TEmbeddedWBhas methods similar to CopyToClipboardand SelectAll.

How can I do standard actions with TEmbeddedWB? How do standard actions determine whether they should be turned on or off (and in which case they do this - in the event OnUpdate)? Can I distribute standard actions to add support for unrecognized components, or do I need to write a replacement for them?

+4
source share
1 answer

Default actions do not work with the control by default TEmbeddedWB, because this component does not come off TCustomEdit. TEditAction, which TEditSelectAllleaves, knows only how to process TCustomEdits.

OnUpdate OnExecute , . , , . TEditSelectAll.

procedure TForm1.EditSelectAll1Update(Sender: TObject);
begin
  EditSelectAll1.Enabled := (Screen.ActiveControl is TEmbeddedWB) or
    EditSelectAll1.HandlesTarget(ActiveControl)
end;

procedure TForm1.EditSelectAll1Execute(Sender: TObject);
begin
  if ActiveControl is TEmbeddedWB then
    TEmbeddedWB(Screen.ActiveControl).SelectAll
  else
    EditSelectAll1.ExecuteTarget(Screen.ActiveControl);
end;

ActionList ( OnActionUpdate OnActionExecute ApplicationEvents) :

procedure TForm1.ActionList1Update(Action: TBasicAction; var Handled: Boolean);
begin
  if Action is TEditAction then
  begin
    TCustomAction(Action).Enabled := (Screen.ActiveControl is TEmbeddedWB) or
      Action.HandlesTarget(Screen.ActiveControl);
    Handled := True;
  end;
end;

procedure TForm1.ActionList1Execute(Action: TBasicAction; var Handled: Boolean);
begin
  if (Action is TEditSelectAll) and (Screen.ActiveControl is TEmbeddedWB) then
  begin
    TEmbeddedWB(Screen.ActiveControl).SelectAll;
    Handled := True;
  end;
end;
+6

All Articles