Browse Source

+ FileDir remembers the last directory for Open and Save

pierre 26 years ago
parent
commit
34d1f98e42
1 changed files with 40 additions and 13 deletions
  1. 40 13
      ide/text/weditor.pas

+ 40 - 13
ide/text/weditor.pas

@@ -18,7 +18,7 @@ unit WEditor;
 interface
 interface
 
 
 uses
 uses
-  Objects,Drivers,Views,Menus,Commands;
+  Dos,Objects,Drivers,Views,Menus,Commands;
 
 
 const
 const
       cmFileNameChanged      = 51234;
       cmFileNameChanged      = 51234;
@@ -345,6 +345,7 @@ const
      NumberChars        : set of char = ['0'..'9'];
      NumberChars        : set of char = ['0'..'9'];
      RealNumberChars    : set of char = ['E','e','.','+','-'];
      RealNumberChars    : set of char = ['E','e','.','+','-'];
      DefaultSaveExt     : string[12] = '.pas';
      DefaultSaveExt     : string[12] = '.pas';
+     FileDir            : DirStr = '';
 
 
      UseSyntaxHighlight : function(Editor: PFileEditor): boolean = DefUseSyntaxHighlight;
      UseSyntaxHighlight : function(Editor: PFileEditor): boolean = DefUseSyntaxHighlight;
      UseTabsPattern     : function(Editor: PFileEditor): boolean = DefUseTabsPattern;
      UseTabsPattern     : function(Editor: PFileEditor): boolean = DefUseTabsPattern;
@@ -354,7 +355,6 @@ procedure RegisterCodeEditors;
 implementation
 implementation
 
 
 uses
 uses
-  Dos,
   MsgBox,Dialogs,App,StdDlg,HistList,Validate,
   MsgBox,Dialogs,App,StdDlg,HistList,Validate,
   WUtils,WViews;
   WUtils,WViews;
 
 
@@ -3494,6 +3494,8 @@ var
   T: TPoint;
   T: TPoint;
   Re: word;
   Re: word;
   Name: string;
   Name: string;
+  DriveNumber : byte; 
+  StoreDir,StoreDir2 : DirStr;
 begin
 begin
   case Dialog of
   case Dialog of
     edOutOfMemory:
     edOutOfMemory:
@@ -3516,16 +3518,38 @@ begin
    nil, mfInsertInApp+ mfInformation + mfYesNoCancel);
    nil, mfInsertInApp+ mfInformation + mfYesNoCancel);
     edSaveAs:
     edSaveAs:
       begin
       begin
-   Name:=PString(Info)^;
-   Re:=Application^.ExecuteDialog(New(PFileDialog, Init('*'+DefaultSaveExt,
-   'Save file as', '~N~ame', fdOkButton, 101)), @Name);
-   if (Re<>cmCancel) and (Name<>PString(Info)^) then
-     if ExistsFile(Name) then
-       if EditorDialog(edReplaceFile,@Name)<>cmYes then
-         Re:=cmCancel;
-   if Re<>cmCancel then
-     PString(Info)^:=Name;
-   StdEditorDialog := Re;
+        Name:=PString(Info)^;
+        GetDir(0,StoreDir);
+        DriveNumber:=0;
+        if (Length(FileDir)>1) and (FileDir[2]=':') then
+          begin
+            { does not assume that lowercase are greater then uppercase ! }
+            if (FileDir[1]>='a') and (FileDir[1]>='z') then
+              DriveNumber:=Ord(FileDir[1])-ord('a')+1
+            else
+              DriveNumber:=Ord(FileDir[1])-ord('A')+1;
+            GetDir(DriveNumber,StoreDir2);
+            ChDir(Copy(FileDir,1,2));
+          end;
+        ChDir(FileDir);
+        Re:=Application^.ExecuteDialog(New(PFileDialog, Init('*'+DefaultSaveExt,
+          'Save file as', '~N~ame', fdOkButton, 101)), @Name);
+        if (Re<>cmCancel) and (Name<>PString(Info)^) then
+          begin
+            FileDir:=DirOf(FExpand(Name));
+            if ExistsFile(Name) then
+              if EditorDialog(edReplaceFile,@Name)<>cmYes then
+                Re:=cmCancel;
+          end;
+        if DriveNumber<>0 then
+          ChDir(StoreDir2);
+        if (Length(StoreDir)>1) and (StoreDir[2]=':') then                                                                                                                                                                                                     
+          ChDir(Copy(StoreDir,1,2));                                                                                                                                                                                                                           
+        ChDir(StoreDir);                                                                                                                                                                                                                                       
+
+        if Re<>cmCancel then
+          PString(Info)^:=Name;
+        StdEditorDialog := Re;
       end;
       end;
     edGotoLine:
     edGotoLine:
       StdEditorDialog :=
       StdEditorDialog :=
@@ -3578,7 +3602,10 @@ end;
 END.
 END.
 {
 {
   $Log$
   $Log$
-  Revision 1.32  1999-06-21 23:36:12  pierre
+  Revision 1.33  1999-06-25 00:31:51  pierre
+   + FileDir remembers the last directory for Open and Save
+
+  Revision 1.32  1999/06/21 23:36:12  pierre
    * Size for Cluster is word (TP compatibility)
    * Size for Cluster is word (TP compatibility)
 
 
   Revision 1.31  1999/05/22 13:44:35  peter
   Revision 1.31  1999/05/22 13:44:35  peter