Wiki copymirror

This is a mirror of the wiki at pascal.chat. Editing, history and sign-in are there.

ATSynEdit EControl adapter

Intro

ATSynEdit has adapter for lexers from SynWrite editor. It's EControl lexer engine.

Unit ATSynEdit_Adapter_EControl contains class TATAdapterEControl. You must create object of this class and assign this object to editor property AdapterHilite.

For ex, if you have editor object:

pascal
  //form's OnCreate
  Adapter:= TATAdapterEControl.Create(Self);
  Edit1.AdapterHilite:= Adapter;

For ex, if you have 2 editor objects with the same text-source (see help topic ATSynEdit):

pascal
  Adapter:= TATAdapterEControl.Create(Self);
  Adapter.AddEditor(Ed1);
  Adapter.AddEditor(Ed2);
  Ed1.AdapterHilite:= Adapter;
  Ed2.AdapterHilite:= Adapter;

Properties

Syntax tree

Support for syntax tree exists like in SynWrite. Many lexers support tree (most C-based, Pascal, HTML, CSS, Python...). You need to add TTreeView to your form and use it in this API. Set tree read/only.

pascal
    procedure TreeFill(ATree: TTreeView);

It fills tree with nodes from adapter. Call it only after parsing is done. On parsing start, better clear the tree.

pascal
    property TreeBusy: boolean

It is true during filling of tree by TreeFill.

pascal
    procedure TreeShowItemForCaret(Tree: TTreeView; P: TPoint);

This focuses tree node, for given caret position. Only if position has a node.

pascal
    function TreeGetPositionOfRange(R: TecTextRange): TPoint;
    function TreeGetRangeOfPosition(P: TPoint): TecTextRange;

These get caret position from a range, or range from caret position. Range is object, it's stored in TTreeNode.Data of nodes. If you want to goto clicked tree item, add OnDblClick event to tree, and use this API. Example:

pascal
procedure TfmMain.TreeDblClick(Sender: TObject);
var
  R: TecTextRange;
  P: TPoint;
begin
  if Tree.Selected=nil then exit;
  if Tree.Selected.Data=nil then exit;
  R:= TecTextRange(Tree.Selected.Data);
  P:= CurrentFrame.Adapter.TreeGetPositionOfRange(R);
  FTreeClick:= true;
  CurrentEditor.DoGotoPosEx(P);
  CurrentEditor.SetFocus;
  FTreeClick:= false;
end;

Syntax tree icons

Many lexers support icons in tree (e.g. Pascal, C#). To show icons, use for tree ImageList with these 8 icons: folder, parts-1, parts-2, parts-3, box, func, arrow-1, arrow-2. Example of icons from CudaText:


From the Free Pascal wiki, page "ATSynEdit EControl adapter", as it stood on 2020-02-09 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.

Revision 2, last changed by WikiArchive .