fpmtools.inc 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502
  1. {
  2. $Id$
  3. This file is part of the Free Pascal Integrated Development Environment
  4. Copyright (c) 1998 by Berczi Gabor
  5. Tools menu entries
  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. procedure TIDEApp.Messages;
  13. begin
  14. if MessagesWindow=nil then
  15. Desktop^.Insert(New(PMessagesWindow, Init))
  16. else
  17. MessagesWindow^.Focus;
  18. end;
  19. procedure TIDEApp.DoAsciiTable;
  20. begin
  21. {$ifndef FVISION}
  22. if ASCIIChart=nil then
  23. begin
  24. New(ASCIIChart, Init);
  25. Desktop^.Insert(ASCIIChart);
  26. end
  27. else
  28. ASCIIChart^.Focus;
  29. {$endif FVISION}
  30. end;
  31. procedure TIDEApp.Calculator;
  32. begin
  33. with CalcWindow^ do
  34. begin
  35. if GetState(sfVisible)=false then Show;
  36. MakeFirst;
  37. end;
  38. end;
  39. procedure TIDEApp.ExecuteTool(Idx: integer);
  40. var Title,ProgramPath,Params: string;
  41. W: PSourceWindow;
  42. ToFocus : sw_integer;
  43. Wo: word;
  44. Err: integer;
  45. CaptureFile: string;
  46. ErrText : Text;
  47. ExecMode: TExecType;
  48. Executed: boolean;
  49. begin
  50. if (Idx<1) or (Idx>GetToolCount) then Exit;
  51. GetToolParams(Idx-1,Title,ProgramPath,Params,Wo);
  52. InitToolTempFiles;
  53. Err:=ParseToolParams(Params,false);
  54. if Err=-1 then
  55. begin
  56. DoneToolTempFiles;
  57. Exit;
  58. end;
  59. if Err<>0 then
  60. begin ErrorBox(msg_errorparsingtoolparams,nil); Exit; end;
  61. if CaptureToolTo<>capNone then
  62. begin
  63. if ToolOutput<>'' then
  64. begin
  65. CaptureFile:=ToolOutput;
  66. end
  67. else
  68. CaptureFile:=ToolCaptureName;
  69. ExecMode:=exNoSwap;
  70. end
  71. else
  72. begin
  73. CaptureFile:='';
  74. ExecMode:=exNormal;
  75. end;
  76. EraseFile(CaptureFile);
  77. EraseFile(FilterCaptureName);
  78. if CaptureToolTo=capMessageWindow then
  79. begin
  80. AddToolCommand(ProgramPath+' '+Params);
  81. ToFocus:=ToolMessages^.count-1;
  82. end
  83. else
  84. ToFocus:=-1;
  85. if CaptureToolTo<>capNone then
  86. ShowMessage(FormatStrStr(msg_executingtool,KillTilde(Title)));
  87. Executed:=DoExecute(ProgramPath,Params,'',CaptureFile,ToolCaptureErr,ExecMode);
  88. if CaptureToolTo<>capNone then
  89. HideMessage;
  90. if Executed then
  91. begin
  92. if (DosError=0) {and (DosExitCode=0)} then
  93. begin
  94. if CaptureToolTo=capEditWindow then
  95. begin
  96. if ToolOutput<>'' then
  97. W:=OpenEditorWindow(nil,ToolOutput,0,0)
  98. else
  99. begin
  100. W:=OpenEditorWindow(nil,'',0,0);
  101. if W<>nil then
  102. if StartEditor(W^.Editor,CaptureFile)=false then
  103. ErrorBox(msg_errorreadingoutput,nil);
  104. end;
  105. end
  106. else if ToolFilter<>'' then
  107. begin
  108. ShowMessage(FormatStrStr(msg_executingfilterfor,KillTilde(Title)));
  109. DoExecute(ToolFilter,'',CaptureFile,FilterCaptureName,'',exNoSwap);
  110. HideMessage;
  111. if (DosError=0) and (DosExitCode=0) then
  112. begin
  113. if ExistsFile(FilterCaptureName)=false then
  114. ErrorBox(msg_cantfindfilteredoutput,nil)
  115. else
  116. if ProcessMessageFile(FilterCaptureName)=false then
  117. ErrorBox(msg_errorprocessingfilteredoutput,nil);
  118. end;
  119. if (DosError<>0) then
  120. ErrorBox(FormatStrStr(msg_errorexecutingfilter,KillTilde(GetToolName(Idx-1))),nil) else
  121. if DosExitCode<>0 then
  122. ErrorBox(FormatStrInt(msg_filterexecutionsuccessfulexitcodeis,DosExitCode),nil);
  123. UpdateToolMessages;
  124. if (ToFocus<>-1) then
  125. if Assigned(MessagesWindow) then
  126. MessagesWindow^.FocusItem(ToFocus);
  127. if DosError=0 then
  128. Messages;
  129. end;
  130. end;
  131. end;
  132. if (DosError<>0) or (DosExitCode<>0) then
  133. begin
  134. if (DosError<>0) then
  135. ErrorBox(FormatStrStr(msg_errorexecutingtool,KillTilde(GetToolName(Idx-1))),nil) else
  136. if DosExitCode<>0 then
  137. ErrorBox(FormatStrInt(msg_toolexecutionsuccessfulexitcodeis,DosExitCode),nil);
  138. {$i-}
  139. Assign(ErrText,ToolCaptureErr);
  140. Reset(ErrText);
  141. while not eof(ErrText) do
  142. begin
  143. Readln(ErrText,Params);
  144. AddToolCommand(Params);
  145. end;
  146. end;
  147. {$ifndef DEBUG}
  148. if ToolOutput='' then
  149. begin
  150. EraseFile(CaptureFile);
  151. ToolOutput:='';
  152. end;
  153. EraseFile(FilterCaptureName);
  154. EraseFile(ToolCaptureErr);
  155. {$endif}
  156. { In case we have something that the compiler touched }
  157. AskToReloadAllModifiedFiles;
  158. DoneToolTempFiles;
  159. end;
  160. procedure TIDEApp.DoGrep;
  161. Const
  162. GrepExeName = 'grep'+ExeExt;
  163. var
  164. PGrepDialog : PCenterDialog;
  165. R,R1,R2 : TRect;
  166. Control : PView;
  167. IL1,IL2 : PInputLine;
  168. s : string;
  169. p,lineNb,GrepOutputLine : longint;
  170. error : word;
  171. PosText : longint;
  172. showmsg,error_in_reading,FirstMsg : boolean;
  173. ToFocus : sw_integer;
  174. searchword,
  175. GrepExe,GrepArgs,Line,ModuleName : String;
  176. GrepOut : text;
  177. Params : Array[0..4] of longint;
  178. begin
  179. showmsg:=false;
  180. ToFocus:=-1;
  181. { Find grep.exe }
  182. GrepExe:=GrepExeName;
  183. If not LocateExeFile(GrepExe) then
  184. Begin
  185. ErrorBox(msg_grepprogramnotfound,nil);
  186. Exit;
  187. End;
  188. { Try to load the word from the editor }
  189. If not(DeskTop^.Current=nil) and
  190. (DeskTop^.Current^.HelpCtx=hcSourceWindow) then
  191. Searchword:=PSourceWindow(DeskTop^.Current)^.Editor^.GetCurrentWord
  192. else
  193. Searchword:='';
  194. { Don't use the listseparator in the file list else it's seen as 1 file
  195. (at least under linux }
  196. s:=highlightexts;
  197. ReplaceStr(s,';',' ');
  198. { add "" for args with spaces }
  199. { WARNING : text must still be entered in usual grep syntax }
  200. { -n is always added later because otherwise
  201. we don't get the line info PM }
  202. GrepArgs:=' -i "$TEXT" '+s;
  203. { Dialog }
  204. R.Assign(0,0,50,8);
  205. new(PGrepDialog,Init(R,dialog_greparguments));
  206. with PGrepDialog^ do
  207. begin
  208. R2.A.Y:=R.A.Y+3;
  209. R2.B.Y:=R2.A.Y+1;
  210. R2.A.X:=R.A.X+3;
  211. R2.B.X:=R.B.X-6;
  212. New(IL1, Init(R2, 128));
  213. IL1^.Data^:=SearchWord;
  214. Insert(IL1);
  215. R2.Move(0,-1);
  216. Insert(New(PLabel, Init(R2, label_grep_texttofind, IL1)));
  217. R1.Assign(R2.B.X, R2.A.Y+1, R2.B.X+3, R2.B.Y+1);
  218. Control := New(PHistory, Init(R1, IL1, TextGrepId));
  219. Insert(Control);
  220. R2.Move(0,4);
  221. New(IL2, Init(R2, 128));
  222. IL2^.Data^:=GrepArgs;
  223. Insert(IL2);
  224. R2.Move(0,-1);
  225. Insert(New(PLabel, Init(R2, label_grep_greparguments, IL2)));
  226. R1.Assign(R2.B.X, R2.A.Y+1, R2.B.X+3, R2.B.Y+1);
  227. Control := New(PHistory, Init(R1, IL2, GrepArgsId));
  228. Insert(Control);
  229. end;
  230. InsertButtons(PGrepDialog);
  231. IL1^.Select;
  232. if Desktop^.ExecView(PGrepDialog)=cmOK then
  233. begin
  234. SearchWord:=IL1^.Data^;
  235. if SearchWord<>'' then
  236. begin
  237. GrepArgs:=IL2^.Data^;
  238. { Remember last used Grep extensions }
  239. PosText:=pos('"$TEXT" ',GrepArgs);
  240. if PosText>0 then
  241. HighlightExts:=Trim(Copy(GrepArgs,PosText+Length('"$TEXT" '),Length(GrepArgs)));
  242. { change spaces back into ';' again }
  243. ReplaceStr(HighlightExts,' ',';');
  244. { Replace search string }
  245. ReplaceStr(GrepArgs,'$TEXT',SearchWord);
  246. { Linux ? }
  247. AddToolCommand(GrepExe+' -n '+GrepArgs);
  248. ToFocus:=ToolMessages^.count-1;
  249. UpdateToolMessages;
  250. if Assigned(MessagesWindow) then
  251. MessagesWindow^.FocusItem(ToFocus);
  252. showmsg:=true;
  253. Messages;
  254. PushStatus(FormatStrStr(msg_runninggrepwithargs,GrepArgs));
  255. if not ExecuteRedir(GrepExe,'-n '+GrepArgs,'',GrepOutName,GrepErrName) then
  256. Begin
  257. PopStatus;
  258. { 2 as exit code just means that
  259. some file vwere not found ! }
  260. if (IOStatus<>0) or (ExecuteResult<>2) then
  261. begin
  262. Params[0]:=IOStatus;
  263. Params[1]:=ExecuteResult;
  264. WarningBox(msg_errorrunninggrep,@Params);
  265. end;
  266. End
  267. else
  268. PopStatus;
  269. {$I-}
  270. Assign(GrepOut,GrepOutName);
  271. Reset(GrepOut);
  272. error_in_reading:=false;
  273. FirstMsg:=True;
  274. GrepOutputLine:=0;
  275. While not eof(GrepOut) do
  276. begin
  277. readln(GrepOut,Line);
  278. Inc(GrepOutputLine);
  279. p:=pos(':',line);
  280. if p>0 then
  281. begin
  282. ModuleName:=copy(Line,1,p-1);
  283. Line:=Copy(Line,p+1,255);
  284. p:=pos(':',Line);
  285. val(copy(Line,1,p-1),lineNb,error);
  286. if error=0 then
  287. begin
  288. AddToolMessage(ModuleName,Copy(Line,p+1,255),LineNb,1);
  289. if FirstMsg then
  290. begin
  291. Inc(ToFocus);
  292. FirstMsg:=false;
  293. end;
  294. end
  295. else
  296. error_in_reading:=true;
  297. end;
  298. end;
  299. Close(GrepOut);
  300. if not error_in_reading then
  301. Erase(GrepOut)
  302. else
  303. begin
  304. ClearFormatParams;
  305. AddFormatParamInt(GrepOutputLine);
  306. AddFormatParamStr(GrepOutName);
  307. WarningBox(msg_errorreadinggrepoutput,@FormatParams);
  308. end;
  309. { Delete also grep$$.err }
  310. if not error_in_reading then
  311. begin
  312. Assign(GrepOut,GrepErrName);
  313. Erase(GrepOut);
  314. end;
  315. {$I+}
  316. EatIO;
  317. end;
  318. end;
  319. Dispose(PGrepDialog, Done);
  320. UpdateToolMessages;
  321. if (ToFocus<>-1) then
  322. if Assigned(MessagesWindow) then
  323. begin
  324. MessagesWindow^.Lock;
  325. MessagesWindow^.FocusItem(ToolMessages^.count-1);
  326. if ToFocus>0 then
  327. MessagesWindow^.FocusItem(ToFocus-1);
  328. MessagesWindow^.FocusItem(ToFocus);
  329. MessagesWindow^.UnLock;
  330. end;
  331. if showmsg then
  332. Messages;
  333. end;
  334. {
  335. $Log$
  336. Revision 1.2 2001-08-05 12:23:00 peter
  337. * Automatically support for fvision or old fv
  338. Revision 1.1 2001/08/04 11:30:23 peter
  339. * ide works now with both compiler versions
  340. Revision 1.1.2.7 2001/03/08 16:43:01 pierre
  341. + add $CAP EDIT(filename) capability
  342. * fix horizontal scrolling
  343. Revision 1.1.2.6 2001/02/19 10:40:50 pierre
  344. * Check for changed files after Running tool or shell
  345. Revision 1.1.2.5 2000/12/13 16:59:09 pierre
  346. * ErrFile filed added to DoExecute method
  347. Revision 1.1.2.4 2000/11/23 16:33:31 pierre
  348. * fix Alt-X problem and set HelpCtx for most dialogs
  349. Revision 1.1.2.3 2000/11/21 17:44:12 pierre
  350. * better message positioning after grep
  351. Revision 1.1.2.2 2000/11/13 16:57:04 pierre
  352. * some grep improovements
  353. Revision 1.1.2.1 2000/07/20 11:02:15 michael
  354. + Fixes from gabor. See fixes.txt
  355. Revision 1.1 2000/07/13 09:48:35 michael
  356. + Initial import
  357. Revision 1.21 2000/06/16 08:50:41 pierre
  358. + new bunch of Gabor's changes
  359. Revision 1.20 2000/05/02 08:42:28 pierre
  360. * new set of Gabor changes: see fixes.txt
  361. Revision 1.19 2000/03/13 20:32:56 pierre
  362. + Grep running also in Status line
  363. Revision 1.18 2000/03/02 22:33:36 pierre
  364. * Grep improoved
  365. Revision 1.17 2000/02/10 00:48:02 pierre
  366. * avoid crash for empty string
  367. Revision 1.16 2000/02/02 22:49:44 pierre
  368. * use desktop^.current for current word in grep
  369. Revision 1.15 1999/10/08 15:25:25 pierre
  370. + Grep read check added
  371. Revision 1.14 1999/09/22 16:17:31 pierre
  372. + HistList for Grep
  373. Revision 1.13 1999/08/03 20:22:35 peter
  374. + TTab acts now on Ctrl+Tab and Ctrl+Shift+Tab...
  375. + Desktop saving should work now
  376. - History saved
  377. - Clipboard content saved
  378. - Desktop saved
  379. - Symbol info saved
  380. * syntax-highlight bug fixed, which compared special keywords case sensitive
  381. (for ex. 'asm' caused asm-highlighting, while 'ASM' didn't)
  382. * with 'whole words only' set, the editor didn't found occourences of the
  383. searched text, if the text appeared previously in the same line, but didn't
  384. satisfied the 'whole-word' condition
  385. * ^QB jumped to (SelStart.X,SelEnd.X) instead of (SelStart.X,SelStart.Y)
  386. (ie. the beginning of the selection)
  387. * when started typing in a new line, but not at the start (X=0) of it,
  388. the editor inserted the text one character more to left as it should...
  389. * TCodeEditor.HideSelection (Ctrl-K+H) didn't update the screen
  390. * Shift shouldn't cause so much trouble in TCodeEditor now...
  391. * Syntax highlight had problems recognizing a special symbol if it was
  392. prefixed by another symbol character in the source text
  393. * Auto-save also occours at Dos shell, Tool execution, etc. now...
  394. Revision 1.12 1999/07/12 13:14:20 pierre
  395. * LineEnd bug corrected, now goes end of text even if selected
  396. + Until Return for debugger
  397. + Code for Quit inside GDB Window
  398. Revision 1.11 1999/03/02 13:48:30 peter
  399. * fixed far problem is fpdebug
  400. * tile/cascading with message window
  401. * grep fixes
  402. Revision 1.10 1999/02/22 12:46:57 peter
  403. * small fixes for linux and grep
  404. Revision 1.9 1999/02/22 11:29:37 pierre
  405. + added col info in MessageItem
  406. + grep uses HighLightExts and should work for linux
  407. Revision 1.8 1999/02/22 02:15:17 peter
  408. + default extension for save in the editor
  409. + Separate Text to Find for the grep dialog
  410. * fixed redir crash with tp7
  411. Revision 1.7 1999/02/20 15:18:31 peter
  412. + ctrl-c capture with confirm dialog
  413. + ascii table in the tools menu
  414. + heapviewer
  415. * empty file fixed
  416. * fixed callback routines in fpdebug to have far for tp7
  417. Revision 1.6 1999/02/05 13:51:42 peter
  418. * unit name of FPSwitches -> FPSwitch which is easier to use
  419. * some fixes for tp7 compiling
  420. Revision 1.5 1999/02/05 12:11:59 pierre
  421. + SourceDir that stores directories for sources that the
  422. compiler should not know about
  423. Automatically asked for addition when a new file that
  424. needed filedialog to be found is in an unknown directory
  425. Stored and retrieved from INIFile
  426. + Breakpoints conditions added to INIFile
  427. * Breakpoints insterted and removed at debin and end of debug session
  428. Revision 1.4 1999/02/04 15:59:08 pierre
  429. * grep$$$.out was not closed
  430. Revision 1.3 1999/02/04 13:32:09 pierre
  431. * Several things added (I cannot commit them independently !)
  432. + added TBreakpoint and TBreakpointCollection
  433. + added cmResetDebugger,cmGrep,CmToggleBreakpoint
  434. + Breakpoint list in INIFile
  435. * Select items now also depend of SwitchMode
  436. * Reading of option '-g' was not possible !
  437. + added search for -Fu args pathes in TryToOpen
  438. + added code for automatic opening of FileDialog
  439. if source not found
  440. Revision 1.2 1999/01/21 11:54:21 peter
  441. + tools menu
  442. + speedsearch in symbolbrowser
  443. * working run command
  444. Revision 1.1 1998/12/22 14:27:54 peter
  445. * moved
  446. Revision 1.2 1998/12/22 10:39:49 peter
  447. + options are now written/read
  448. + find and replace routines
  449. }