fptools.pas 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725
  1. {
  2. $Id$
  3. This file is part of the Free Pascal Integrated Development Environment
  4. Copyright (c) 1998 by Berczi Gabor
  5. Tool support for the IDE
  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 FPTools;
  13. interface
  14. uses Objects,Drivers,Dialogs,Validate,
  15. FPViews;
  16. type
  17. PTool = ^TTool;
  18. TTool = object(TObject)
  19. constructor Init(const ATitle, AProgramPath, ACommandLine: string; AHotKey: word);
  20. function GetTitle: string; virtual;
  21. procedure GetParams(var ATitle, AProgramPath, ACommandLine: string; var AHotKey: word); virtual;
  22. procedure SetParams(const ATitle, AProgramPath, ACommandLine: string; const AHotKey: word); virtual;
  23. destructor Done; virtual;
  24. private
  25. Title : PString;
  26. ProgramPath : PString;
  27. CommandLine : PString;
  28. HotKey : word;
  29. end;
  30. PToolCollection = ^TToolCollection;
  31. TToolCollection = object(TCollection)
  32. function At(Index: sw_Integer): PTool;
  33. end;
  34. PToolListBox = ^TToolListBox;
  35. TToolListBox = object(TAdvancedListBox)
  36. function GetText(Item,MaxLen: sw_integer): String; virtual;
  37. end;
  38. PToolParamValidator = ^TToolParamValidator;
  39. TToolParamValidator = object(TValidator)
  40. function IsValid(const S: string): Boolean; virtual;
  41. procedure Error; virtual;
  42. private
  43. ErrorPos: integer;
  44. end;
  45. PToolItemDialog = ^TToolItemDialog;
  46. TToolItemDialog = object(TCenterDialog)
  47. constructor Init(ATool: PTool);
  48. function Execute: Word; virtual;
  49. private
  50. Tool : PTool;
  51. TitleIL : PInputLine;
  52. ProgramIL: PInputLine;
  53. ParamIL : PInputLine;
  54. HotKeyRB : PRadioButtons;
  55. end;
  56. PToolsDialog = ^TToolsDialog;
  57. TToolsDialog = object(TCenterDialog)
  58. constructor Init;
  59. function Execute: Word; virtual;
  60. procedure HandleEvent(var Event: TEvent); virtual;
  61. private
  62. ToolsLB : PToolListBox;
  63. procedure Add;
  64. procedure Edit;
  65. procedure Delete;
  66. end;
  67. procedure InitTools;
  68. function GetToolCount: Sw_integer;
  69. function GetToolName(Idx: Sw_integer): string;
  70. function AddTool(Title, ProgramPath, Params: string; HotKey: word): Sw_integer;
  71. procedure GetToolParams(Idx: Sw_integer; var Title, ProgramPath, Params: string; var HotKey: word);
  72. procedure SetToolParams(Idx: Sw_integer; Title, ProgramPath, Params: string; HotKey: word);
  73. procedure DoneTools;
  74. function GetHotKeyName(Key: word): string;
  75. function ParseToolParams(var Params: string; CheckOnly: boolean): Sw_integer;
  76. implementation
  77. uses Dos,
  78. Commands,Views,App,MsgBox,
  79. FPConst,FPVars,FPUtils;
  80. type
  81. THotKeyDef = record
  82. Name : string[12];
  83. KeyCode : word;
  84. end;
  85. const
  86. HotKeys : array[0..8] of THotKeyDef =
  87. ( (Name : '~U~nassigned' ; KeyCode : kbNoKey ),
  88. { Used for Grep, so it can't be assigned for user tools
  89. (Name : 'Shift+F~2~' ; KeyCode : kbShiftF2 ), }
  90. (Name : 'Shift+F~3~' ; KeyCode : kbShiftF3 ),
  91. (Name : 'Shift+F~4~' ; KeyCode : kbShiftF4 ),
  92. (Name : 'Shift+F~5~' ; KeyCode : kbShiftF5 ),
  93. (Name : 'Shift+F~6~' ; KeyCode : kbShiftF6 ),
  94. (Name : 'Shift+F~7~' ; KeyCode : kbShiftF7 ),
  95. (Name : 'Shift+F~8~' ; KeyCode : kbShiftF8 ),
  96. (Name : 'Shift+F~9~' ; KeyCode : kbShiftF9 ),
  97. (Name : 'Shift+F~1~0' ; KeyCode : kbShiftF10));
  98. Tools : PToolCollection = nil;
  99. function GetHotKeyCount: Sw_integer;
  100. begin
  101. GetHotKeyCount:=ord(High(HotKeys))-ord(Low(HotKeys))+1;
  102. end;
  103. function GetHotKeyNameByIdx(Idx: Sw_integer): string;
  104. begin
  105. GetHotKeyNameByIdx:=HotKeys[Idx].Name;
  106. end;
  107. function HotKeyToIdx(Key: word): Sw_integer;
  108. var Count,I: Sw_integer;
  109. Found: boolean;
  110. begin
  111. Count:=GetHotKeyCount; Found:=false;
  112. I:=0;
  113. while (I<Count) and (Found=false) do
  114. begin
  115. Found:=HotKeys[I].KeyCode=Key;
  116. if Found=false then
  117. Inc(I);
  118. end;
  119. if Found=false then I:=-1;
  120. HotKeyToIdx:=I;
  121. end;
  122. function IdxToHotKey(Idx: Sw_integer): word;
  123. var Count: Sw_integer;
  124. Key: word;
  125. begin
  126. Count:=GetHotKeyCount;
  127. if (0<=Idx) and (Idx<Count) then
  128. Key:=HotKeys[Idx].KeyCode
  129. else
  130. Key:=kbNoKey;
  131. IdxToHotKey:=Key;
  132. end;
  133. function GetHotKeyName(Key: word): string;
  134. var Idx: Sw_integer;
  135. S: string;
  136. begin
  137. Idx:=HotKeyToIdx(Key);
  138. if Idx=0 then S:='' else
  139. if Idx=-1 then S:='???' else
  140. S:=GetHotKeyNameByIdx(Idx);
  141. GetHotKeyName:=S;
  142. end;
  143. constructor TTool.Init(const ATitle, AProgramPath, ACommandLine: string; AHotKey: word);
  144. begin
  145. inherited Init;
  146. SetParams(ATitle,AProgramPath,ACommandLine,AHotKey);
  147. end;
  148. function TTool.GetTitle: string;
  149. begin
  150. GetTitle:=KillTilde(GetStr(Title));
  151. end;
  152. procedure TTool.GetParams(var ATitle, AProgramPath, ACommandLine: string; var AHotKey: word);
  153. begin
  154. ATitle:=GetStr(Title); AProgramPath:=GetStr(ProgramPath);
  155. ACommandLine:=GetStr(CommandLine);
  156. AHotKey:=HotKey;
  157. end;
  158. procedure TTool.SetParams(const ATitle, AProgramPath, ACommandLine: string; const AHotKey: word);
  159. begin
  160. if Title<>nil then DisposeStr(Title); Title:=nil;
  161. if ProgramPath<>nil then DisposeStr(ProgramPath); ProgramPath:=nil;
  162. if CommandLine<>nil then DisposeStr(CommandLine); CommandLine:=nil;
  163. Title:=NewStr(ATitle); ProgramPath:=NewStr(AProgramPath);
  164. CommandLine:=NewStr(ACommandLine);
  165. HotKey:=AHotKey;
  166. end;
  167. destructor TTool.Done;
  168. begin
  169. inherited Done;
  170. if Title<>nil then DisposeStr(Title);
  171. if ProgramPath<>nil then DisposeStr(ProgramPath);
  172. if CommandLine<>nil then DisposeStr(CommandLine);
  173. end;
  174. function TToolCollection.At(Index: sw_Integer): PTool;
  175. begin
  176. At:=inherited At(Index);
  177. end;
  178. function TToolListBox.GetText(Item,MaxLen: sw_integer): String;
  179. var S: string;
  180. P: PTool;
  181. begin
  182. P:=List^.At(Item);
  183. S:=P^.GetTitle;
  184. GetText:=copy(S,1,MaxLen);
  185. end;
  186. procedure InitTools;
  187. begin
  188. if Tools<>nil then DoneTools;
  189. New(Tools, Init(10,20));
  190. end;
  191. function GetToolCount: Sw_integer;
  192. var Count: Sw_integer;
  193. begin
  194. if Tools=nil then Count:=0 else
  195. Count:=Tools^.Count;
  196. GetToolCount:=Count;
  197. end;
  198. function GetToolName(Idx: Sw_integer): string;
  199. var S1,S2: string;
  200. W: word;
  201. begin
  202. GetToolParams(Idx,S1,S2,S2,W);
  203. GetToolName:=KillTilde(S1);
  204. end;
  205. function AddTool(Title, ProgramPath, Params: string; HotKey: word): Sw_integer;
  206. var P: PTool;
  207. begin
  208. if Tools=nil then InitTools;
  209. New(P, Init(Title,ProgramPath,Params,HotKey));
  210. Tools^.Insert(P);
  211. AddTool:=Tools^.IndexOf(P);
  212. end;
  213. procedure GetToolParams(Idx: Sw_integer; var Title, ProgramPath, Params: string; var HotKey: word);
  214. var P: PTool;
  215. begin
  216. P:=Tools^.At(Idx);
  217. P^.GetParams(Title,ProgramPath,Params,HotKey);
  218. end;
  219. procedure SetToolParams(Idx: Sw_integer; Title, ProgramPath, Params: string; HotKey: word);
  220. var P: PTool;
  221. begin
  222. P:=Tools^.At(Idx);
  223. P^.GetParams(Title,ProgramPath,Params,HotKey);
  224. end;
  225. procedure DoneTools;
  226. begin
  227. if Tools<>nil then Dispose(Tools, Done); Tools:=nil;
  228. end;
  229. procedure TToolParamValidator.Error;
  230. begin
  231. MsgParms[1].Long:=ErrorPos;
  232. ErrorBox(^C'Error parsing parameters line at line position %d.',@MsgParms);
  233. end;
  234. function TToolParamValidator.IsValid(const S: string): Boolean;
  235. var P: string;
  236. begin
  237. P:=S;
  238. ErrorPos:=ParseToolParams(P,true);
  239. IsValid:=ErrorPos=0;
  240. end;
  241. constructor TToolItemDialog.Init(ATool: PTool);
  242. var R,R2,R3: TRect;
  243. Items: PSItem;
  244. I,KeyCount: Sw_integer;
  245. begin
  246. KeyCount:=GetHotKeyCount;
  247. R.Assign(0,0,60,Max(3+KeyCount,12));
  248. inherited Init(R,'Modify/New Tool');
  249. Tool:=ATool;
  250. GetExtent(R); R.Grow(-3,-2); R3.Copy(R);
  251. Inc(R.A.Y); R.B.Y:=R.A.Y+1; R.B.X:=R.A.X+36;
  252. New(TitleIL, Init(R, 128)); Insert(TitleIL);
  253. R2.Copy(R); R2.Move(-1,-1); Insert(New(PLabel, Init(R2, '~T~itle', TitleIL)));
  254. R.Move(0,3);
  255. New(ProgramIL, Init(R, 128)); Insert(ProgramIL);
  256. R2.Copy(R); R2.Move(-1,-1); Insert(New(PLabel, Init(R2, 'Program ~p~ath', ProgramIL)));
  257. R.Move(0,3);
  258. New(ParamIL, Init(R, 128)); Insert(ParamIL);
  259. ParamIL^.SetValidator(New(PToolParamValidator, Init));
  260. R2.Copy(R); R2.Move(-1,-1); Insert(New(PLabel, Init(R2, 'Command ~l~ine', ParamIL)));
  261. R.Copy(R3); Inc(R.A.X,38); R.B.Y:=R.A.Y+KeyCount;
  262. Items:=nil;
  263. for I:=KeyCount-1 downto 0 do
  264. Items:=NewSItem(GetHotKeyNameByIdx(I), Items);
  265. New(HotKeyRB, Init(R, Items));
  266. Insert(HotKeyRB);
  267. InsertButtons(@Self);
  268. TitleIL^.Select;
  269. end;
  270. function TToolItemDialog.Execute: Word;
  271. var R: word;
  272. S1,S2,S3: string;
  273. W: word;
  274. L: longint;
  275. begin
  276. Tool^.GetParams(S1,S2,S3,W);
  277. TitleIL^.SetData(S1); ProgramIL^.SetData(S2); ParamIL^.SetData(S3);
  278. L:=HotKeyToIdx(W); if L=-1 then L:=255;
  279. HotKeyRB^.SetData(L);
  280. R:=inherited Execute;
  281. if R=cmOK then
  282. begin
  283. TitleIL^.GetData(S1); ProgramIL^.GetData(S2); ParamIL^.GetData(S3);
  284. HotKeyRB^.GetData(L); W:=IdxToHotKey(L);
  285. Tool^.SetParams(S1,S2,S3,W);
  286. end;
  287. Execute:=R;
  288. end;
  289. constructor TToolsDialog.Init;
  290. var R,R2,R3: TRect;
  291. SB: PScrollBar;
  292. begin
  293. R.Assign(0,0,46,16);
  294. inherited Init(R,'Tools');
  295. GetExtent(R); R.Grow(-3,-2); Inc(R.A.Y); R3.Copy(R); Dec(R.B.X,12);
  296. R2.Copy(R); R2.Move(1,0); R2.A.X:=R2.B.X-1;
  297. New(SB, Init(R2)); Insert(SB);
  298. New(ToolsLB, Init(R,1,SB));
  299. Insert(ToolsLB);
  300. R2.Copy(R); R2.Move(0,-1); R2.B.Y:=R2.A.Y+1; Dec(R2.A.X);
  301. Insert(New(PLabel, Init(R2, '~P~rogram titles', ToolsLB)));
  302. R.Copy(R3); R.A.X:=R.B.X-10; R.B.Y:=R.A.Y+2;
  303. Insert(New(PButton, Init(R, 'O~K~', cmOK, bfNormal)));
  304. R.Move(0,2);
  305. Insert(New(PButton, Init(R, '~E~dit', cmEditItem, bfDefault)));
  306. R.Move(0,2);
  307. Insert(New(PButton, Init(R, '~N~ew', cmAddItem, bfNormal)));
  308. R.Move(0,2);
  309. Insert(New(PButton, Init(R, '~D~elete', cmDeleteItem, bfNormal)));
  310. R.Move(0,2);
  311. Insert(New(PButton, Init(R, 'Cancel', cmCancel, bfNormal)));
  312. SelectNext(false);
  313. end;
  314. procedure TToolsDialog.HandleEvent(var Event: TEvent);
  315. var DontClear: boolean;
  316. begin
  317. case Event.What of
  318. evKeyDown :
  319. begin
  320. DontClear:=false;
  321. case Event.KeyCode of
  322. kbIns :
  323. Message(@Self,evCommand,cmAddItem,nil);
  324. kbDel :
  325. Message(@Self,evCommand,cmDeleteItem,nil);
  326. else DontClear:=true;
  327. end;
  328. if DontClear=false then ClearEvent(Event);
  329. end;
  330. evBroadcast :
  331. case Event.Command of
  332. cmListItemSelected :
  333. if Event.InfoPtr=pointer(ToolsLB) then
  334. Message(@Self,evCommand,cmEditItem,nil);
  335. end;
  336. evCommand :
  337. begin
  338. DontClear:=false;
  339. case Event.Command of
  340. cmAddItem : Add;
  341. cmDeleteItem : Delete;
  342. cmEditItem : Edit;
  343. else DontClear:=true;
  344. end;
  345. if DontClear=false then ClearEvent(Event);
  346. end;
  347. end;
  348. inherited HandleEvent(Event);
  349. end;
  350. function TToolsDialog.Execute: Word;
  351. var R: word;
  352. C: PToolCollection;
  353. I: integer;
  354. S1,S2,S3: string;
  355. W: word;
  356. begin
  357. New(C, Init(10,20));
  358. if Tools<>nil then
  359. for I:=0 to Tools^.Count-1 do
  360. begin
  361. Tools^.At(I)^.GetParams(S1,S2,S3,W);
  362. C^.Insert(New(PTool, Init(S1,S2,S3,W)));
  363. end;
  364. ToolsLB^.NewList(C);
  365. R:=inherited Execute;
  366. if R=cmOK then
  367. begin
  368. if Tools<>nil then Dispose(Tools, Done);
  369. Tools:=C;
  370. Message(Application,evBroadcast,cmUpdateTools,nil);
  371. end
  372. else
  373. Dispose(C, Done);
  374. Execute:=R;
  375. end;
  376. procedure TToolsDialog.Add;
  377. var P: PTool;
  378. IC: boolean;
  379. S1,S2,S3: string;
  380. W: word;
  381. begin
  382. if ToolsLB^.Range>=MaxToolCount then
  383. begin InformationBox(^C'Can''t install more tools...',nil); Exit; end;
  384. IC:=ToolsLB^.Range=0;
  385. if IC=false then
  386. begin
  387. P:=ToolsLB^.List^.At(ToolsLB^.Focused);
  388. P^.GetParams(S1,S2,S3,W);
  389. end
  390. else
  391. begin
  392. S1:=''; S2:=''; S3:=''; W:=0;
  393. end;
  394. New(P, Init(S1,S2,S3,W));
  395. if Application^.ExecuteDialog(New(PToolItemDialog, Init(P)), nil)=cmOK then
  396. begin
  397. ToolsLB^.List^.Insert(P);
  398. ToolsLB^.SetRange(ToolsLB^.List^.Count);
  399. ReDraw;
  400. end
  401. else
  402. Dispose(P, Done);
  403. end;
  404. procedure TToolsDialog.Edit;
  405. var P: PTool;
  406. begin
  407. if ToolsLB^.Range=0 then Exit;
  408. P:=ToolsLB^.List^.At(ToolsLB^.Focused);
  409. Application^.ExecuteDialog(New(PToolItemDialog, Init(P)), nil);
  410. ReDraw;
  411. end;
  412. procedure TToolsDialog.Delete;
  413. begin
  414. if ToolsLB^.Range=0 then Exit;
  415. ToolsLB^.List^.AtFree(ToolsLB^.Focused);
  416. ToolsLB^.SetRange(ToolsLB^.List^.Count);
  417. ReDraw;
  418. end;
  419. function ParseToolParams(var Params: string; CheckOnly: boolean): Sw_integer;
  420. var Err: integer;
  421. W: PSourceWindow;
  422. procedure ParseParams(Pass: integer);
  423. var I: Sw_integer;
  424. function IsAlpha(Ch: char): boolean;
  425. begin
  426. IsAlpha:=(Upcase(Ch) in['A'..'Z','_','$']);
  427. end;
  428. function ReplacePart(StartP,EndP: integer; const S: string): integer;
  429. begin
  430. Params:=copy(Params,1,StartP-1)+S+copy(Params,EndP+1,255);
  431. ReplacePart:=length(S)-(EndP-StartP+1);
  432. end;
  433. function Consume(Ch: char): boolean;
  434. var OK: boolean;
  435. begin
  436. OK:=Params[I]=Ch;
  437. if OK then Inc(I);
  438. Consume:=OK;
  439. end;
  440. function ReadTill(var S: string; C: char): boolean;
  441. var Found: boolean;
  442. begin
  443. Found:=false; S:='';
  444. while (I<=length(Params)) and (Found=false) do
  445. begin
  446. Found:=Params[I]=C;
  447. if Found=false then
  448. begin
  449. S:=S+Params[I];
  450. Inc(I);
  451. end;
  452. end;
  453. ReadTill:=Found;
  454. end;
  455. var C,PrevC: char;
  456. WordS: string;
  457. LastWordStart: Sw_integer;
  458. L: longint;
  459. S: string;
  460. D: DirStr; N: NameStr; E: ExtStr;
  461. begin
  462. I:=1; WordS:=''; LastWordStart:=I; PrevC:=' ';
  463. while (I<=length(Params)+1) and (Err=0) do
  464. begin
  465. if I<=length(Params) then C:=Params[I];
  466. if (I<=length(Params)) and IsAlpha(C) then
  467. begin
  468. if (I=1) or (IsAlpha(PrevC)=false) then
  469. begin WordS:=''; LastWordStart:=I; end;
  470. { if IsAlpha(C) then ForceConcat:=false;}
  471. WordS:=WordS+C;
  472. end
  473. else
  474. begin
  475. WordS:=UpcaseStr(Trim(WordS));
  476. if WordS<>'' then
  477. if (WordS='$COL') then
  478. begin
  479. if (Pass=1) then
  480. begin
  481. if W=nil then L:=0 else
  482. L:=W^.Editor^.CurPos.X+1;
  483. I:=I+ReplacePart(LastWordStart,I-1,IntToStr(L));
  484. end;
  485. end else
  486. if (WordS='$CONFIG') then
  487. begin
  488. if (Pass=1) then
  489. I:=I+ReplacePart(LastWordStart,I-1,INIPath);
  490. end else
  491. if (WordS='$DIR') then
  492. begin
  493. if (Pass=2) then
  494. if Consume('(')=false then Err:=I else
  495. if ReadTill(S,')')=false then Err:=I else
  496. begin
  497. Consume(')');
  498. FSplit(S,D,N,E);
  499. I:=I+ReplacePart(LastWordStart,I-1,D);
  500. end;
  501. end else
  502. if (WordS='$DRIVE') then
  503. begin
  504. if (Pass=2) then
  505. if Consume('(')=false then Err:=I else
  506. if ReadTill(S,')')=false then Err:=I else
  507. begin
  508. Consume(')');
  509. FSplit(S,D,N,E);
  510. L:=Pos(':',D); if L=0 then L:=-1;
  511. D:=copy(D,1,L+1);
  512. I:=I+ReplacePart(LastWordStart,I-1,D);
  513. end;
  514. end else
  515. if (WordS='$EDNAME') then
  516. begin
  517. if (Pass=1) then
  518. begin
  519. if W=nil then S:='' else
  520. S:=W^.Editor^.FileName;
  521. I:=I+ReplacePart(LastWordStart,I-1,S);
  522. end;
  523. end else
  524. if (WordS='$EXENAME') then
  525. begin
  526. if (Pass=1) then
  527. I:=I+ReplacePart(LastWordStart,I-1,EXEFile);
  528. end else
  529. if (WordS='$EXT') then
  530. begin
  531. if (Pass=2) then
  532. if Consume('(')=false then Err:=I else
  533. if ReadTill(S,')')=false then Err:=I else
  534. begin
  535. Consume(')');
  536. FSplit(S,D,N,E); E:=copy(E,2,255);
  537. I:=I+ReplacePart(LastWordStart,I-1,E);
  538. end;
  539. end else
  540. if (WordS='$LINE') then
  541. begin
  542. if (Pass=1) then
  543. begin
  544. if W=nil then L:=0 else
  545. L:=W^.Editor^.CurPos.Y+1;
  546. I:=I+ReplacePart(LastWordStart,I-1,IntToStr(L));
  547. end;
  548. end else
  549. if (WordS='$NAME') then
  550. begin
  551. if (Pass=2) then
  552. if Consume('(')=false then Err:=I else
  553. if ReadTill(S,')')=false then Err:=I else
  554. begin
  555. Consume(')');
  556. FSplit(S,D,N,E);
  557. I:=I+ReplacePart(LastWordStart,I-1,N);
  558. end;
  559. end else
  560. if (WordS='$NAMEEXT') then
  561. begin
  562. if (Pass=2) then
  563. if Consume('(')=false then Err:=I else
  564. if ReadTill(S,')')=false then Err:=I else
  565. begin
  566. Consume(')');
  567. FSplit(S,D,N,E);
  568. I:=I+ReplacePart(LastWordStart,I-1,N+E);
  569. end;
  570. end else
  571. if (WordS='$NOSWAP') then
  572. begin
  573. if (Pass=1) then
  574. begin
  575. I:=I+ReplacePart(LastWordStart,I-1,'');
  576. end;
  577. end else
  578. if (WordS='$PROMPT') then
  579. begin
  580. if (Pass=3) then
  581. begin
  582. I:=I+ReplacePart(LastWordStart,I-1,'');
  583. if CheckOnly=false then
  584. begin
  585. S:=copy(Params,I+1,255);
  586. if InputBox('Program Arguments', '~E~nter program argument',
  587. S,255-I+1)=cmOK then
  588. begin
  589. ReplacePart(LastWordStart,255,S);
  590. I:=255;
  591. end
  592. else
  593. Err:=-1;
  594. end;
  595. end;
  596. end else
  597. if (WordS='$SAVE') then
  598. begin
  599. if (Pass=0) then
  600. if (Params[I]=' ') and (I<=255) then Params[I]:='_';
  601. end else
  602. if (WordS='$SAVE_ALL') then
  603. begin
  604. if (Pass=2) then
  605. begin
  606. I:=I+ReplacePart(LastWordStart,I-1,'');
  607. Message(Application,evCommand,cmSaveAll,nil);
  608. end;
  609. end else
  610. if (WordS='$SAVE_CUR') then
  611. begin
  612. if (Pass=2) then
  613. begin
  614. I:=I+ReplacePart(LastWordStart,I-1,'');
  615. Message(W,evCommand,cmSave,nil);
  616. end;
  617. end else
  618. if (WordS='$SAVE_PROMPT') then
  619. begin
  620. if (Pass=2) then
  621. begin
  622. I:=I+ReplacePart(LastWordStart,I-1,'');
  623. if W<>nil then
  624. if W^.Editor^.SaveAsk=false then
  625. Err:=-1;
  626. end;
  627. end else
  628. if copy(WordS,1,1)='$' then
  629. Err:=LastWordStart;
  630. WordS:='';
  631. end;
  632. PrevC:=C;
  633. Inc(I);
  634. end;
  635. end;
  636. var Pass: Sw_integer;
  637. begin
  638. W:=FirstEditorWindow;
  639. Err:=0;
  640. for Pass:=0 to 3 do
  641. begin
  642. ParseParams(Pass);
  643. if Err<>0 then Break;
  644. end;
  645. ParseToolParams:=Err;
  646. end;
  647. END.
  648. {
  649. $Log$
  650. Revision 1.3 1999-02-22 02:15:19 peter
  651. + default extension for save in the editor
  652. + Separate Text to Find for the grep dialog
  653. * fixed redir crash with tp7
  654. Revision 1.2 1999/02/19 15:43:21 peter
  655. * compatibility fixes for FV
  656. Revision 1.1 1999/01/21 11:54:25 peter
  657. + tools menu
  658. + speedsearch in symbolbrowser
  659. * working run command
  660. Revision 1.0 1999/01/16 10:43:31 gabor
  661. Original implementation
  662. }