fpmfile.inc 11 KB

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