fpmtools.inc 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503
  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. if ASCIIChart=nil then
  22. begin
  23. New(ASCIIChart, Init);
  24. Desktop^.Insert(ASCIIChart);
  25. end
  26. else
  27. ASCIIChart^.Focus;
  28. end;
  29. procedure TIDEApp.Calculator;
  30. begin
  31. with CalcWindow^ do
  32. begin
  33. if GetState(sfVisible)=false then Show;
  34. MakeFirst;
  35. end;
  36. end;
  37. procedure TIDEApp.ExecuteTool(Idx: integer);
  38. var Title,ProgramPath,Params: string;
  39. W: PSourceWindow;
  40. ToFocus : sw_integer;
  41. Wo: word;
  42. Err: integer;
  43. CaptureFile: string;
  44. ErrText : Text;
  45. ExecMode: TExecType;
  46. Executed: boolean;
  47. begin
  48. if (Idx<1) or (Idx>GetToolCount) then Exit;
  49. GetToolParams(Idx-1,Title,ProgramPath,Params,Wo);
  50. InitToolTempFiles;
  51. Err:=ParseToolParams(Params,false);
  52. if Err=-1 then
  53. begin
  54. DoneToolTempFiles;
  55. Exit;
  56. end;
  57. if Err<>0 then
  58. begin ErrorBox(msg_errorparsingtoolparams,nil); Exit; end;
  59. if CaptureToolTo<>capNone then
  60. begin
  61. if ToolOutput<>'' then
  62. begin
  63. CaptureFile:=ToolOutput;
  64. end
  65. else
  66. CaptureFile:=ToolCaptureName;
  67. ExecMode:=exNoSwap;
  68. end
  69. else
  70. begin
  71. CaptureFile:='';
  72. ExecMode:=exNormal;
  73. end;
  74. EraseFile(CaptureFile);
  75. EraseFile(FilterCaptureName);
  76. if CaptureToolTo=capMessageWindow then
  77. begin
  78. AddToolCommand(ProgramPath+' '+Params);
  79. ToFocus:=ToolMessages^.count-1;
  80. end
  81. else
  82. ToFocus:=-1;
  83. if CaptureToolTo<>capNone then
  84. ShowMessage(FormatStrStr(msg_executingtool,KillTilde(Title)));
  85. Executed:=DoExecute(ProgramPath,Params,'',CaptureFile,ToolCaptureErr,ExecMode);
  86. if CaptureToolTo<>capNone then
  87. HideMessage;
  88. if Executed then
  89. begin
  90. if (DosError=0) {and (DosExitCode=0)} then
  91. begin
  92. if CaptureToolTo=capEditWindow then
  93. begin
  94. if ToolOutput<>'' then
  95. W:=OpenEditorWindow(nil,ToolOutput,0,0)
  96. else
  97. begin
  98. W:=OpenEditorWindow(nil,'',0,0);
  99. if W<>nil then
  100. if StartEditor(W^.Editor,CaptureFile)=false then
  101. ErrorBox(msg_errorreadingoutput,nil);
  102. end;
  103. end
  104. else if ToolFilter<>'' then
  105. begin
  106. ShowMessage(FormatStrStr(msg_executingfilterfor,KillTilde(Title)));
  107. DoExecute(ToolFilter,'',CaptureFile,FilterCaptureName,'',exNoSwap);
  108. HideMessage;
  109. if (DosError=0) and (DosExitCode=0) then
  110. begin
  111. if ExistsFile(FilterCaptureName)=false then
  112. ErrorBox(msg_cantfindfilteredoutput,nil)
  113. else
  114. if ProcessMessageFile(FilterCaptureName)=false then
  115. ErrorBox(msg_errorprocessingfilteredoutput,nil);
  116. end;
  117. if (DosError<>0) then
  118. ErrorBox(FormatStrStr(msg_errorexecutingfilter,KillTilde(GetToolName(Idx-1))),nil) else
  119. if DosExitCode<>0 then
  120. ErrorBox(FormatStrInt(msg_filterexecutionsuccessfulexitcodeis,DosExitCode),nil);
  121. UpdateToolMessages;
  122. if (ToFocus<>-1) then
  123. if Assigned(MessagesWindow) then
  124. MessagesWindow^.FocusItem(ToFocus);
  125. if DosError=0 then
  126. Messages;
  127. end;
  128. end;
  129. end;
  130. if (DosError<>0) or (DosExitCode<>0) then
  131. begin
  132. if (DosError<>0) then
  133. ErrorBox(FormatStrStr(msg_errorexecutingtool,KillTilde(GetToolName(Idx-1))),nil) else
  134. if DosExitCode<>0 then
  135. ErrorBox(FormatStrInt(msg_toolexecutionsuccessfulexitcodeis,DosExitCode),nil);
  136. {$i-}
  137. Assign(ErrText,ToolCaptureErr);
  138. Reset(ErrText);
  139. while not eof(ErrText) do
  140. begin
  141. Readln(ErrText,Params);
  142. AddToolCommand(Params);
  143. end;
  144. end;
  145. {$ifndef DEBUG}
  146. if ToolOutput='' then
  147. begin
  148. EraseFile(CaptureFile);
  149. ToolOutput:='';
  150. end;
  151. EraseFile(FilterCaptureName);
  152. EraseFile(ToolCaptureErr);
  153. {$endif}
  154. { In case we have something that the compiler touched }
  155. AskToReloadAllModifiedFiles;
  156. DoneToolTempFiles;
  157. end;
  158. procedure TIDEApp.DoGrep;
  159. Const
  160. GrepExeName = 'grep'+ExeExt;
  161. var
  162. PGrepDialog : PCenterDialog;
  163. R,R1,R2 : TRect;
  164. Control : PView;
  165. IL1,IL2 : PInputLine;
  166. s : string;
  167. p,lineNb,GrepOutputLine : longint;
  168. error : word;
  169. PosText : longint;
  170. showmsg,error_in_reading,FirstMsg : boolean;
  171. ToFocus : sw_integer;
  172. searchword,
  173. GrepExe,GrepArgs,Line,ModuleName : String;
  174. GrepOut : text;
  175. Params : Array[0..4] of longint;
  176. begin
  177. showmsg:=false;
  178. ToFocus:=-1;
  179. { Find grep.exe }
  180. GrepExe:=GrepExeName;
  181. If not LocateExeFile(GrepExe) then
  182. Begin
  183. ErrorBox(msg_grepprogramnotfound,nil);
  184. Exit;
  185. End;
  186. { Try to load the word from the editor }
  187. If not(DeskTop^.Current=nil) and
  188. (DeskTop^.Current^.HelpCtx=hcSourceWindow) then
  189. Searchword:=PSourceWindow(DeskTop^.Current)^.Editor^.GetCurrentWord
  190. else
  191. Searchword:='';
  192. { Don't use the listseparator in the file list else it's seen as 1 file
  193. (at least under linux }
  194. s:=highlightexts;
  195. ReplaceStr(s,';',' ');
  196. { add "" for args with spaces }
  197. { WARNING : text must still be entered in usual grep syntax }
  198. { -n is always added later because otherwise
  199. we don't get the line info PM }
  200. GrepArgs:=' -i "$TEXT" '+s;
  201. { Dialog }
  202. R.Assign(0,0,50,8);
  203. new(PGrepDialog,Init(R,dialog_greparguments));
  204. with PGrepDialog^ do
  205. begin
  206. R2.A.Y:=R.A.Y+3;
  207. R2.B.Y:=R2.A.Y+1;
  208. R2.A.X:=R.A.X+3;
  209. R2.B.X:=R.B.X-6;
  210. New(IL1, Init(R2, 128));
  211. IL1^.Data^:=SearchWord;
  212. Insert(IL1);
  213. R2.Move(0,-1);
  214. Insert(New(PLabel, Init(R2, label_grep_texttofind, IL1)));
  215. R1.Assign(R2.B.X, R2.A.Y+1, R2.B.X+3, R2.B.Y+1);
  216. Control := New(PHistory, Init(R1, IL1, TextGrepId));
  217. Insert(Control);
  218. R2.Move(0,4);
  219. New(IL2, Init(R2, 128));
  220. IL2^.Data^:=GrepArgs;
  221. Insert(IL2);
  222. R2.Move(0,-1);
  223. Insert(New(PLabel, Init(R2, label_grep_greparguments, IL2)));
  224. R1.Assign(R2.B.X, R2.A.Y+1, R2.B.X+3, R2.B.Y+1);
  225. Control := New(PHistory, Init(R1, IL2, GrepArgsId));
  226. Insert(Control);
  227. end;
  228. InsertButtons(PGrepDialog);
  229. IL1^.Select;
  230. if Desktop^.ExecView(PGrepDialog)=cmOK then
  231. begin
  232. SearchWord:=IL1^.Data^;
  233. if SearchWord<>'' then
  234. begin
  235. GrepArgs:=IL2^.Data^;
  236. { Remember last used Grep extensions }
  237. PosText:=pos('"$TEXT" ',GrepArgs);
  238. if PosText>0 then
  239. HighlightExts:=Trim(Copy(GrepArgs,PosText+Length('"$TEXT" '),Length(GrepArgs)));
  240. { change spaces back into ';' again }
  241. ReplaceStr(HighlightExts,' ',';');
  242. { Replace search string }
  243. ReplaceStr(GrepArgs,'$TEXT',SearchWord);
  244. { Linux ? }
  245. AddToolCommand(GrepExe+' -n '+GrepArgs);
  246. ToFocus:=ToolMessages^.count-1;
  247. UpdateToolMessages;
  248. if Assigned(MessagesWindow) then
  249. MessagesWindow^.FocusItem(ToFocus);
  250. showmsg:=true;
  251. Messages;
  252. PushStatus(FormatStrStr(msg_runninggrepwithargs,GrepArgs));
  253. if not ExecuteRedir(GrepExe,'-n '+GrepArgs,'',GrepOutName,GrepErrName) then
  254. Begin
  255. PopStatus;
  256. { 2 as exit code just means that
  257. some file vwere not found ! }
  258. if (IOStatus<>0) or (ExecuteResult<>2) then
  259. begin
  260. Params[0]:=IOStatus;
  261. Params[1]:=ExecuteResult;
  262. WarningBox(msg_errorrunninggrep,@Params);
  263. end;
  264. End
  265. else
  266. PopStatus;
  267. {$I-}
  268. Assign(GrepOut,GrepOutName);
  269. Reset(GrepOut);
  270. error_in_reading:=false;
  271. FirstMsg:=True;
  272. GrepOutputLine:=0;
  273. While not eof(GrepOut) do
  274. begin
  275. readln(GrepOut,Line);
  276. Inc(GrepOutputLine);
  277. p:=pos(':',line);
  278. if p>0 then
  279. begin
  280. ModuleName:=copy(Line,1,p-1);
  281. Line:=Copy(Line,p+1,255);
  282. p:=pos(':',Line);
  283. val(copy(Line,1,p-1),lineNb,error);
  284. if error=0 then
  285. begin
  286. AddToolMessage(ModuleName,Copy(Line,p+1,255),LineNb,1);
  287. if FirstMsg then
  288. begin
  289. Inc(ToFocus);
  290. FirstMsg:=false;
  291. end;
  292. end
  293. else
  294. error_in_reading:=true;
  295. end;
  296. end;
  297. Close(GrepOut);
  298. if not error_in_reading then
  299. Erase(GrepOut)
  300. else
  301. begin
  302. ClearFormatParams;
  303. AddFormatParamInt(GrepOutputLine);
  304. AddFormatParamStr(GrepOutName);
  305. WarningBox(msg_errorreadinggrepoutput,@FormatParams);
  306. end;
  307. { Delete also grep$$.err }
  308. if not error_in_reading then
  309. begin
  310. Assign(GrepOut,GrepErrName);
  311. Erase(GrepOut);
  312. end;
  313. {$I+}
  314. EatIO;
  315. end;
  316. end;
  317. Dispose(PGrepDialog, Done);
  318. UpdateToolMessages;
  319. if (ToFocus<>-1) then
  320. if Assigned(MessagesWindow) then
  321. begin
  322. MessagesWindow^.Lock;
  323. MessagesWindow^.FocusItem(ToolMessages^.count-1);
  324. if ToFocus>0 then
  325. MessagesWindow^.FocusItem(ToFocus-1);
  326. MessagesWindow^.FocusItem(ToFocus);
  327. MessagesWindow^.UnLock;
  328. end;
  329. if showmsg then
  330. Messages;
  331. end;
  332. {
  333. $Log$
  334. Revision 1.3 2002-05-29 22:38:13 pierre
  335. Asciitab now in fvision
  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. }