fpmfile.inc 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  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. {$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. { like for BP unexistant files should be created PM }
  120. OpenEditorWindow(nil,FileName,0,0)
  121. else
  122. {ErrorBox(FormatStrStr(msg_cantfindfile,FileName),nil);}
  123. begin
  124. NewPSW:=OpenEditorWindow(nil,'',0,0);
  125. NewPSW^.Editor^.FileName:=FileName;
  126. NewPSW^.SetTitle(FileName);
  127. Message(Application,evBroadcast,cmFileNameChanged,NewPSW^.Editor);
  128. end;
  129. end;
  130. end;
  131. function TIDEApp.OpenSearch(FileName: string) : boolean;
  132. var D: PFileDialog;
  133. OpenIt: boolean;
  134. P : PString;
  135. Dir,S : String;
  136. begin
  137. OpenIt:=False;
  138. if not OpenIt then
  139. begin
  140. ClearFormatParams; AddFormatParamStr(FileName);
  141. FormatStr(S,label_lookingfor,FormatParams);
  142. New(D, Init(FileName,dialog_openafile,S,fdOpenButton,hidOpenSourceFile));
  143. D^.HelpCtx:=hcOpen;
  144. OpenIt:=Desktop^.ExecView(D)<>cmCancel;
  145. if OpenIt then
  146. Begin
  147. D^.GetFileName(FileName);
  148. End;
  149. Dispose(D, Done);
  150. end;
  151. if OpenIt then
  152. begin
  153. FileName:=FExpand(LocatePasFile(FileName));
  154. Dir:=DirOf(FileName);
  155. P:=@Dir;
  156. If Pos(Dir+';',GetSourceDirectories)=0 then
  157. if ConfirmBox(msg_confirmsourcediradd,@P,false)=cmYes then
  158. begin
  159. SourceDirs:=SourceDirs+';'+Dir;
  160. {$IFNDEF NODEBUG}
  161. if assigned(Debugger) then
  162. Debugger^.SetSourceDirs;
  163. {$ENDIF}
  164. end;
  165. OpenEditorWindow(nil,FileName,0,0);
  166. end;
  167. OpenSearch:=OpenIt;
  168. end;
  169. procedure TIDEApp.OpenRecentFile(RecentIndex: integer);
  170. begin
  171. with RecentFiles[RecentIndex] do
  172. if OpenEditorWindow(nil,FileName,LastPos.X,LastPos.Y)<>nil then
  173. RemoveRecentFile(RecentIndex);
  174. end;
  175. function TIDEApp.AskSaveAll: boolean;
  176. function CanClose(P: PView): boolean; {$ifndef FPC}far;{$endif}
  177. begin
  178. CanClose:=not P^.Valid(cmAskSaveAll);
  179. end;
  180. begin
  181. AskSaveAll:=Desktop^.FirstThat(@CanClose)=nil;
  182. end;
  183. function TIDEApp.SaveAll: boolean;
  184. procedure SendSave(P: PView); {$ifndef FPC}far;{$endif}
  185. begin
  186. Message(P,evCommand,cmSave,nil);
  187. end;
  188. begin
  189. SaveCancelled:=false;
  190. Desktop^.ForEach(@SendSave);
  191. SaveAll:=not SaveCancelled;
  192. end;
  193. procedure TIDEApp.ChangeDir;
  194. var
  195. D : PChDirDialog;
  196. begin
  197. New(D, Init(cdNormal, hisChDirDialog));
  198. D^.HelpCtx:=hcChangeDir;
  199. ExecuteDialog(D,nil);
  200. CurDirChanged;
  201. { Set new startup dir }
  202. GetDir(0,StartUpDir);
  203. end;
  204. procedure TIDEApp.PrinterSetup;
  205. var R,R2: TRect;
  206. D: PCenterDialog;
  207. IL: PEditorInputLine;
  208. begin
  209. R.Assign(0,0,round(ScreenWidth*54/80),4);
  210. New(D, Init(R, dialog_setupprinter));
  211. with D^ do
  212. begin
  213. GetExtent(R); R.Grow(-2,-1); Inc(R.A.Y); R.B.Y:=R.A.Y+1;
  214. R2.Copy(R); R2.A.X:=16; Dec(R2.B.X,4);
  215. New(IL, Init(R2, 255));
  216. IL^.Data^:=GetPrinterDevice;
  217. Insert(IL);
  218. R2.Copy(R); R2.A.X:=R2.B.X-3; R2.B.X:=R2.A.X+3;
  219. Insert(New(PHistory, Init(R2, IL, hidPrinterDevice)));
  220. R2.Copy(R); R2.B.X:=16;
  221. Insert(New(PLabel, Init(R2, label_setupprinter_device, IL)));
  222. end;
  223. InsertButtons(D);
  224. IL^.Select;
  225. if Desktop^.ExecView(D)=cmOK then
  226. SetPrinterDevice(IL^.Data^);
  227. Dispose(D, Done);
  228. end;
  229. procedure TIDEApp.Print;
  230. var
  231. d : string;
  232. P : PSourceWindow;
  233. i : longint;
  234. f : text;
  235. begin
  236. d:=GetPrinterDevice;
  237. { sanity check }
  238. if d='' then
  239. d:='prn';
  240. P:=Message(Desktop,evBroadcast,cmSearchWindow,nil);
  241. if assigned(P) then
  242. begin
  243. assign(f,d);
  244. rewrite(f);
  245. if ioresult<>0 then
  246. begin
  247. MessageBox(#3+msg_PrintError,nil,mferror+mfokbutton);
  248. exit;
  249. end;
  250. for i:=0 to P^.Editor^.Core^.GetLineCount-1 do
  251. begin
  252. writeln(f,P^.Editor^.Core^.GetLineText(i));
  253. if ioresult<>0 then
  254. begin
  255. MessageBox(#3+msg_PrintError,nil,mferror+mfokbutton);
  256. close(f);
  257. exit;
  258. end;
  259. end;
  260. write(f,#12);
  261. close(f);
  262. end;
  263. end;