fpmfile.inc 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. {
  2. $Id$
  3. This file is part of the Free Pascal Integrated Development Environment
  4. Copyright (c) 1998 by Berczi Gabor
  5. File 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.NewEditor;
  13. begin
  14. OpenEditorWindow(nil,'',0,0);
  15. end;
  16. procedure TIDEApp.NewFromTemplate;
  17. var D: PCenterDialog;
  18. R,R2: TRect;
  19. SB: PScrollBar;
  20. LB: PAdvancedListBox;
  21. I: integer;
  22. C: PUnsortedStringCollection;
  23. TE: PSourceWindow;
  24. begin
  25. if GetTemplateCount=0 then
  26. begin InformationBox(msg_notemplatesavailable,nil); Exit; end;
  27. New(C, Init(10,10));
  28. R.Assign(0,0,40,14);
  29. New(D, Init(R, dialog_newfromtemplate));
  30. with D^ do
  31. begin
  32. HelpCtx:=hcNewFromTemplate;
  33. GetExtent(R); R.Grow(-2,-2); Inc(R.A.Y); Dec(R.B.X,12);
  34. R2.Copy(R); R2.Move(1,0); R2.A.X:=R2.B.X-1;
  35. New(SB, Init(R2)); Insert(SB);
  36. New(LB, Init(R,1,SB));
  37. LB^.Default:=true;
  38. for I:=0 to GetTemplateCount-1 do
  39. C^.Insert(NewStr(GetTemplateName(I)));
  40. LB^.NewList(C);
  41. Insert(LB);
  42. Dec(R.A.Y); R.B.Y:=R.A.Y+1;
  43. Insert(New(PLabel, Init(R, label_availabletemplates, LB)));
  44. GetExtent(R2); R2.Grow(-2,-3); R2.A.X:=R.B.X+2; R2.B.Y:=R2.A.Y+2;
  45. Insert(New(PButton, Init(R2, button_OK, cmOK, bfDefault)));
  46. R2.Move(0,2);
  47. Insert(New(PButton, Init(R2, button_Cancel, cmCancel, bfNormal)));
  48. end;
  49. LB^.Select;
  50. if Desktop^.ExecView(D)=cmOK then
  51. begin
  52. { Desktop^.Lock;}
  53. TE:=OpenEditorWindow(nil,'',0,0);
  54. if TE<>nil then
  55. begin
  56. StartTemplate(LB^.Focused,TE^.Editor);
  57. TE^.Editor^.SetModified(false); { if nothing changes, we don't need to save it }
  58. (* TE^.Hide; { we need this trick to get the editor updated }
  59. TE^.Show;*)
  60. end;
  61. { Desktop^.UnLock;}
  62. end;
  63. Dispose(D, Done);
  64. Dispose(C, Done);
  65. end;
  66. procedure TIDEApp.Open(FileName: string);
  67. var D: PFileDialog;
  68. OpenIt: boolean;
  69. DriveNumber : byte;
  70. StoreDir,StoreDir2 : DirStr;
  71. begin
  72. OpenIt:=FileName<>'';
  73. DriveNumber:=0;
  74. if not OpenIt then
  75. begin
  76. GetDir(0,StoreDir);
  77. if (Length(FileDir)>1) and (FileDir[2]=':') then
  78. begin
  79. { does not assume that lowercase are greater then uppercase ! }
  80. if (FileDir[1]>='a') and (FileDir[1]<='z') then
  81. DriveNumber:=Ord(FileDir[1])-ord('a')+1
  82. else
  83. DriveNumber:=Ord(FileDir[1])-ord('A')+1;
  84. GetDir(DriveNumber,StoreDir2);
  85. {$ifndef FPC}
  86. ChDir(Copy(FileDir,1,2));
  87. { sets InOutRes in win32 PM }
  88. {$endif not FPC}
  89. end;
  90. if (FileDir<>'') and ExistsDir(FileDir) then
  91. ChDir(TrimEndSlash(FileDir));
  92. New(D, Init(OpenExts,dialog_openafile,label_filetoopen,fdOpenButton,hidOpenSourceFile));
  93. D^.HelpCtx:=hcOpen;
  94. OpenIt:=Desktop^.ExecView(D)<>cmCancel;
  95. { if I go to root under go32v2 and there is no
  96. floppy I get a InOutRes = 152
  97. get rid of it ! }
  98. EatIO;
  99. if OpenIt then
  100. Begin
  101. D^.GetFileName(FileName);
  102. OpenExts:=D^.WildCard;
  103. if ExistsDir(DirOf(FExpand(FileName))) then
  104. FileDir:=DirOf(FExpand(FileName));
  105. End;
  106. Dispose(D, Done);
  107. if DriveNumber<>0 then
  108. ChDir(TrimEndSlash(StoreDir2));
  109. {$ifndef FPC}
  110. if (Length(StoreDir)>1) and (StoreDir[2]=':') then
  111. ChDir(Copy(StoreDir,1,2));
  112. {$endif not FPC}
  113. ChDir(TrimEndSlash(StoreDir));
  114. end;
  115. if OpenIt then
  116. begin
  117. FileName:=FExpand(LocatePasFile(FileName));
  118. if ExistsFile(FileName) then
  119. OpenEditorWindow(nil,FileName,0,0)
  120. else
  121. ErrorBox(FormatStrStr(msg_cantfindfile,FileName),nil);
  122. end;
  123. end;
  124. function TIDEApp.OpenSearch(FileName: string) : boolean;
  125. var D: PFileDialog;
  126. OpenIt: boolean;
  127. P : PString;
  128. Dir,S : String;
  129. begin
  130. OpenIt:=False;
  131. if not OpenIt then
  132. begin
  133. ClearFormatParams; AddFormatParamStr(FileName);
  134. FormatStr(S,label_lookingfor,FormatParams);
  135. New(D, Init(FileName,dialog_openafile,S,fdOpenButton,hidOpenSourceFile));
  136. D^.HelpCtx:=hcOpen;
  137. OpenIt:=Desktop^.ExecView(D)<>cmCancel;
  138. if OpenIt then
  139. Begin
  140. D^.GetFileName(FileName);
  141. End;
  142. Dispose(D, Done);
  143. end;
  144. if OpenIt then
  145. begin
  146. FileName:=FExpand(LocatePasFile(FileName));
  147. Dir:=DirOf(FileName);
  148. P:=@Dir;
  149. If Pos(Dir+';',GetSourceDirectories)=0 then
  150. if ConfirmBox(msg_confirmsourcediradd,@P,false)=cmYes then
  151. begin
  152. SourceDirs:=SourceDirs+';'+Dir;
  153. if assigned(Debugger) then
  154. Debugger^.SetDirectories;
  155. end;
  156. OpenEditorWindow(nil,FileName,0,0);
  157. end;
  158. OpenSearch:=OpenIt;
  159. end;
  160. procedure TIDEApp.OpenRecentFile(RecentIndex: integer);
  161. begin
  162. with RecentFiles[RecentIndex] do
  163. if OpenEditorWindow(nil,FileName,LastPos.X,LastPos.Y)<>nil then
  164. RemoveRecentFile(RecentIndex);
  165. end;
  166. function TIDEApp.AskSaveAll: boolean;
  167. function CanClose(P: PView): boolean; {$ifndef FPC}far;{$endif}
  168. begin
  169. CanClose:=not P^.Valid(cmAskSaveAll);
  170. end;
  171. begin
  172. AskSaveAll:=Desktop^.FirstThat(@CanClose)=nil;
  173. end;
  174. function TIDEApp.SaveAll: boolean;
  175. procedure SendSave(P: PView); {$ifndef FPC}far;{$endif}
  176. begin
  177. Message(P,evCommand,cmSave,nil);
  178. end;
  179. begin
  180. SaveCancelled:=false;
  181. Desktop^.ForEach(@SendSave);
  182. SaveAll:=not SaveCancelled;
  183. end;
  184. procedure TIDEApp.ChangeDir;
  185. var
  186. D : PChDirDialog;
  187. begin
  188. New(D, Init(cdNormal, hisChDirDialog));
  189. D^.HelpCtx:=hcChangeDir;
  190. ExecuteDialog(D,nil);
  191. CurDirChanged;
  192. end;
  193. {
  194. $Log$
  195. Revision 1.2 2001-09-12 09:49:35 pierre
  196. + Call to TDebugController.SetDirectories when SourceDirs changes
  197. Revision 1.1 2001/08/04 11:30:23 peter
  198. * ide works now with both compiler versions
  199. Revision 1.1.2.4 2001/06/20 22:57:26 pierre
  200. * fix bug 1527
  201. Revision 1.1.2.3 2000/12/30 22:52:27 peter
  202. * check modified while in debug mode. But placed it between a
  203. conditional again as it reports also if the file was already modified
  204. before the first compile.
  205. * remove unsaved file checks when compiling without primary file so it
  206. works the same as with a primary file set.
  207. Revision 1.1.2.2 2000/11/23 16:33:31 pierre
  208. * fix Alt-X problem and set HelpCtx for most dialogs
  209. Revision 1.1.2.1 2000/10/18 21:53:27 pierre
  210. * several Gabor fixes
  211. Revision 1.1 2000/07/13 09:48:35 michael
  212. + Initial import
  213. Revision 1.21 2000/06/16 08:50:41 pierre
  214. + new bunch of Gabor's changes
  215. Revision 1.20 2000/05/02 08:42:28 pierre
  216. * new set of Gabor changes: see fixes.txt
  217. Revision 1.19 2000/04/25 08:42:33 pierre
  218. * New Gabor changes : see fixes.txt
  219. Revision 1.18 2000/03/21 23:29:52 pierre
  220. + Use TrimEndSlash by Gabor
  221. Revision 1.17 1999/12/01 16:48:09 pierre
  222. * avoid problems after going to root directory
  223. Revision 1.16 1999/11/30 17:15:32 pierre
  224. * avoid chdir('d:') in FPC
  225. Revision 1.15 1999/10/29 13:47:00 pierre
  226. * typo error corrected
  227. Revision 1.14 1999/10/27 10:44:08 pierre
  228. * Avoid ChDir('') gives sometimes DosError 3 !!
  229. Revision 1.13 1999/08/16 18:25:20 peter
  230. * Adjusting the selection when the editor didn't contain any line.
  231. * Reserved word recognition redesigned, but this didn't affect the overall
  232. syntax highlight speed remarkably (at least not on my Amd-K6/350).
  233. The syntax scanner loop is a bit slow but the main problem is the
  234. recognition of special symbols. Switching off symbol processing boosts
  235. the performance up to ca. 200%...
  236. * The editor didn't allow copying (for ex to clipboard) of a single character
  237. * 'File|Save as' caused permanently run-time error 3. Not any more now...
  238. * Compiler Messages window (actually the whole desktop) did not act on any
  239. keypress when compilation failed and thus the window remained visible
  240. + Message windows are now closed upon pressing Esc
  241. + At 'Run' the IDE checks whether any sources are modified, and recompiles
  242. only when neccessary
  243. + BlockRead and BlockWrite (Ctrl+K+R/W) implemented in TCodeEditor
  244. + LineSelect (Ctrl+K+L) implemented
  245. * The IDE had problems closing help windows before saving the desktop
  246. Revision 1.12 1999/08/03 20:22:34 peter
  247. + TTab acts now on Ctrl+Tab and Ctrl+Shift+Tab...
  248. + Desktop saving should work now
  249. - History saved
  250. - Clipboard content saved
  251. - Desktop saved
  252. - Symbol info saved
  253. * syntax-highlight bug fixed, which compared special keywords case sensitive
  254. (for ex. 'asm' caused asm-highlighting, while 'ASM' didn't)
  255. * with 'whole words only' set, the editor didn't found occourences of the
  256. searched text, if the text appeared previously in the same line, but didn't
  257. satisfied the 'whole-word' condition
  258. * ^QB jumped to (SelStart.X,SelEnd.X) instead of (SelStart.X,SelStart.Y)
  259. (ie. the beginning of the selection)
  260. * when started typing in a new line, but not at the start (X=0) of it,
  261. the editor inserted the text one character more to left as it should...
  262. * TCodeEditor.HideSelection (Ctrl-K+H) didn't update the screen
  263. * Shift shouldn't cause so much trouble in TCodeEditor now...
  264. * Syntax highlight had problems recognizing a special symbol if it was
  265. prefixed by another symbol character in the source text
  266. * Auto-save also occours at Dos shell, Tool execution, etc. now...
  267. Revision 1.11 1999/06/25 00:35:54 pierre
  268. + uses weditor FileDir var to remember Directory for Open/Save
  269. Revision 1.10 1999/03/23 15:11:32 peter
  270. * desktop saving things
  271. * vesa mode
  272. * preferences dialog
  273. Revision 1.9 1999/02/19 18:43:47 peter
  274. + open dialog supports mask list
  275. Revision 1.8 1999/02/05 12:11:57 pierre
  276. + SourceDir that stores directories for sources that the
  277. compiler should not know about
  278. Automatically asked for addition when a new file that
  279. needed filedialog to be found is in an unknown directory
  280. Stored and retrieved from INIFile
  281. + Breakpoints conditions added to INIFile
  282. * Breakpoints insterted and removed at debin and end of debug session
  283. Revision 1.7 1999/02/04 13:32:05 pierre
  284. * Several things added (I cannot commit them independently !)
  285. + added TBreakpoint and TBreakpointCollection
  286. + added cmResetDebugger,cmGrep,CmToggleBreakpoint
  287. + Breakpoint list in INIFile
  288. * Select items now also depend of SwitchMode
  289. * Reading of option '-g' was not possible !
  290. + added search for -Fu args pathes in TryToOpen
  291. + added code for automatic opening of FileDialog
  292. if source not found
  293. Revision 1.6 1999/02/02 16:41:41 peter
  294. + automatic .pas/.pp adding by opening of file
  295. * better debuggerscreen changes
  296. Revision 1.5 1999/01/21 11:54:17 peter
  297. + tools menu
  298. + speedsearch in symbolbrowser
  299. * working run command
  300. Revision 1.4 1999/01/14 21:42:21 peter
  301. * source tracking from Gabor
  302. Revision 1.3 1999/01/04 11:49:46 peter
  303. * 'Use tab characters' now works correctly
  304. + Syntax highlight now acts on File|Save As...
  305. + Added a new class to syntax highlight: 'hex numbers'.
  306. * There was something very wrong with the palette managment. Now fixed.
  307. + Added output directory (-FE<xxx>) support to 'Directories' dialog...
  308. * Fixed some possible bugs in Running/Compiling, and the compilation/run
  309. process revised
  310. Revision 1.2 1998/12/28 15:47:47 peter
  311. + Added user screen support, display & window
  312. + Implemented Editor,Mouse Options dialog
  313. + Added location of .INI and .CFG file
  314. + Option (INI) file managment implemented (see bottom of Options Menu)
  315. + Switches updated
  316. + Run program
  317. Revision 1.4 1998/12/24 08:27:12 gabor
  318. + displaying 'opening source file...' text while reading
  319. Revision 1.3 1998/12/22 10:39:46 peter
  320. + options are now written/read
  321. + find and replace routines
  322. }