fpmtools.inc 12 KB

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