Back to Devexpress

TdxAICommandList Class

vcl-dxai-1db3a025.md

latest9.5 KB
Original Source

TdxAICommandList Class

A collection of AI-powered commands.

Declaration

delphi
TdxAICommandList = class sealed(TObject)

Remarks

The TdxAICommandList class implements a pre-populated list of AI-powered commands available in all supported native VCL controls. You can handle an OnGetAICommands event in any supported control to customize the list of available commands as demonstrated in code examples below.

Pre-Populated Command List

A TdxAICommandList collection accessible through the AAICommands parameter within an OnGetAICommands event handler is populated with the following AI-powered command IDs (declared in the dxAI.Commands.Consts unit):

TdxAICommandIDs.ExpandExpands original text with additional information or in-depth explanations.TdxAICommandIDs.ShortenRemoves redundant details and makes content more concise.TdxAICommandIDs.SummarizeCreates a brief summary based on original text.TdxAICommandIDs.ExplainRephrases text in more clear terms and makes complex content more accessible and understandable.TdxAICommandIDs.ProofreadReviews text for spelling, grammar, punctuation, and style errors.TdxAICommandIDs.ChangeTone

The Change Tone command group is designed to adjust text tone to meet specific audience or context requirements. This group includes the following nested commands:

  • Professional (TdxAICommandIDs.ChangeTone.Professional)
  • Casual (TdxAICommandIDs.ChangeTone.Casual)
  • Straightforward (TdxAICommandIDs.ChangeTone.Straightforward)
  • Confident (TdxAICommandIDs.ChangeTone.Confident)
  • Friendly (TdxAICommandIDs.ChangeTone.Friendly)

TdxAICommandIDs.ChangeStyle

The Change Style command group is designed to rephrase or paraphrase original text while retaining its original meaning. This group includes the following nested commands:

  • Formal (TdxAICommandIDs.ChangeStyle.Formal)
  • Informal (TdxAICommandIDs.ChangeStyle.Informal)
  • Technical (TdxAICommandIDs.ChangeStyle.Technical)
  • Business (TdxAICommandIDs.ChangeStyle.Business)
  • Creative (TdxAICommandIDs.ChangeStyle.Creative)
  • Journalistic (TdxAICommandIDs.ChangeStyle.Journalistic)
  • Academic (TdxAICommandIDs.ChangeStyle.Academic)
  • Persuasive (TdxAICommandIDs.ChangeStyle.Persuasive)
  • Narrative (TdxAICommandIDs.ChangeStyle.Narrative)
  • Expository (TdxAICommandIDs.ChangeStyle.Expository)
  • Descriptive (TdxAICommandIDs.ChangeStyle.Descriptive)
  • Conversational (TdxAICommandIDs.ChangeStyle.Conversational)

TdxAICommandIDs.Translate

The Translate command group is designed to translate original text into a different language. Includes the following nested commands that correspond to individual target languages:

  • English (TdxAICommandIDs.Translate.English)
  • German (TdxAICommandIDs.Translate.German)
  • French (TdxAICommandIDs.Translate.French)

Main API Members

The list below outlines key members of the TdxAICommandList class. These members allow you to add/remove/rearrange individual end-user AI commands in the pre-populated list as well as change their status.

AI Command Collection Management

Add | Delete | RemoveAdd and remove individual commands.ClearClears the AI command collection.CountReturns the number of AI-powered commands in the collection.ExchangeSwaps two individual AI-powered commands.InsertInserts a new command at the target position.MoveMoves a command within the collection.

AI Command Availability

Available

Specifies if an individual AI-powered command is available to users.

Tip

This property allows you to enable or disable UI elements and other options (such as dedicated keystrokes) associated with end-user AI commands.

Find | IndexOfReturn the index of the target command in the collection (-1 if no such command is present in the collection).

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;
}

Direct TdxAICommandList Class Reference

The TdxOnGetAICommands procedural type references a TdxAICommandList object as the AAICommands parameter.

Inheritance

TObject TdxAICommandList

See Also

TcxCustomTextEditProperties.OnGetAICommands Event

TdxRichEditControlBase.OnGetAICommands Event

TdxAICommandList Members

dxAI Unit