fpcodtmp.pas 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  1. unit FPCodTmp; { Code Templates }
  2. interface
  3. uses Objects,Drivers,Dialogs,
  4. WUtils,WViews,WEditor,
  5. FPViews;
  6. type
  7. PCodeTemplate = ^TCodeTemplate;
  8. TCodeTemplate = object(TObject)
  9. constructor Init(const AShortCut: string; AText: PUnsortedStringCollection);
  10. function GetShortCut: string;
  11. procedure GetText(AList: PUnsortedStringCollection);
  12. procedure SetShortCut(const AShortCut: string);
  13. procedure SetText(AList: PUnsortedStringCollection);
  14. procedure GetParams(var AShortCut: string; Lines: PUnsortedStringCollection);
  15. procedure SetParams(const AShortCut: string; Lines: PUnsortedStringCollection);
  16. constructor Load(var S: TStream);
  17. procedure Store(var S: TStream);
  18. destructor Done; virtual;
  19. private
  20. ShortCut: PString;
  21. Text: PUnsortedStringCollection;
  22. end;
  23. PCodeTemplateCollection = ^TCodeTemplateCollection;
  24. TCodeTemplateCollection = object(TSortedCollection)
  25. function Compare(Key1, Key2: Pointer): sw_Integer; virtual;
  26. function SearchByShortCut(const ShortCut: string): PCodeTemplate; virtual;
  27. function LookUp(const S: string; AcceptMulti: boolean; var Idx: sw_integer): string; virtual;
  28. end;
  29. PCodeTemplateListBox = ^TCodeTemplateListBox;
  30. TCodeTemplateListBox = object(TAdvancedListBox)
  31. function GetText(Item,MaxLen: Sw_Integer): String; virtual;
  32. end;
  33. PCodeTemplateDialog = ^TCodeTemplateDialog;
  34. TCodeTemplateDialog = object(TCenterDialog)
  35. constructor Init(const ATitle: string; ATemplate: PCodeTemplate);
  36. function Execute: Word; virtual;
  37. private
  38. Template : PCodeTemplate;
  39. ShortcutIL : PInputLine;
  40. CodeMemo : PFPCodeMemo;
  41. end;
  42. PCodeTemplatesDialog = ^TCodeTemplatesDialog;
  43. TCodeTemplatesDialog = object(TCenterDialog)
  44. SelMode: boolean;
  45. constructor Init(ASelMode: boolean;const AShortCut : string);
  46. function Execute: Word; virtual;
  47. procedure HandleEvent(var Event: TEvent); virtual;
  48. function GetSelectedShortCut: string;
  49. private
  50. CodeTemplatesLB : PCodeTemplateListBox;
  51. TemplateViewer : PFPCodeMemo;
  52. StartIdx : sw_integer;
  53. procedure Add;
  54. procedure Edit;
  55. procedure Delete;
  56. procedure Update;
  57. end;
  58. const CodeTemplates : PCodeTemplateCollection = nil;
  59. function FPTranslateCodeTemplate(var Shortcut: string; ALines: PUnsortedStringCollection): boolean;
  60. procedure InitCodeTemplates;
  61. function LoadCodeTemplates(var S: TStream): boolean;
  62. function StoreCodeTemplates(var S: TStream): boolean;
  63. procedure DoneCodeTemplates;
  64. procedure RegisterCodeTemplates;
  65. implementation
  66. uses Views,App,Validate,
  67. {$ifdef FVISION}
  68. FVConsts,
  69. {$else}
  70. Commands,
  71. {$endif}
  72. FPConst,FPString;
  73. {$ifndef NOOBJREG}
  74. const
  75. RCodeTemplate: TStreamRec = (
  76. ObjType: 14501;
  77. VmtLink: Ofs(TypeOf(TCodeTemplate)^);
  78. Load: @TCodeTemplate.Load;
  79. Store: @TCodeTemplate.Store
  80. );
  81. RCodeTemplateCollection: TStreamRec = (
  82. ObjType: 14502;
  83. VmtLink: Ofs(TypeOf(TCodeTemplateCollection)^);
  84. Load: @TCodeTemplateCollection.Load;
  85. Store: @TCodeTemplateCollection.Store
  86. );
  87. {$endif}
  88. constructor TCodeTemplate.Init(const AShortCut: string; AText: PUnsortedStringCollection);
  89. procedure CopyIt(P: PString); {$ifndef FPC}far;{$endif}
  90. begin
  91. Text^.Insert(NewStr(GetStr(P)));
  92. end;
  93. begin
  94. inherited Init;
  95. ShortCut:=NewStr(AShortCut);
  96. SetText(AText);
  97. end;
  98. function TCodeTemplate.GetShortCut: string;
  99. begin
  100. GetShortCut:=GetStr(ShortCut);
  101. end;
  102. procedure TCodeTemplate.GetText(AList: PUnsortedStringCollection);
  103. procedure CopyIt(P: PString); {$ifndef FPC}far;{$endif}
  104. begin
  105. AList^.Insert(NewStr(GetStr(P)));
  106. end;
  107. begin
  108. if Assigned(AList) and Assigned(Text) then
  109. Text^.ForEach(@CopyIt);
  110. end;
  111. procedure TCodeTemplate.SetShortCut(const AShortCut: string);
  112. begin
  113. if Assigned(ShortCut) then DisposeStr(ShortCut);
  114. ShortCut:=NewStr(AShortCut);
  115. end;
  116. procedure TCodeTemplate.SetText(AList: PUnsortedStringCollection);
  117. begin
  118. if Assigned(Text) then Dispose(Text, Done);
  119. New(Text, CreateFrom(AList));
  120. end;
  121. procedure TCodeTemplate.GetParams(var AShortCut: string; Lines: PUnsortedStringCollection);
  122. begin
  123. AShortCut:=GetShortCut;
  124. GetText(Lines);
  125. end;
  126. procedure TCodeTemplate.SetParams(const AShortCut: string; Lines: PUnsortedStringCollection);
  127. begin
  128. SetShortCut(AShortCut);
  129. SetText(Lines);
  130. end;
  131. constructor TCodeTemplate.Load(var S: TStream);
  132. begin
  133. ShortCut:=S.ReadStr;
  134. New(Text, Load(S));
  135. end;
  136. procedure TCodeTemplate.Store(var S: TStream);
  137. begin
  138. S.WriteStr(ShortCut);
  139. Text^.Store(S);
  140. end;
  141. destructor TCodeTemplate.Done;
  142. begin
  143. if Assigned(ShortCut) then DisposeStr(ShortCut); ShortCut:=nil;
  144. if Assigned(Text) then Dispose(Text, Done); Text:=nil;
  145. inherited Done;
  146. end;
  147. function TCodeTemplateCollection.Compare(Key1, Key2: Pointer): sw_Integer;
  148. var K1: PCodeTemplate absolute Key1;
  149. K2: PCodeTemplate absolute Key2;
  150. R: Sw_integer;
  151. S1,S2: string;
  152. begin
  153. S1:=UpCaseStr(K1^.GetShortCut);
  154. S2:=UpCaseStr(K2^.GetShortCut);
  155. if S1<S2 then R:=-1 else
  156. if S1>S2 then R:=1 else
  157. R:=0;
  158. Compare:=R;
  159. end;
  160. function TCodeTemplateCollection.SearchByShortCut(const ShortCut: string): PCodeTemplate;
  161. var T: TCodeTemplate;
  162. Index: sw_integer;
  163. P: PCodeTemplate;
  164. begin
  165. T.Init(ShortCut,nil);
  166. if Search(@T,Index)=false then P:=nil else
  167. P:=At(Index);
  168. T.Done;
  169. SearchByShortCut:=P;
  170. end;
  171. function TCodeTemplateCollection.LookUp(const S: string; AcceptMulti: boolean; var Idx: sw_integer): string;
  172. var OLI,ORI,Left,Right,Mid: sw_integer;
  173. MidP: PCodeTemplate;
  174. MidS: string;
  175. FoundS: string;
  176. UpS : string;
  177. begin
  178. Idx:=-1; FoundS:='';
  179. Left:=0; Right:=Count-1;
  180. UpS:=UpCaseStr(S);
  181. while Left<=Right do
  182. begin
  183. OLI:=Left; ORI:=Right;
  184. Mid:=Left+(Right-Left) div 2;
  185. MidP:=At(Mid);
  186. MidS:=UpCaseStr(MidP^.GetShortCut);
  187. if copy(MidS,1,length(UpS))=UpS then
  188. begin
  189. if (Idx<>-1) and (Idx<>Mid) and not AcceptMulti then
  190. begin
  191. { several solutions possible, return nothing }
  192. Idx:=-1;
  193. FoundS:='';
  194. break;
  195. end
  196. else if Idx=-1 then
  197. begin
  198. Idx:=Mid;
  199. FoundS:=MidP^.GetShortCut;
  200. end;
  201. end;
  202. if UpS<MidS then
  203. Right:=Mid
  204. else
  205. Left:=Mid;
  206. if (OLI=Left) and (ORI=Right) then
  207. begin
  208. if (Left<Right) then
  209. Left:=Right
  210. else
  211. Break;
  212. end;
  213. end;
  214. { check if next also fits...
  215. return '' in that case }
  216. if (Idx<>-1) and (Idx<Count-1) and not AcceptMulti then
  217. begin
  218. MidP:=At(Idx+1);
  219. MidS:=UpCaseStr(MidP^.GetShortCut);
  220. if copy(MidS,1,length(UpS))=UpS then
  221. begin
  222. Idx:=-1;
  223. FoundS:='';
  224. end;
  225. end;
  226. LookUp:=FoundS;
  227. end;
  228. function FPTranslateCodeTemplate(var Shortcut: string; ALines: PUnsortedStringCollection): boolean;
  229. var OK: boolean;
  230. P: PCodeTemplate;
  231. CompleteName: String;
  232. Idx : sw_integer;
  233. begin
  234. OK:=Assigned(CodeTemplates);
  235. if OK then
  236. begin
  237. P:=CodeTemplates^.SearchByShortCut(ShortCut);
  238. if not assigned(P) then
  239. begin
  240. CompleteName:=CodeTemplates^.Lookup(ShortCut,false,Idx);
  241. if Idx<>-1 then
  242. begin
  243. P:=CodeTemplates^.At(Idx);
  244. ShortCut:=CompleteName;
  245. end;
  246. end;
  247. OK:=Assigned(P);
  248. if OK then
  249. P^.GetText(ALines);
  250. end;
  251. FPTranslateCodeTemplate:=OK;
  252. end;
  253. procedure InitCodeTemplates;
  254. begin
  255. if Assigned(CodeTemplates) then Exit;
  256. New(CodeTemplates, Init(10,10));
  257. end;
  258. function LoadCodeTemplates(var S: TStream): boolean;
  259. var C: PCodeTemplateCollection;
  260. OK: boolean;
  261. begin
  262. New(C, Load(S));
  263. OK:=Assigned(C) and (S.Status=stOk);
  264. if OK then
  265. begin
  266. if Assigned(CodeTemplates) then Dispose(CodeTemplates, Done);
  267. CodeTemplates:=C;
  268. end
  269. else
  270. if Assigned(C) then
  271. Dispose(C, Done);
  272. LoadCodeTemplates:=OK;
  273. end;
  274. function StoreCodeTemplates(var S: TStream): boolean;
  275. var OK: boolean;
  276. begin
  277. OK:=Assigned(CodeTemplates);
  278. if OK then
  279. begin
  280. CodeTemplates^.Store(S);
  281. OK:=OK and (S.Status=stOK);
  282. end;
  283. StoreCodeTemplates:=OK;
  284. end;
  285. procedure DoneCodeTemplates;
  286. begin
  287. if Assigned(CodeTemplates) then Dispose(CodeTemplates, Done);
  288. CodeTemplates:=nil;
  289. end;
  290. function TCodeTemplateListBox.GetText(Item,MaxLen: Sw_Integer): String;
  291. var P: PCodeTemplate;
  292. begin
  293. P:=List^.At(Item);
  294. GetText:=P^.GetShortCut;
  295. end;
  296. constructor TCodeTemplateDialog.Init(const ATitle: string; ATemplate: PCodeTemplate);
  297. var R,R2,R3: TRect;
  298. begin
  299. R.Assign(0,0,52,15);
  300. inherited Init(R,ATitle);
  301. Template:=ATemplate;
  302. GetExtent(R); R.Grow(-3,-2); R3.Copy(R);
  303. Inc(R.A.Y); R.B.Y:=R.A.Y+1; R.B.X:=R.A.X+46;
  304. New(ShortCutIL, Init(R, 128)); Insert(ShortcutIL);
  305. ShortCutIL^.SetValidator(New(PFilterValidator,Init(NumberChars+AlphaChars)));
  306. R2.Copy(R); R2.Move(-1,-1);
  307. Insert(New(PLabel, Init(R2, label_codetemplate_shortcut, ShortcutIL)));
  308. R.Move(0,3); R.B.Y:=R.A.Y+8;
  309. New(CodeMemo, Init(R, nil,nil,nil{,4096 does not compile !! }));
  310. Insert(CodeMemo);
  311. R2.Copy(R); R2.Move(-1,-1); R2.B.Y:=R2.A.Y+1;
  312. Insert(New(PLabel, Init(R2, label_codetemplate_content, CodeMemo)));
  313. InsertButtons(@Self);
  314. ShortcutIL^.Select;
  315. end;
  316. function TCodeTemplateDialog.Execute: Word;
  317. var R: word;
  318. S: string;
  319. L: PUnsortedStringCollection;
  320. begin
  321. New(L, Init(10,10));
  322. S:=Template^.GetShortCut;
  323. Template^.GetText(L);
  324. ShortcutIL^.SetData(S);
  325. CodeMemo^.SetContent(L);
  326. R:=inherited Execute;
  327. if R=cmOK then
  328. begin
  329. L^.FreeAll;
  330. ShortcutIL^.GetData(S);
  331. CodeMemo^.GetContent(L);
  332. Template^.SetShortcut(S);
  333. Template^.SetText(L);
  334. end;
  335. Execute:=R;
  336. end;
  337. constructor TCodeTemplatesDialog.Init(ASelMode: boolean;const AShortCut : string);
  338. function B2I(B: boolean; I1,I2: longint): longint;
  339. begin
  340. if B then B2I:=I1 else B2I:=I2;
  341. end;
  342. var R,R2,R3: TRect;
  343. SB: PScrollBar;
  344. begin
  345. R.Assign(0,0,46,20);
  346. inherited Init(R,'Code Templates');
  347. HelpCtx:=hcCodeTemplateOptions;
  348. SelMode:=ASelMode;
  349. GetExtent(R); R.Grow(-3,-2); Inc(R.A.Y); R.B.Y:=R.A.Y+10;
  350. R3.Copy(R); Dec(R.B.X,12);
  351. R2.Copy(R); R2.Move(1,0); R2.A.X:=R2.B.X-1;
  352. New(SB, Init(R2)); Insert(SB);
  353. New(CodeTemplatesLB, Init(R,1,SB));
  354. Insert(CodeTemplatesLB);
  355. if AShortCut<>'' then
  356. begin
  357. If assigned(CodeTemplates) then
  358. CodeTemplates^.Lookup(AShortCut,true,StartIdx)
  359. else
  360. StartIdx:=-1;
  361. end;
  362. R2.Copy(R); R2.Move(0,-1); R2.B.Y:=R2.A.Y+1; Dec(R2.A.X);
  363. Insert(New(PLabel, Init(R2, label_codetemplate_templates, CodeTemplatesLB)));
  364. GetExtent(R); R.Grow(-2,-2); Inc(R.A.Y,12);
  365. R2.Copy(R); R2.Move(1,0); R2.A.X:=R2.B.X-1;
  366. New(SB, Init(R2)); Insert(SB);
  367. New(TemplateViewer, Init(R,nil,SB,nil{,4096 does not compile }));
  368. with TemplateViewer^ do
  369. begin
  370. ReadOnly:=true;
  371. AlwaysShowScrollBars:=true;
  372. end;
  373. Insert(TemplateViewer);
  374. R.Copy(R3); R.A.X:=R.B.X-10; R.B.Y:=R.A.Y+2;
  375. Insert(New(PButton, Init(R, button_OK, cmOK, B2I(SelMode,bfDefault,bfNormal))));
  376. R.Move(0,2);
  377. Insert(New(PButton, Init(R, button_Edit, cmEditItem, B2I(SelMode,bfNormal,bfDefault) )));
  378. R.Move(0,2);
  379. Insert(New(PButton, Init(R, button_New, cmAddItem, bfNormal)));
  380. R.Move(0,2);
  381. Insert(New(PButton, Init(R, button_Delete, cmDeleteItem, bfNormal)));
  382. R.Move(0,2);
  383. Insert(New(PButton, Init(R, button_Cancel, cmCancel, bfNormal)));
  384. SelectNext(false);
  385. end;
  386. procedure TCodeTemplatesDialog.Update;
  387. var C: PUnsortedStringCollection;
  388. begin
  389. if CodeTemplatesLB^.Range=0 then C:=nil else
  390. C:=PCodeTemplate(CodeTemplatesLB^.GetFocusedItem)^.Text;
  391. TemplateViewer^.SetContent(C);
  392. ReDraw;
  393. end;
  394. function TCodeTemplatesDialog.GetSelectedShortCut: string;
  395. var S: string;
  396. begin
  397. if CodeTemplatesLB^.Range=0 then S:='' else
  398. S:=GetStr(PCodeTemplate(CodeTemplatesLB^.GetFocusedItem)^.ShortCut);
  399. GetSelectedShortCut:=S;
  400. end;
  401. procedure TCodeTemplatesDialog.HandleEvent(var Event: TEvent);
  402. var DontClear: boolean;
  403. begin
  404. case Event.What of
  405. evKeyDown :
  406. begin
  407. DontClear:=false;
  408. case Event.KeyCode of
  409. kbIns :
  410. Message(@Self,evCommand,cmAddItem,nil);
  411. kbDel :
  412. Message(@Self,evCommand,cmDeleteItem,nil);
  413. else DontClear:=true;
  414. end;
  415. if DontClear=false then ClearEvent(Event);
  416. end;
  417. evBroadcast :
  418. case Event.Command of
  419. cmListItemSelected :
  420. if Event.InfoPtr=pointer(CodeTemplatesLB) then
  421. Message(@Self,evCommand,cmEditItem,nil);
  422. cmListFocusChanged :
  423. if Event.InfoPtr=pointer(CodeTemplatesLB) then
  424. Message(@Self,evBroadcast,cmUpdate,nil);
  425. cmUpdate :
  426. Update;
  427. end;
  428. evCommand :
  429. begin
  430. DontClear:=false;
  431. case Event.Command of
  432. cmAddItem : Add;
  433. cmDeleteItem : Delete;
  434. cmEditItem : Edit;
  435. else DontClear:=true;
  436. end;
  437. if DontClear=false then ClearEvent(Event);
  438. end;
  439. end;
  440. inherited HandleEvent(Event);
  441. end;
  442. function TCodeTemplatesDialog.Execute: Word;
  443. var R: word;
  444. P: PCodeTemplate;
  445. C: PCodeTemplateCollection;
  446. L: PUnsortedStringCollection;
  447. I: integer;
  448. begin
  449. New(C, Init(10,20));
  450. if Assigned(CodeTemplates) then
  451. for I:=0 to CodeTemplates^.Count-1 do
  452. begin
  453. P:=CodeTemplates^.At(I);
  454. New(L, Init(10,50));
  455. P^.GetText(L);
  456. C^.Insert(New(PCodeTemplate, Init(P^.GetShortCut,L)));
  457. Dispose(L, Done);
  458. end;
  459. CodeTemplatesLB^.NewList(C);
  460. if StartIdx<>-1 then
  461. CodeTemplatesLB^.SetFocusedItem(CodeTemplates^.At(StartIdx));
  462. Update;
  463. R:=inherited Execute;
  464. if R=cmOK then
  465. begin
  466. if Assigned(CodeTemplates) then Dispose(CodeTemplates, Done);
  467. CodeTemplates:=C;
  468. end
  469. else
  470. Dispose(C, Done);
  471. Execute:=R;
  472. end;
  473. procedure TCodeTemplatesDialog.Add;
  474. var P,P2: PCodeTemplate;
  475. IC: boolean;
  476. S: string;
  477. L: PUnsortedStringCollection;
  478. Cmd: word;
  479. CanExit: boolean;
  480. begin
  481. New(L, Init(10,10));
  482. IC:=CodeTemplatesLB^.Range=0;
  483. if IC=false then
  484. begin
  485. P:=CodeTemplatesLB^.List^.At(CodeTemplatesLB^.Focused);
  486. P^.GetParams(S,L);
  487. end
  488. else
  489. begin
  490. S:='';
  491. end;
  492. New(P, Init(S,L));
  493. repeat
  494. Cmd:=Application^.ExecuteDialog(New(PCodeTemplateDialog, Init(dialog_newtemplate,P)), nil);
  495. CanExit:=(Cmd<>cmOK);
  496. if CanExit=false then
  497. begin
  498. P2:=PCodeTemplateCollection(CodeTemplatesLB^.List)^.SearchByShortCut(P^.GetShortCut);
  499. CanExit:=(Assigned(P2)=false);
  500. if CanExit=false then
  501. begin
  502. ClearFormatParams; AddFormatParamStr(P^.GetShortCut);
  503. ErrorBox(msg_codetemplate_alreadyinlist,@FormatParams);
  504. end;
  505. end;
  506. until CanExit;
  507. if Cmd=cmOK then
  508. begin
  509. CodeTemplatesLB^.List^.Insert(P);
  510. CodeTemplatesLB^.SetRange(CodeTemplatesLB^.List^.Count);
  511. CodeTemplatesLB^.SetFocusedItem(P);
  512. Update;
  513. end
  514. else
  515. Dispose(P, Done);
  516. Dispose(L, Done);
  517. end;
  518. procedure TCodeTemplatesDialog.Edit;
  519. var P,O,P2: PCodeTemplate;
  520. I: sw_integer;
  521. S: string;
  522. L: PUnsortedStringCollection;
  523. Cmd: word;
  524. CanExit: boolean;
  525. begin
  526. if CodeTemplatesLB^.Range=0 then Exit;
  527. New(L, Init(10,10));
  528. I:=CodeTemplatesLB^.Focused;
  529. O:=CodeTemplatesLB^.List^.At(I);
  530. O^.GetParams(S,L);
  531. P:=New(PCodeTemplate, Init(S, L));
  532. repeat
  533. Cmd:=Application^.ExecuteDialog(New(PCodeTemplateDialog, Init(dialog_modifytemplate,P)), nil);
  534. CanExit:=(Cmd<>cmOK);
  535. if CanExit=false then
  536. begin
  537. P2:=PCodeTemplateCollection(CodeTemplatesLB^.List)^.SearchByShortCut(P^.GetShortCut);
  538. CanExit:=(Assigned(P2)=false) or (CodeTemplatesLB^.List^.IndexOf(P2)=I);
  539. if CanExit=false then
  540. begin
  541. ClearFormatParams; AddFormatParamStr(P^.GetShortCut);
  542. ErrorBox(msg_codetemplate_alreadyinlist,@FormatParams);
  543. end;
  544. end;
  545. until CanExit;
  546. if Cmd=cmOK then
  547. begin
  548. with CodeTemplatesLB^ do
  549. begin
  550. List^.AtFree(I); O:=nil;
  551. List^.Insert(P);
  552. SetFocusedItem(P);
  553. end;
  554. Update;
  555. end;
  556. Dispose(L, Done);
  557. end;
  558. procedure TCodeTemplatesDialog.Delete;
  559. begin
  560. if CodeTemplatesLB^.Range=0 then Exit;
  561. CodeTemplatesLB^.List^.AtFree(CodeTemplatesLB^.Focused);
  562. CodeTemplatesLB^.SetRange(CodeTemplatesLB^.List^.Count);
  563. Update;
  564. end;
  565. procedure RegisterCodeTemplates;
  566. begin
  567. {$ifndef NOOBJREG}
  568. RegisterType(RCodeTemplate);
  569. RegisterType(RCodeTemplateCollection);
  570. {$endif}
  571. end;
  572. END.