fpmfile.inc 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  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('No templates available.',nil); Exit; end;
  27. New(C, Init(10,10));
  28. R.Assign(0,0,40,14);
  29. New(D, Init(R, 'New from template'));
  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, 'Available ~t~emplates', 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, 'O~K~', cmOK, bfDefault)));
  45. R2.Move(0,2);
  46. Insert(New(PButton, Init(R2, '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(FileDir);
  91. New(D, Init(OpenExts,'Open a file','File to ope~n~',fdOpenButton,0));
  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(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(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 : String;
  123. begin
  124. OpenIt:=False;
  125. if not OpenIt then
  126. begin
  127. New(D, Init(FileName+'*','Open a file','Looking for '+FileName,fdOpenButton,0));
  128. OpenIt:=Desktop^.ExecView(D)<>cmCancel;
  129. if OpenIt then
  130. Begin
  131. D^.GetFileName(FileName);
  132. End;
  133. Dispose(D, Done);
  134. end;
  135. if OpenIt then
  136. begin
  137. FileName:=FExpand(LocatePasFile(FileName));
  138. Dir:=DirOf(FileName);
  139. P:=@Dir;
  140. If Pos(Dir+';',GetSourceDirectories)=0 then
  141. if ConfirmBox(#3'Directory %s is not in list'#13#3+
  142. 'Should we add it ?',@P,false)=cmYes then
  143. SourceDirs:=SourceDirs+';'+Dir;
  144. OpenEditorWindow(nil,FileName,0,0);
  145. end;
  146. OpenSearch:=OpenIt;
  147. end;
  148. procedure TIDEApp.OpenRecentFile(RecentIndex: integer);
  149. begin
  150. with RecentFiles[RecentIndex] do
  151. if OpenEditorWindow(nil,FileName,LastPos.X,LastPos.Y)<>nil then
  152. RemoveRecentFile(RecentIndex);
  153. end;
  154. function TIDEApp.SaveAll: boolean;
  155. procedure SendSave(P: PView); {$ifndef FPC}far;{$endif}
  156. begin
  157. Message(P,evCommand,cmSave,nil);
  158. end;
  159. begin
  160. SaveCancelled:=false;
  161. Desktop^.ForEach(@SendSave);
  162. SaveAll:=not SaveCancelled;
  163. end;
  164. procedure TIDEApp.ChangeDir;
  165. begin
  166. ExecuteDialog(New(PChDirDialog, Init(cdNormal, hisChDirDialog)),nil);
  167. CurDirChanged;
  168. end;
  169. {
  170. $Log$
  171. Revision 1.17 1999-12-01 16:48:09 pierre
  172. * avoid problems after going to root directory
  173. Revision 1.16 1999/11/30 17:15:32 pierre
  174. * avoid chdir('d:') in FPC
  175. Revision 1.15 1999/10/29 13:47:00 pierre
  176. * typo error corrected
  177. Revision 1.14 1999/10/27 10:44:08 pierre
  178. * Avoid ChDir('') gives sometimes DosError 3 !!
  179. Revision 1.13 1999/08/16 18:25:20 peter
  180. * Adjusting the selection when the editor didn't contain any line.
  181. * Reserved word recognition redesigned, but this didn't affect the overall
  182. syntax highlight speed remarkably (at least not on my Amd-K6/350).
  183. The syntax scanner loop is a bit slow but the main problem is the
  184. recognition of special symbols. Switching off symbol processing boosts
  185. the performance up to ca. 200%...
  186. * The editor didn't allow copying (for ex to clipboard) of a single character
  187. * 'File|Save as' caused permanently run-time error 3. Not any more now...
  188. * Compiler Messages window (actually the whole desktop) did not act on any
  189. keypress when compilation failed and thus the window remained visible
  190. + Message windows are now closed upon pressing Esc
  191. + At 'Run' the IDE checks whether any sources are modified, and recompiles
  192. only when neccessary
  193. + BlockRead and BlockWrite (Ctrl+K+R/W) implemented in TCodeEditor
  194. + LineSelect (Ctrl+K+L) implemented
  195. * The IDE had problems closing help windows before saving the desktop
  196. Revision 1.12 1999/08/03 20:22:34 peter
  197. + TTab acts now on Ctrl+Tab and Ctrl+Shift+Tab...
  198. + Desktop saving should work now
  199. - History saved
  200. - Clipboard content saved
  201. - Desktop saved
  202. - Symbol info saved
  203. * syntax-highlight bug fixed, which compared special keywords case sensitive
  204. (for ex. 'asm' caused asm-highlighting, while 'ASM' didn't)
  205. * with 'whole words only' set, the editor didn't found occourences of the
  206. searched text, if the text appeared previously in the same line, but didn't
  207. satisfied the 'whole-word' condition
  208. * ^QB jumped to (SelStart.X,SelEnd.X) instead of (SelStart.X,SelStart.Y)
  209. (ie. the beginning of the selection)
  210. * when started typing in a new line, but not at the start (X=0) of it,
  211. the editor inserted the text one character more to left as it should...
  212. * TCodeEditor.HideSelection (Ctrl-K+H) didn't update the screen
  213. * Shift shouldn't cause so much trouble in TCodeEditor now...
  214. * Syntax highlight had problems recognizing a special symbol if it was
  215. prefixed by another symbol character in the source text
  216. * Auto-save also occours at Dos shell, Tool execution, etc. now...
  217. Revision 1.11 1999/06/25 00:35:54 pierre
  218. + uses weditor FileDir var to remember Directory for Open/Save
  219. Revision 1.10 1999/03/23 15:11:32 peter
  220. * desktop saving things
  221. * vesa mode
  222. * preferences dialog
  223. Revision 1.9 1999/02/19 18:43:47 peter
  224. + open dialog supports mask list
  225. Revision 1.8 1999/02/05 12:11:57 pierre
  226. + SourceDir that stores directories for sources that the
  227. compiler should not know about
  228. Automatically asked for addition when a new file that
  229. needed filedialog to be found is in an unknown directory
  230. Stored and retrieved from INIFile
  231. + Breakpoints conditions added to INIFile
  232. * Breakpoints insterted and removed at debin and end of debug session
  233. Revision 1.7 1999/02/04 13:32:05 pierre
  234. * Several things added (I cannot commit them independently !)
  235. + added TBreakpoint and TBreakpointCollection
  236. + added cmResetDebugger,cmGrep,CmToggleBreakpoint
  237. + Breakpoint list in INIFile
  238. * Select items now also depend of SwitchMode
  239. * Reading of option '-g' was not possible !
  240. + added search for -Fu args pathes in TryToOpen
  241. + added code for automatic opening of FileDialog
  242. if source not found
  243. Revision 1.6 1999/02/02 16:41:41 peter
  244. + automatic .pas/.pp adding by opening of file
  245. * better debuggerscreen changes
  246. Revision 1.5 1999/01/21 11:54:17 peter
  247. + tools menu
  248. + speedsearch in symbolbrowser
  249. * working run command
  250. Revision 1.4 1999/01/14 21:42:21 peter
  251. * source tracking from Gabor
  252. Revision 1.3 1999/01/04 11:49:46 peter
  253. * 'Use tab characters' now works correctly
  254. + Syntax highlight now acts on File|Save As...
  255. + Added a new class to syntax highlight: 'hex numbers'.
  256. * There was something very wrong with the palette managment. Now fixed.
  257. + Added output directory (-FE<xxx>) support to 'Directories' dialog...
  258. * Fixed some possible bugs in Running/Compiling, and the compilation/run
  259. process revised
  260. Revision 1.2 1998/12/28 15:47:47 peter
  261. + Added user screen support, display & window
  262. + Implemented Editor,Mouse Options dialog
  263. + Added location of .INI and .CFG file
  264. + Option (INI) file managment implemented (see bottom of Options Menu)
  265. + Switches updated
  266. + Run program
  267. Revision 1.4 1998/12/24 08:27:12 gabor
  268. + displaying 'opening source file...' text while reading
  269. Revision 1.3 1998/12/22 10:39:46 peter
  270. + options are now written/read
  271. + find and replace routines
  272. }