fpmfile.inc 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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. TE^.Editor^.SetModified(false); { if nothing changes, we don't need to save it }
  57. StartTemplate(LB^.Focused,TE^.Editor);
  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. {$IFNDEF NODEBUG}
  162. if assigned(Debugger) then
  163. Debugger^.SetDirectories;
  164. {$ENDIF}
  165. end;
  166. OpenEditorWindow(nil,FileName,0,0);
  167. end;
  168. OpenSearch:=OpenIt;
  169. end;
  170. procedure TIDEApp.OpenRecentFile(RecentIndex: integer);
  171. begin
  172. with RecentFiles[RecentIndex] do
  173. if OpenEditorWindow(nil,FileName,LastPos.X,LastPos.Y)<>nil then
  174. RemoveRecentFile(RecentIndex);
  175. end;
  176. function TIDEApp.AskSaveAll: boolean;
  177. function CanClose(P: PView): boolean; {$ifndef FPC}far;{$endif}
  178. begin
  179. CanClose:=not P^.Valid(cmAskSaveAll);
  180. end;
  181. begin
  182. AskSaveAll:=Desktop^.FirstThat(@CanClose)=nil;
  183. end;
  184. function TIDEApp.SaveAll: boolean;
  185. procedure SendSave(P: PView); {$ifndef FPC}far;{$endif}
  186. begin
  187. Message(P,evCommand,cmSave,nil);
  188. end;
  189. begin
  190. SaveCancelled:=false;
  191. Desktop^.ForEach(@SendSave);
  192. SaveAll:=not SaveCancelled;
  193. end;
  194. procedure TIDEApp.ChangeDir;
  195. var
  196. D : PChDirDialog;
  197. begin
  198. New(D, Init(cdNormal, hisChDirDialog));
  199. D^.HelpCtx:=hcChangeDir;
  200. ExecuteDialog(D,nil);
  201. CurDirChanged;
  202. end;
  203. {
  204. $Log$
  205. Revision 1.7 2002-10-12 19:43:07 hajny
  206. * missing HasSignal conditionals added (needed for FPC/2)
  207. Revision 1.6 2002/09/07 15:40:43 peter
  208. * old logs removed and tabs fixed
  209. Revision 1.5 2002/08/29 09:58:04 pierre
  210. * remove wrong log line
  211. Revision 1.4 2002/08/29 09:31:53 pierre
  212. * set modified flag to false before prompt
  213. dialog are executed in NewFromTemplate
  214. Revision 1.3 2002/04/10 22:38:11 pierre
  215. * allow to open non existant file
  216. }