fpcodtmp.pas 17 KB

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