fpcodcmp.pas 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665
  1. {
  2. $Id$
  3. This file is part of the Free Pascal Integrated Development Environment
  4. Copyright (c) 1998 by Berczi Gabor
  5. Code Complete 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 FPCodCmp; { CodeComplete }
  13. interface
  14. uses Objects,Drivers,Dialogs,
  15. WEditor,WUtils,WViews;
  16. type
  17. PCodeCompleteWordList = ^TCodeCompleteWordList;
  18. TCodeCompleteWordList = object(TTextCollection)
  19. end;
  20. PCodeCompleteDialog = ^TCodeCompleteDialog;
  21. TCodeCompleteDialog = object(TCenterDialog)
  22. constructor Init;
  23. function Execute: Word; virtual;
  24. procedure HandleEvent(var Event: TEvent); virtual;
  25. private
  26. CodeCompleteLB : PAdvancedListBox;
  27. RB : PRadioButtons;
  28. CB : PCheckBoxes;
  29. MinInputL,InputL : PEditorInputLine;
  30. procedure Add;
  31. procedure Edit;
  32. procedure Delete;
  33. end;
  34. function FPCompleteCodeWord(const WordS: string; var Text: string): boolean;
  35. procedure InitCodeComplete;
  36. function LoadCodeComplete(var S: TStream): boolean;
  37. procedure AddStandardUnitsToCodeComplete;
  38. procedure AddAvailableUnitsToCodeComplete(OnlyStandard : boolean);
  39. function StoreCodeComplete(var S: TStream): boolean;
  40. procedure DoneCodeComplete;
  41. const CodeCompleteWords : PCodeCompleteWordList = nil;
  42. type
  43. TCodeCompleteCase = (ccc_unchanged, ccc_lower, ccc_upper, ccc_mixed);
  44. const
  45. CodeCompleteCase : TCodeCompleteCase = ccc_unchanged;
  46. UnitsCodeCompleteWords : PCodeCompleteWordList = nil;
  47. procedure RegisterCodeComplete;
  48. implementation
  49. uses App,Views,MsgBox,Validate,
  50. FVConsts,
  51. systems, BrowCol,
  52. FPSwitch, FPCompil,
  53. FPVars, FPSymbol,
  54. FPConst,FPString,FPViews;
  55. {$ifndef NOOBJREG}
  56. const
  57. RCodeCompleteWordList: TStreamRec = (
  58. ObjType: 14401;
  59. VmtLink: Ofs(TypeOf(TCodeCompleteWordList)^);
  60. Load: @TCodeCompleteWordList.Load;
  61. Store: @TCodeCompleteWordList.Store
  62. );
  63. {$endif}
  64. function FPCompleteCodeWord(const WordS: string; var Text: string): boolean;
  65. var OK: boolean;
  66. CIndex, Index, i : sw_integer;
  67. St, UpWordS : string;
  68. begin
  69. if ShowOnlyUnique then
  70. UpWordS:=UpCaseStr(WordS);
  71. OK:=Assigned(CodeCompleteWords);
  72. if OK then
  73. begin
  74. Text:=CodeCompleteWords^.Lookup(WordS,CIndex);
  75. OK:=(CIndex<>-1) and (length(Text)<>length(WordS));
  76. Index:=-1;
  77. if OK and ShowOnlyUnique and (CIndex<CodeCompleteWords^.Count-1) then
  78. begin
  79. St:=PString(CodeCompleteWords^.At(CIndex+1))^;
  80. if (UpCaseStr(Copy(St,1,length(WordS)))=UpWordS) then
  81. begin
  82. {if UpCase(st[Length(UpWordS)+1])<>Upcase(Text[Length(UpWordS)+1]) then}
  83. begin
  84. Text:='';
  85. FPCompleteCodeWord:=false;
  86. exit;
  87. (* end
  88. else
  89. { only give the common part }
  90. begin
  91. i:=Length(UpWordS)+1;
  92. while (i<=length(st)) and (i<=length(text)) and (UpCase(st[i])=Upcase(Text[i])) do
  93. inc(i);
  94. SetLength(Text,i-1); *)
  95. end;
  96. end;
  97. end;
  98. end;
  99. if (ShowOnlyUnique or not OK) and Assigned(UnitsCodeCompleteWords) then
  100. begin
  101. Text:=UnitsCodeCompleteWords^.Lookup(WordS,Index);
  102. OK:=(Index<>-1) and (length(Text)<>length(WordS));
  103. if ShowOnlyUnique and (Index<UnitsCodeCompleteWords^.Count-1) then
  104. begin
  105. St:=PString(UnitsCodeCompleteWords^.At(Index+1))^;
  106. if UpCaseStr(Copy(St,1,length(WordS)))=UpWordS then
  107. begin
  108. {if UpCase(st[Length(UpWordS)+1])<>Upcase(Text[Length(UpWordS)+1]) then}
  109. begin
  110. Text:='';
  111. FPCompleteCodeWord:=false;
  112. exit;
  113. (* end
  114. else
  115. { only give the common part }
  116. begin
  117. i:=Length(UpWordS)+1;
  118. while (i<=length(st)) and (i<=length(text)) and (UpCase(st[i])=Upcase(Text[i])) do
  119. inc(i);
  120. SetLength(Text,i-1); *)
  121. end;
  122. end;
  123. end;
  124. end;
  125. if ShowOnlyUnique and (Index<>-1) and (CIndex<>-1) then
  126. begin
  127. {St:=PString(CodeCompleteWords^.At(CIndex+1))^;
  128. Was wrong, CIndex+1 could be above count => collection.error
  129. generated RTE 213
  130. if UpCase(st[Length(UpWordS)+1])<>Upcase(Text[Length(UpWordS)+1]) then}
  131. begin
  132. Text:='';
  133. FPCompleteCodeWord:=false;
  134. exit;
  135. (* end
  136. else
  137. { only give the common part }
  138. begin
  139. i:=Length(UpWordS)+1;
  140. while (i<=length(st)) and (i<=length(text)) and (UpCase(st[i])=Upcase(Text[i])) do
  141. inc(i);
  142. SetLength(Text,i-1); *)
  143. end;
  144. end;
  145. if OK=false then Text:=''
  146. else case CodeCompleteCase of
  147. ccc_upper : Text:=UpcaseStr(Text);
  148. ccc_lower : Text:=LowcaseStr(Text);
  149. ccc_mixed : Text:=UpCase(Text[1])+LowCaseStr(Copy(Text,2,High(Text)));
  150. end;
  151. FPCompleteCodeWord:=OK;
  152. end;
  153. procedure InitCodeComplete;
  154. var I:integer;
  155. S: string;
  156. begin
  157. if Assigned(CodeCompleteWords) then
  158. Dispose(CodeCompleteWords, Done);
  159. New(CodeCompleteWords, Init(10,10));
  160. for I:=0 to GetReservedWordCount-1 do
  161. begin
  162. S:=LowCaseStr(GetReservedWord(I));
  163. if length(S)>=CodeCompleteMinLen then
  164. CodeCompleteWords^.Insert(NewStr(S));
  165. end;
  166. {
  167. there should be also a user front-end for customizing CodeComplete !
  168. any volunteers to implement? ;) - Gabor
  169. }
  170. end;
  171. procedure AddAvailableUnitsToCodeComplete(OnlyStandard : boolean);
  172. var
  173. I : sw_integer;
  174. Overflow: boolean;
  175. Level : longint;
  176. UpStandardUnits : string;
  177. procedure InsertInS(P: PSymbol); {$ifndef FPC}far;{$endif}
  178. procedure InsertItemsInS(P: PSymbolCollection);
  179. var I: Sw_integer;
  180. begin
  181. for I:=0 to P^.Count-1 do
  182. InsertInS(P^.At(I));
  183. end;
  184. Var
  185. st : string;
  186. begin
  187. Inc(level);
  188. if UnitsCodeCompleteWords^.Count=MaxCollectionSize then
  189. begin Overflow:=true; Exit; end;
  190. st:=P^.GetName;
  191. if Length(st)>=CodeCompleteMinLen then
  192. if not ((level=1) and OnlyStandard and (st=UpCaseStr(CodeCompleteUnitName))) then
  193. UnitsCodeCompleteWords^.Insert(NewStr(Lowcasestr(st)));
  194. { this is wrong because it inserted args or locals of proc
  195. in the globals list !! PM}
  196. if (P^.Items<>nil) and (level=1) and
  197. ((not OnlyStandard or (Pos(P^.GetName+',',UpStandardUnits)>0) or
  198. { don't exclude system unit ... }
  199. (Pos('SYS',P^.GetName)>0))) then
  200. InsertItemsInS(P^.Items);
  201. Dec(level);
  202. end;
  203. begin
  204. if OnlyStandard then
  205. UpStandardunits:=UpCaseStr(StandardUnits)+',';
  206. if IsSymbolInfoAvailable then
  207. begin
  208. if Assigned(UnitsCodeCompleteWords) then
  209. begin
  210. Dispose(UnitsCodeCompleteWords,done);
  211. UnitsCodeCompleteWords:=nil;
  212. end;
  213. New(UnitsCodeCompleteWords, Init(10,10));
  214. level:=0;
  215. Overflow:=false;
  216. BrowCol.Modules^.ForEach(@InsertInS);
  217. { if Overflow then
  218. WarningBox(msg_toomanysymbolscantdisplayall,nil); }
  219. end;
  220. end;
  221. procedure AddStandardUnitsToCodeComplete;
  222. var
  223. HiddenSource : PSourceWindow;
  224. R : TRect;
  225. StoreBrowserSwitchesConfig : string;
  226. begin
  227. Desktop^.GetExtent(R);
  228. New(HiddenSource,init(R,'*'));
  229. HiddenSource^.NoNameCount:=0;
  230. HiddenSource^.UpdateTitle;
  231. HiddenSource^.Hide;
  232. CompilingHiddenFile:=HiddenSource;
  233. { compile a dummy file to get symbol info }
  234. with HiddenSource^.Editor^ do
  235. begin
  236. FileName:=CodeCompleteUnitName+'.pp';
  237. Addline('unit '+CodeCompleteUnitName+';');
  238. Addline('interface');
  239. if StandardUnits<>'' then
  240. begin
  241. AddLine('uses');
  242. Addline(StandardUnits);
  243. Addline(' ;');
  244. end;
  245. Addline('implementation');
  246. Addline('end.');
  247. SetModified(true);
  248. // SaveFile;
  249. end;
  250. StoreBrowserSwitchesConfig:=BrowserSwitches^.GetCurrSelParam;
  251. BrowserSwitches^.ReadItemsCfg('+');
  252. DoCompile(cCompile);
  253. BrowserSwitches^.SetCurrSelParam(StoreBrowserSwitchesConfig);
  254. AddAvailableUnitsToCodeComplete(true);
  255. { Now add the interface declarations to the Code Complete list }
  256. CompilingHiddenFile:=nil;
  257. Dispose(HiddenSource,Done);
  258. end;
  259. function LoadCodeComplete(var S: TStream): boolean;
  260. var C: PCodeCompleteWordList;
  261. OK: boolean;
  262. NewCodeCompleteMinLen : byte;
  263. NewUseStandardUnitsInCodeComplete,
  264. NewUseAllUnitsInCodeComplete,
  265. NewShowOnlyUnique : boolean;
  266. NewCodeCompleteCase : TCodeCompleteCase;
  267. StPtr : PString;
  268. begin
  269. New(C, Load(S));
  270. OK:=Assigned(C) and (S.Status=stOk);
  271. if OK then
  272. begin
  273. if Assigned(CodeCompleteWords) then Dispose(CodeCompleteWords, Done);
  274. CodeCompleteWords:=C;
  275. S.Read(NewCodeCompleteCase,Sizeof(TCodeCompleteCase));
  276. OK:=(S.Status=stOk);
  277. if OK then
  278. CodeCompleteCase:=NewCodeCompleteCase;
  279. { Old version of Code complete, also OK PM }
  280. if not OK or (S.getPos=S.getSize) then
  281. begin
  282. LoadCodeComplete:=OK;
  283. exit;
  284. end;
  285. if S.Status=stOK then
  286. S.Read(NewUseStandardUnitsInCodeComplete,Sizeof(UseStandardUnitsInCodeComplete));
  287. if S.Status=stOK then
  288. UseStandardUnitsInCodeComplete:=NewUseStandardUnitsInCodeComplete;
  289. if S.Status=stOK then
  290. S.Read(NewUseAllUnitsInCodeComplete,Sizeof(UseAllUnitsInCodeComplete));
  291. if S.Status=stOK then
  292. UseAllUnitsInCodeComplete:=NewUseAllUnitsInCodeComplete;
  293. if S.Status=stOK then
  294. S.Read(NewShowOnlyUnique,Sizeof(ShowOnlyUnique));
  295. if S.Status=stOK then
  296. ShowOnlyUnique:=NewShowOnlyUnique;
  297. if S.Status=stOK then
  298. S.Read(NewCodeCompleteMinLen,Sizeof(CodeCompleteMinLen));
  299. if S.Status=stOK then
  300. CodeCompleteMinLen:=NewCodeCompleteMinLen;
  301. if S.Status=stOK then
  302. StPtr:=S.ReadStr
  303. else
  304. StPtr:=nil;
  305. if (S.Status=stOK) then
  306. StandardUnits:=GetStr(StPtr);
  307. if assigned(StPtr) then
  308. FreeMem(StPtr,Length(StandardUnits)+1);
  309. OK:=S.Status=stOK;
  310. end
  311. else
  312. if Assigned(C) then
  313. Dispose(C, Done);
  314. LoadCodeComplete:=OK;
  315. end;
  316. function StoreCodeComplete(var S: TStream): boolean;
  317. var OK: boolean;
  318. begin
  319. OK:=Assigned(CodeCompleteWords);
  320. if OK then
  321. begin
  322. CodeCompleteWords^.Store(S);
  323. S.Write(CodeCompleteCase,Sizeof(TCodeCompleteCase));
  324. { New fields added }
  325. S.Write(UseStandardUnitsInCodeComplete,Sizeof(UseStandardUnitsInCodeComplete));
  326. S.Write(UseAllUnitsInCodeComplete,Sizeof(UseAllUnitsInCodeComplete));
  327. S.Write(ShowOnlyUnique,Sizeof(ShowOnlyUnique));
  328. S.Write(CodeCompleteMinLen,Sizeof(CodeCompleteMinLen));
  329. S.WriteStr(@StandardUnits);
  330. OK:=OK and (S.Status=stOK);
  331. end;
  332. StoreCodeComplete:=OK;
  333. end;
  334. procedure DoneCodeComplete;
  335. begin
  336. if Assigned(CodeCompleteWords) then
  337. begin
  338. Dispose(CodeCompleteWords, Done);
  339. CodeCompleteWords:=nil;
  340. end;
  341. if Assigned(UnitsCodeCompleteWords) then
  342. begin
  343. Dispose(UnitsCodeCompleteWords,done);
  344. UnitsCodeCompleteWords:=nil;
  345. end;
  346. end;
  347. constructor TCodeCompleteDialog.Init;
  348. var R,R2,R3: TRect;
  349. Items: PSItem;
  350. SB: PScrollBar;
  351. begin
  352. R.Assign(0,0,50,22);
  353. inherited Init(R,dialog_codecomplete);
  354. HelpCtx:=hcCodeCompleteOptions;
  355. { name list dialog }
  356. GetExtent(R); R.Grow(-3,-2); Inc(R.A.Y); R3.Copy(R); Dec(R.B.X,12);
  357. Dec(R.B.Y,7);
  358. R2.Copy(R); R2.Move(1,0); R2.A.X:=R2.B.X-1;
  359. New(SB, Init(R2)); Insert(SB);
  360. New(CodeCompleteLB, Init(R,1,SB));
  361. Insert(CodeCompleteLB);
  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_codecomplete_keywords, CodeCompleteLB)));
  364. { Case choice }
  365. R.Copy(R3); Dec(R.B.Y,2); R.A.Y:=R.B.Y-4; Inc(R.A.X); R.B.X:=R.A.X+15;
  366. Items:=NewSItem('Unc~h~anged',
  367. NewSItem('~L~ower',
  368. NewSItem('~U~pper',
  369. NewSItem('~M~ixed',nil))));
  370. RB:=New(PRadioButtons,Init(R,Items));
  371. RB^.SetData(ord(CodeCompleteCase));
  372. R2.Copy(R); R2.Move(0,-1); R2.B.Y:=R2.A.Y+1; Dec(R2.A.X);
  373. Insert(New(PLabel, Init(R2, 'Case handling', RB)));
  374. Insert(RB);
  375. { Mininum length inputline }
  376. R.Copy(R3); R.A.Y:=R.B.Y-7;R.B.Y:=R.A.Y+1; Dec(R.B.X); R.A.X:=R.B.X -5;
  377. New(MinInputL, Init(R,5));
  378. MinInputL^.SetValidator(New(PRangeValidator, Init(1,255)));
  379. Insert(MinInputL);
  380. R2.Copy(R); R2.A.X:=20;Dec(R2.B.X,5);
  381. Insert(New(PLabel, Init(R2, 'Min. length', MinInputL)));
  382. { Standard/all units booleans }
  383. Items:=nil;
  384. Items:=NewSItem('Add standard units', Items);
  385. Items:=NewSItem('Add all units', Items);
  386. Items:=NewSItem('Show only unique', Items);
  387. R.Copy(R3); R.A.Y:=R.B.Y-5;R.B.Y:=R.A.Y+3; Inc(R.A.X,18); Dec(R.B.X);
  388. New(CB, Init(R, Items));
  389. Insert(CB);
  390. R2.Copy(R); R2.Move(0,-1); R2.B.Y:=R2.A.Y+1; Dec(R2.A.X);
  391. Insert(New(PLabel, Init(R2, 'Unit handling', CB)));
  392. R2.Copy(R); R2.Move(0,-1); R2.B.Y:=R2.A.Y+1;
  393. If ShowOnlyUnique then
  394. CB^.Press(0);
  395. If UseAllUnitsInCodeComplete then
  396. CB^.Press(1);
  397. If UseStandardUnitsInCodeComplete then
  398. CB^.Press(2);
  399. { Standard unit name boolean }
  400. R.Copy(R3); R.A.Y:=R.B.Y-1; Inc(R.A.X); Dec(R.B.X);
  401. New(InputL,Init(R,255));
  402. Insert(InputL);
  403. InputL^.SetValidator(New(PFilterValidator,Init(NumberChars+AlphaChars+[','])));
  404. R2.Copy(R); R2.Move(0,-1); R2.B.Y:=R2.A.Y+1; Dec(R2.A.X);R2.B.X:=R2.A.X+25;
  405. Insert(New(PLabel, Init(R2, '~S~tandard unit list', InputL)));
  406. R.Copy(R3); R.A.X:=R.B.X-10; R.B.Y:=R.A.Y+2;
  407. Insert(New(PButton, Init(R, button_OK, cmOK, bfNormal)));
  408. R.Move(0,2);
  409. Insert(New(PButton, Init(R, button_Edit, cmEditItem, bfDefault)));
  410. R.Move(0,2);
  411. Insert(New(PButton, Init(R, button_New, cmAddItem, bfNormal)));
  412. R.Move(0,2);
  413. Insert(New(PButton, Init(R, button_Delete, cmDeleteItem, bfNormal)));
  414. R.Move(0,2);
  415. Insert(New(PButton, Init(R, button_Cancel, cmCancel, bfNormal)));
  416. SelectNext(false);
  417. end;
  418. procedure TCodeCompleteDialog.HandleEvent(var Event: TEvent);
  419. var DontClear: boolean;
  420. begin
  421. case Event.What of
  422. evKeyDown :
  423. begin
  424. DontClear:=false;
  425. case Event.KeyCode of
  426. kbIns :
  427. Message(@Self,evCommand,cmAddItem,nil);
  428. kbDel :
  429. Message(@Self,evCommand,cmDeleteItem,nil);
  430. else DontClear:=true;
  431. end;
  432. if DontClear=false then ClearEvent(Event);
  433. end;
  434. evBroadcast :
  435. case Event.Command of
  436. cmListItemSelected :
  437. if Event.InfoPtr=pointer(CodeCompleteLB) then
  438. Message(@Self,evCommand,cmEditItem,nil);
  439. end;
  440. evCommand :
  441. begin
  442. DontClear:=false;
  443. case Event.Command of
  444. cmAddItem : Add;
  445. cmDeleteItem : Delete;
  446. cmEditItem : Edit;
  447. else DontClear:=true;
  448. end;
  449. if DontClear=false then ClearEvent(Event);
  450. end;
  451. end;
  452. inherited HandleEvent(Event);
  453. end;
  454. function TCodeCompleteDialog.Execute: Word;
  455. var R: word;
  456. C: PCodeCompleteWordList;
  457. NewVal, I: integer;
  458. NewValStr : string;
  459. begin
  460. New(C, Init(10,20));
  461. if Assigned(CodeCompleteWords) then
  462. for I:=0 to CodeCompleteWords^.Count-1 do
  463. C^.Insert(NewStr(GetStr(CodeCompleteWords^.At(I))));
  464. CodeCompleteLB^.NewList(C);
  465. InputL^.SetData(StandardUnits);
  466. NewValStr:=IntToStr(CodeCompleteMinLen);
  467. MinInputL^.SetData(NewValStr);
  468. R:=inherited Execute;
  469. if R=cmOK then
  470. begin
  471. if Assigned(CodeCompleteWords) then Dispose(CodeCompleteWords, Done);
  472. CodeCompleteWords:=C;
  473. CodeCompleteCase:=TCodeCompleteCase(RB^.Value);
  474. MinInputL^.GetData(NewValStr);
  475. NewVal:=StrToInt(NewValStr);
  476. if (NewVal>0) and (NewVal<>CodeCompleteMinLen) then
  477. begin
  478. CodeCompleteMinLen:=NewVal;
  479. InitCodeComplete;
  480. end;
  481. ShowOnlyUnique:=CB^.Mark(0);
  482. UseAllUnitsInCodeComplete:=CB^.Mark(1);
  483. UseStandardUnitsInCodeComplete:=CB^.Mark(2);
  484. if UseStandardUnitsInCodeComplete and (not UseAllUnitsInCodeComplete or not assigned(UnitsCodeCompleteWords)) and
  485. ((StandardUnits<>GetStr(InputL^.Data)) or not assigned(UnitsCodeCompleteWords)) then
  486. begin
  487. InputL^.GetData(StandardUnits);
  488. AddStandardUnitsToCodeComplete;
  489. end
  490. else
  491. InputL^.GetData(StandardUnits);
  492. end
  493. else
  494. Dispose(C, Done);
  495. Execute:=R;
  496. end;
  497. procedure TCodeCompleteDialog.Add;
  498. var IC: boolean;
  499. S: string;
  500. P: PString;
  501. Cmd: word;
  502. CanExit: boolean;
  503. I: sw_integer;
  504. begin
  505. IC:=CodeCompleteLB^.Range=0;
  506. if IC=false then
  507. S:=GetStr(CodeCompleteLB^.List^.At(CodeCompleteLB^.Focused))
  508. else
  509. S:='';
  510. repeat
  511. Cmd:=InputBox(dialog_codecomplete_add,label_codecomplete_add_keyword,S,255);
  512. CanExit:=Cmd<>cmOK;
  513. if CanExit=false then
  514. begin
  515. CanExit:=PCodeCompleteWordList(CodeCompleteLB^.List)^.Search(@S,I)=false;
  516. if CanExit=false then
  517. begin
  518. ClearFormatParams; AddFormatParamStr(S);
  519. ErrorBox(msg_codecomplete_alreadyinlist,@FormatParams);
  520. end;
  521. end;
  522. until CanExit;
  523. if Cmd=cmOK then
  524. begin
  525. P:=NewStr(S);
  526. with CodeCompleteLB^ do
  527. begin
  528. List^.Insert(P);
  529. SetRange(List^.Count);
  530. SetFocusedItem(P);
  531. end;
  532. ReDraw;
  533. end;
  534. end;
  535. procedure TCodeCompleteDialog.Edit;
  536. var S: string;
  537. I,T: sw_integer;
  538. Cmd: word;
  539. CanExit: boolean;
  540. P: PString;
  541. begin
  542. if CodeCompleteLB^.Range=0 then Exit;
  543. I:=CodeCompleteLB^.Focused;
  544. S:=GetStr(CodeCompleteLB^.List^.At(I));
  545. repeat
  546. Cmd:=InputBox(dialog_codecomplete_edit,label_codecomplete_edit_keyword,S,255);
  547. CanExit:=Cmd<>cmOK;
  548. if CanExit=false then
  549. begin
  550. CanExit:=PCodeCompleteWordList(CodeCompleteLB^.List)^.Search(@S,T)=false;
  551. CanExit:=CanExit or (T=I);
  552. if CanExit=false then
  553. begin
  554. ClearFormatParams; AddFormatParamStr(S);
  555. ErrorBox(msg_codecomplete_alreadyinlist,@FormatParams);
  556. end;
  557. end;
  558. until CanExit;
  559. if Cmd=cmOK then
  560. begin
  561. P:=NewStr(S);
  562. with CodeCompleteLB^ do
  563. begin
  564. List^.AtFree(I);
  565. List^.Insert(P);
  566. SetFocusedItem(P);
  567. end;
  568. ReDraw;
  569. end;
  570. end;
  571. procedure TCodeCompleteDialog.Delete;
  572. begin
  573. if CodeCompleteLB^.Range=0 then Exit;
  574. CodeCompleteLB^.List^.AtFree(CodeCompleteLB^.Focused);
  575. CodeCompleteLB^.SetRange(CodeCompleteLB^.List^.Count);
  576. ReDraw;
  577. end;
  578. procedure RegisterCodeComplete;
  579. begin
  580. {$ifndef NOOBJREG}
  581. RegisterType(RCodeCompleteWordList);
  582. {$endif}
  583. end;
  584. END.
  585. {
  586. $Log$
  587. Revision 1.14 2004-11-08 20:28:26 peter
  588. * Breakpoints are now deleted when removed from source, disabling is
  589. still possible from the breakpoint list
  590. * COMPILER_1_0, FVISION, GABOR defines removed, only support new
  591. FV and 1.9.x compilers
  592. * Run directory added to Run menu
  593. * Useless programinfo window removed
  594. Revision 1.13 2004/03/04 05:37:14 pierre
  595. * fix a possibly uninitiated var
  596. Revision 1.12 2002/12/18 01:19:20 pierre
  597. + Use TEditorInputLine instead of TInputLine
  598. Revision 1.11 2002/09/26 13:00:41 pierre
  599. * avoid RTE 213
  600. Revision 1.10 2002/09/11 13:12:42 pierre
  601. * fix CodeComplete loading and use a unit for standard units code complete
  602. Revision 1.9 2002/09/09 06:53:54 pierre
  603. * avoid to save file used by codecomplete
  604. Revision 1.8 2002/09/09 06:22:45 pierre
  605. * get it to load old and new desktops
  606. }