Sign in Join
Wiki copytemporary

ATSynEdit EControl adapter: what changed

Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.

Title: ATSynEdit EControl adapter

OldNewLine
1+# Intro
2+
3+[[ATSynEdit]] has adapter for lexers from SynWrite editor. It's EControl lexer engine.
4+
5+- Use repo <https://github.com/Alexey-T/EControl>
6+- Use repo <https://github.com/Alexey-T/ATSynEdit_Ex>
7+
8+Unit ATSynEdit_Adapter_EControl contains class TATAdapterEControl. You must create object of this class and assign this object to editor property AdapterHilite.
9+
10+For ex, if you have editor object:
11+
12+``` pascal
13+ //form's OnCreate
14+ Adapter:= TATAdapterEControl.Create(Self);
15+ Edit1.AdapterHilite:= Adapter;
16+```
17+
18+For ex, if you have 2 editor objects with the same text-source (see help topic [[ATSynEdit]]):
19+
20+``` pascal
21+ Adapter:= TATAdapterEControl.Create(Self);
22+ Adapter.AddEditor(Ed1);
23+ Adapter.AddEditor(Ed2);
24+ Ed1.AdapterHilite:= Adapter;
25+ Ed2.AdapterHilite:= Adapter;
26+```
27+
28+# Properties
29+
30+- Lexer: TecSyntAnalyzer. You must set this prop from SyntaxManager object. SyntaxManager is a collection of lexers, which is loaded from .lxl file. After you load SyntaxManager, get its any item and assign it to Lexer prop. Example exists in demo of ATSynEdit. Set to nil to disable adapter.
31+
32+- DynamicHiliteEnabled: boolean. This enables dynamic highlight, ie highlight of tokens depending on caret position. If enabled, adapter reads editor's caret-pos-changed event and recalculates hiliting if needed. Some lexers use this feature: HTML hilites tags with green if caret is inside tag; Pascal hilites "begin"/"end" with green if caret is inside block; rare C-like lexers hilite brackets.
33+
34+<figure>
35+<img src="atsynedit_dyn_hilite.png" title="atsynedit_dyn_hilite.png" />
36+<figcaption>atsynedit_dyn_hilite.png</figcaption>
37+</figure>
38+
39+- OnParseBegin, OnParseDone: these events called by adapter on analyzing start and after analyzing finish. If big file parsed, OnParseDone will fire after few seconds, during which user may edit/scroll file.
40+
41+- procedure AddEditor(AEdit: TATSynEdit). This adds editor to internal list. This is to support 2+ editors which have single text-source (application has split-tab feature). Pass nil to clear internal list and disable adapter.
42+
43+# Syntax tree
44+
45+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.
46+
47+<figure>
48+<img src="atsynedit_tree.png" title="atsynedit_tree.png" />
49+<figcaption>atsynedit_tree.png</figcaption>
50+</figure>
51+
52+``` pascal
53+ procedure TreeFill(ATree: TTreeView);
54+```
55+
56+It fills tree with nodes from adapter. Call it only after parsing is done. On parsing start, better clear the tree.
57+
58+``` pascal
59+ property TreeBusy: boolean
60+```
61+
62+It is true during filling of tree by TreeFill.
63+
64+``` pascal
65+ procedure TreeShowItemForCaret(Tree: TTreeView; P: TPoint);
66+```
67+
68+This focuses tree node, for given caret position. Only if position has a node.
69+
70+``` pascal
71+ function TreeGetPositionOfRange(R: TecTextRange): TPoint;
72+ function TreeGetRangeOfPosition(P: TPoint): TecTextRange;
73+```
74+
75+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:
76+
77+``` pascal
78+procedure TfmMain.TreeDblClick(Sender: TObject);
79+var
80+ R: TecTextRange;
81+ P: TPoint;
82+begin
83+ if Tree.Selected=nil then exit;
84+ if Tree.Selected.Data=nil then exit;
85+ R:= TecTextRange(Tree.Selected.Data);
86+ P:= CurrentFrame.Adapter.TreeGetPositionOfRange(R);
87+ FTreeClick:= true;
88+ CurrentEditor.DoGotoPosEx(P);
89+ CurrentEditor.SetFocus;
90+ FTreeClick:= false;
91+end;
92+```
93+
94+# Syntax tree icons
95+
96+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:
97+
98+<figure>
99+<img src="atsynedit_tree_img.png" title="atsynedit_tree_img.png" />
100+<figcaption>atsynedit_tree_img.png</figcaption>
101+</figure>
102+
103+---
104+*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](/wiki-contact).*
105+Category: ATSynEdit

Back to history