Back to Devexpress

TdxOnGetAICommands Type

vcl-dxai-2af68592.md

latest7.6 KB
Original Source

TdxOnGetAICommands Type

The procedural type for AI command list population events.

Declaration

delphi
TdxOnGetAICommands = procedure(Sender: TObject; const AAICommands: TdxAICommandList) of object;

Parameters

NameTypeDescription
SenderTObject

Provides access to the control that raised the AI command list population event. You need to cast this parameter value to the corresponding terminal control class to access public API members.

Tip

Call the Sender.ClassType function or use other RTTI functionality to identify the actual control class.

| | AAICommands | TdxAICommandList |

Provides access to the pre-populated list of AI-powered end-user commands.

Call AAICommands.Add or AAICommands.Remove procedures to add or remove individual commands. To enable or disable UI elements associated with corresponding commands, use the AAICommands.Available property.

Refer to the TdxAICommandList class description for detailed information on all available options (including the full list of predefined AI command IDs).

|

Remarks

An AI command list population event occurs every time a supported control displays UI elements mapped to AI-powered end-user commands. You can handle these events to manage the list of available AI-powered commands and modify their status depending on specific conditions in your application.

Code Examples

Rearrange AI-powered Commands

The following code example moves Explain and Proofread commands to the second and third positions in a context menu, respectively:

delphi
uses
  dxRichEdit.Control, // Declares TdxRichEditControl
  dxAI; // Declares AI-specific types
// ...

procedure TMyForm.dxRichEditControl1GetAICommands(Sender: TObject;
  const AAICommands: TdxAICommandList);
var
  ACommandIndex: Integer;
begin
  ACommandIndex := AAICommands.IndexOf(TdxAICommandIDs.Explain);
  AAICommands.Move(ACommandIndex, 1); // Moves "Explain" to the second position (after "Expand")
  ACommandIndex := AAICommands.IndexOf(TdxAICommandIDs.Proofread);
  AAICommands.Move(ACommandIndex, 2); // Moves "Proofread" to the third position (after "Explain")
end;
cpp
#include "dxRichEdit.Control.hpp" // Declares TdxRichEditControl
#include "dxAI.hpp" // Declares AI-specific types
// ...

void __fastcall TMyForm::dxRichEditControl1GetAICommands(TObject *Sender,
  const TdxAICommandList *AAICommands)
{
  int ACommandIndex = AAICommands->IndexOf(TdxAICommandIDs::Explain);
  AAICommands->Move(ACommandIndex, 1); // Moves "Explain" to the second position (after "Expand")
  ACommandIndex = AAICommands->IndexOf(TdxAICommandIDs::Proofread);
  AAICommands->Move(ACommandIndex, 2); // Moves "Proofread" to the third position" (after "Explain")
}

Hide AI-powered Commands

The following code example hides all AI-powered commands (removes the AI Assistant item) when no content is selected in the document:

delphi
uses
  dxRichEdit.Control, // Declares TdxRichEditControl
  dxAI; // Declares AI-specific types
// ...

procedure TMyForm.dxRichEditControl1GetAICommands(Sender: TObject;
  const AAICommands: TdxAICommandList);
begin
  if ((Sender as TdxRichEditControl).Document.Selections.Count = 0) or
     ((Sender as TdxRichEditControl).Document.Selection.Length = 0) then
       AAICommands.Clear;
end;
cpp
#include "dxRichEdit.Control.hpp" // Declares TdxRichEditControl
#include "dxAI.hpp" // Declares AI-specific types
// ...

void __fastcall TMyForm::dxRichEditControl1GetAICommands(TObject *Sender,
  const TdxAICommandList *AAICommands)
{
  if((dynamic_cast<TdxRichEditControl*>(Sender)->Document->Selections->Count == 0) ||
    ((dynamic_cast<TdxRichEditControl*>(Sender)->Document->Selection->Length == 0)))
      AAICommands->Clear();
}

Disable Individual AI-powered Commands

The following code example disables Expand , Shorten and Summarize commands in the context menu:

delphi
uses
  dxRichEdit.Control, // Declares TdxRichEditControl
  dxAI, // Declares AI-specific types
  dxAI.Commands.Consts; // Declares AI command identifiers
// ...

procedure TMyForm.dxRichEditControl1GetAICommands(Sender: TObject;
  const AAICommands: TdxAICommandList);
begin
  AAICommands.Available[TdxAICommandIDs.Expand] := False;
  AAICommands.Available[TdxAICommandIDs.Shorten] := False;
  AAICommands.Available[TdxAICommandIDs.Summarize] := False;
end;
cpp
#include "dxRichEdit.Control.hpp" // Declares TdxRichEditControl
#include "dxAI.hpp" // Declares AI-specific types
#include "dxAI.Commands.Consts;" // Declares AI command identifiers
// ...

void __fastcall TMyForm::dxRichEditControl1GetAICommands(TObject *Sender,
  const TdxAICommandList *AAICommands)
{
  AAICommands->Available[TdxAICommandIDs::Expand] = false;
  AAICommands->Available[TdxAICommandIDs::Shorten] = false;
  AAICommands->Available[TdxAICommandIDs::Summarize] = false;
}

To see AI-powered commands in action, run the Word Processing RTF demo in the VCL Demo Center installed with compiled DevExpress VCL demos.

Select a text range, right-click within the control area, and expand the AI Assistant item to select the required command. The demo displays the result in a separate modal dialog:

Download: Compiled VCL Demos

Tip

You can find full source code for the installed Rich Edit control demo in the following folder:

%PUBLIC%\Documents\DevExpress VCL Demos\MegaDemos\Product Demos\ExpressRichEditControl

Direct TdxOnGetAICommands Type References

The following events reference the TdxOnGetAICommands procedural type:

TcxCustomTextEditProperties.OnGetAICommandsAllows you to modify the list of AI-powered commands available in the editor.TdxRichEditControlBase.OnGetAICommandsAllows you to modify the list of AI-powered commands available in the Rich Edit control. See Also

dxAI Unit