fpmfile.inc 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. {
  2. This file is part of the Free Pascal Integrated Development Environment
  3. Copyright (c) 1998 by Berczi Gabor
  4. File menu entries
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. procedure TIDEApp.NewEditor;
  12. begin
  13. OpenEditorWindow(nil,'',0,0);
  14. end;
  15. procedure TIDEApp.NewFromTemplate;
  16. var D: PCenterDialog;
  17. R,R2: TRect;
  18. SB: PScrollBar;
  19. LB: PAdvancedListBox;
  20. I: integer;
  21. C: PUnsortedStringCollection;
  22. TE: PSourceWindow;
  23. begin
  24. if GetTemplateCount=0 then
  25. begin InformationBox(msg_notemplatesavailable,nil); Exit; end;
  26. New(C, Init(10,10));
  27. R.Assign(0,0,40,14);
  28. New(D, Init(R, dialog_newfromtemplate));
  29. with D^ do
  30. begin
  31. HelpCtx:=hcNewFromTemplate;
  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. TE^.Editor^.SetModified(false); { if nothing changes, we don't need to save it }
  56. StartTemplate(LB^.Focused,TE^.Editor);
  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;FileDir:string);
  66. var D: PFileDialog;
  67. OpenIt: boolean;
  68. DriveNumber : byte;
  69. StoreDir,StoreDir2 : DirStr;
  70. NewPSW : PSourceWindow;
  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. end;
  86. if (FileDir<>'') and ExistsDir(FileDir) then
  87. ChDir(TrimEndSlash(FileDir));
  88. New(D, Init(OpenExts,dialog_openafile,label_filetoopen,fdOpenButton,hidOpenSourceFile));
  89. D^.HelpCtx:=hcOpen;
  90. OpenIt:=Desktop^.ExecView(D)<>cmCancel;
  91. { if I go to root under go32v2 and there is no
  92. floppy I get a InOutRes = 152
  93. get rid of it ! }
  94. EatIO;
  95. if OpenIt then
  96. Begin
  97. D^.GetFileName(FileName);
  98. OpenExts:=D^.WildCard;
  99. if ExistsDir(DirOf(FExpand(FileName))) then
  100. FileDir:=DirOf(FExpand(FileName));
  101. End;
  102. Dispose(D, Done);
  103. if DriveNumber<>0 then
  104. ChDir(TrimEndSlash(StoreDir2));
  105. ChDir(TrimEndSlash(StoreDir));
  106. end;
  107. if OpenIt then
  108. begin
  109. FileName:=FExpand(LocatePasFile(FileName));
  110. if ExistsFile(FileName) then
  111. { like for BP unexistant files should be created PM }
  112. OpenEditorWindow(nil,FileName,0,0)
  113. else
  114. {ErrorBox(FormatStrStr(msg_cantfindfile,FileName),nil);}
  115. begin
  116. NewPSW:=OpenEditorWindow(nil,'',0,0);
  117. NewPSW^.Editor^.FileName:=FileName;
  118. NewPSW^.SetTitle(FileName);
  119. Message(Application,evBroadcast,cmFileNameChanged,NewPSW^.Editor);
  120. end;
  121. end;
  122. end;
  123. function TIDEApp.OpenSearch(FileName: string) : boolean;
  124. var D: PFileDialog;
  125. OpenIt: boolean;
  126. P : PString;
  127. Dir,S : String;
  128. begin
  129. OpenIt:=False;
  130. if not OpenIt then
  131. begin
  132. ClearFormatParams; AddFormatParamStr(FileName);
  133. FormatStr(S,label_lookingfor,FormatParams);
  134. New(D, Init(FileName,dialog_openafile,S,fdOpenButton,hidOpenSourceFile));
  135. D^.HelpCtx:=hcOpen;
  136. OpenIt:=Desktop^.ExecView(D)<>cmCancel;
  137. if OpenIt then
  138. Begin
  139. D^.GetFileName(FileName);
  140. End;
  141. Dispose(D, Done);
  142. end;
  143. if OpenIt then
  144. begin
  145. FileName:=FExpand(LocatePasFile(FileName));
  146. Dir:=DirOf(FileName);
  147. P:=@Dir;
  148. If Pos(Dir+';',GetSourceDirectories)=0 then
  149. if ConfirmBox(msg_confirmsourcediradd,@P,false)=cmYes then
  150. begin
  151. SourceDirs:=SourceDirs+';'+Dir;
  152. {$IFNDEF NODEBUG}
  153. if assigned(Debugger) then
  154. Debugger^.SetSourceDirs;
  155. {$ENDIF}
  156. end;
  157. OpenEditorWindow(nil,FileName,0,0);
  158. end;
  159. OpenSearch:=OpenIt;
  160. end;
  161. procedure TIDEApp.OpenRecentFile(RecentIndex: integer);
  162. begin
  163. with RecentFiles[RecentIndex] do
  164. if OpenEditorWindow(nil,FileName,LastPos.X,LastPos.Y)<>nil then
  165. RemoveRecentFile(RecentIndex);
  166. end;
  167. function TIDEApp.AskSaveAll: boolean;
  168. function CanClose(P: PView): boolean;
  169. begin
  170. CanClose:=not P^.Valid(cmAskSaveAll);
  171. end;
  172. begin
  173. AskSaveAll:=Desktop^.FirstThat(@CanClose)=nil;
  174. end;
  175. function TIDEApp.SaveAll: boolean;
  176. procedure SendSave(P: PView);
  177. begin
  178. Message(P,evCommand,cmSave,nil);
  179. end;
  180. begin
  181. SaveCancelled:=false;
  182. Desktop^.ForEach(@SendSave);
  183. SaveAll:=not SaveCancelled;
  184. end;
  185. procedure TIDEApp.ChangeDir;
  186. var
  187. D : PChDirDialog;
  188. begin
  189. New(D, Init(cdNormal, hisChDirDialog));
  190. D^.HelpCtx:=hcChangeDir;
  191. ExecuteDialog(D,nil);
  192. CurDirChanged;
  193. { Set new startup dir }
  194. GetDir(0,StartUpDir);
  195. end;
  196. procedure TIDEApp.PrinterSetup;
  197. var R,R2: TRect;
  198. D: PCenterDialog;
  199. IL: PEditorInputLine;
  200. begin
  201. R.Assign(0,0,round(ScreenWidth*54/80),4);
  202. New(D, Init(R, dialog_setupprinter));
  203. with D^ do
  204. begin
  205. GetExtent(R); R.Grow(-2,-1); Inc(R.A.Y); R.B.Y:=R.A.Y+1;
  206. R2.Copy(R); R2.A.X:=16; Dec(R2.B.X,4);
  207. New(IL, Init(R2, 255));
  208. IL^.Data^:=GetPrinterDevice;
  209. Insert(IL);
  210. R2.Copy(R); R2.A.X:=R2.B.X-3; R2.B.X:=R2.A.X+3;
  211. Insert(New(PHistory, Init(R2, IL, hidPrinterDevice)));
  212. R2.Copy(R); R2.B.X:=16;
  213. Insert(New(PLabel, Init(R2, label_setupprinter_device, IL)));
  214. end;
  215. InsertButtons(D);
  216. IL^.Select;
  217. if Desktop^.ExecView(D)=cmOK then
  218. SetPrinterDevice(IL^.Data^);
  219. Dispose(D, Done);
  220. end;
  221. procedure TIDEApp.Print;
  222. var
  223. d : string;
  224. P : PSourceWindow;
  225. i : longint;
  226. f : text;
  227. begin
  228. d:=GetPrinterDevice;
  229. { sanity check }
  230. if d='' then
  231. d:='prn';
  232. P:=Message(Desktop,evBroadcast,cmSearchWindow,nil);
  233. if assigned(P) then
  234. begin
  235. assign(f,d);
  236. {$I-}
  237. rewrite(f);
  238. {$I+}
  239. if ioresult<>0 then
  240. begin
  241. MessageBox(#3+msg_printernotopened,nil,mferror+mfokbutton);
  242. exit;
  243. end;
  244. for i:=0 to P^.Editor^.Core^.GetLineCount-1 do
  245. begin
  246. writeln(f,P^.Editor^.Core^.GetLineText(i));
  247. if ioresult<>0 then
  248. begin
  249. MessageBox(#3+msg_PrintError,nil,mferror+mfokbutton);
  250. close(f);
  251. exit;
  252. end;
  253. end;
  254. write(f,#12);
  255. close(f);
  256. end;
  257. end;