2
0

fpmfile.inc 12 KB

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