Browse Source

+ saving and opening of open files on exit

pierre 26 years ago
parent
commit
925bf35c30
3 changed files with 114 additions and 11 deletions
  1. 12 5
      ide/text/fp.pas
  2. 79 5
      ide/text/fpini.pas
  3. 23 1
      ide/text/wini.pas

+ 12 - 5
ide/text/fp.pas

@@ -85,19 +85,22 @@ BEGIN
   InitTools;
   InitTools;
   InitTemplates;
   InitTemplates;
 
 
-{ load old options }
-  ReadINIFile;
   ReadSwitches(SwitchesPath);
   ReadSwitches(SwitchesPath);
 
 
   MyApp.Init;
   MyApp.Init;
+  { load all options after init because of open files }
+  ReadINIFile;
 
 
   ProcessParams(false);
   ProcessParams(false);
 
 
   MyApp.Run;
   MyApp.Run;
+
+  { must be written before done for open files }
+  WriteINIFile;
+
   MyApp.Done;
   MyApp.Done;
 
 
   WriteSwitches(SwitchesPath);
   WriteSwitches(SwitchesPath);
-  WriteINIFile;
 
 
   DoneTemplates;
   DoneTemplates;
   DoneTools;
   DoneTools;
@@ -111,11 +114,15 @@ BEGIN
 END.
 END.
 {
 {
   $Log$
   $Log$
-  Revision 1.13  1999-03-01 15:41:48  peter
+  Revision 1.14  1999-03-05 17:53:00  pierre
+   + saving and opening of open files on exit
+
+  Revision 1.13  1999/03/01 15:41:48  peter
     + Added dummy entries for functions not yet implemented
     + Added dummy entries for functions not yet implemented
     * MenuBar didn't update itself automatically on command-set changes
     * MenuBar didn't update itself automatically on command-set changes
     * Fixed Debugging/Profiling options dialog
     * Fixed Debugging/Profiling options dialog
-    * TCodeEditor converts spaces to tabs at save only if efUseTabChars is
 set
+    * TCodeEditor converts spaces to tabs at save only if efUseTabChars is
+ set
     * efBackSpaceUnindents works correctly
     * efBackSpaceUnindents works correctly
     + 'Messages' window implemented
     + 'Messages' window implemented
     + Added '$CAP MSG()' and '$CAP EDIT' to available tool-macros
     + Added '$CAP MSG()' and '$CAP EDIT' to available tool-macros

+ 79 - 5
ide/text/fpini.pas

@@ -34,9 +34,9 @@ function  WriteINIFile: boolean;
 implementation
 implementation
 
 
 uses
 uses
-  Dos,Objects,Drivers,
+  Dos,Objects,Drivers,App,
   WINI,{$ifndef EDITORS}WEditor{$else}Editors{$endif},
   WINI,{$ifndef EDITORS}WEditor{$else}Editors{$endif},
-  FPDebug,FPConst,FPVars,
+  FPDebug,FPConst,FPVars,FPViews,
   FPIntf,FPTools,FPSwitch;
   FPIntf,FPTools,FPSwitch;
 
 
 const
 const
@@ -56,6 +56,8 @@ const
 
 
   { INI file tags }
   { INI file tags }
   ieRecentFile       = 'RecentFile';
   ieRecentFile       = 'RecentFile';
+  ieOpenFile         = 'OpenFile';
+  ieOpenFileCount    = 'OpenFileCount';
   ieRunParameters    = 'Parameters';
   ieRunParameters    = 'Parameters';
   iePrimaryFile      = 'PrimaryFile';
   iePrimaryFile      = 'PrimaryFile';
   ieCompileMode      = 'CompileMode';
   ieCompileMode      = 'CompileMode';
@@ -207,10 +209,12 @@ function ReadINIFile: boolean;
 var INIFile: PINIFile;
 var INIFile: PINIFile;
     S,PS,S1,S2,S3: string;
     S,PS,S1,S2,S3: string;
     I,P: integer;
     I,P: integer;
+    X,Y : sw_integer;
     BreakPointCount:longint;
     BreakPointCount:longint;
     OK: boolean;
     OK: boolean;
     ts : TSwitchMode;
     ts : TSwitchMode;
     W: word;
     W: word;
+    R : TRect;
 begin
 begin
   OK:=ExistsFile(INIPath);
   OK:=ExistsFile(INIPath);
   if OK then
   if OK then
@@ -293,6 +297,44 @@ begin
   PS:=PS+StrToPalette(INIFile^.GetEntry(secColors,iePalette+'_161_200',PaletteToStr(copy(S,161,40))));
   PS:=PS+StrToPalette(INIFile^.GetEntry(secColors,iePalette+'_161_200',PaletteToStr(copy(S,161,40))));
   PS:=PS+StrToPalette(INIFile^.GetEntry(secColors,iePalette+'_201_240',PaletteToStr(copy(S,201,40))));
   PS:=PS+StrToPalette(INIFile^.GetEntry(secColors,iePalette+'_201_240',PaletteToStr(copy(S,201,40))));
   AppPalette:=PS;
   AppPalette:=PS;
+  for I:=INIFile^.GetIntEntry(secFiles,ieOpenFileCount,0) downto 1 do
+    begin
+      S:=INIFile^.GetEntry(secFiles,ieOpenFile+IntToStr(I),'');
+      if (S='') then
+        break;
+      P:=Pos(',',S); if P=0 then P:=length(S)+1;
+      S1:=copy(S,1,P-1);
+      Delete(S,1,P);
+      P:=Pos(',',S);
+      if P=0 then P:=length(S)+1;
+      X:=Max(0,StrToInt(copy(S,1,P-1)));
+      Delete(S,1,P);
+      P:=Pos(',',S);
+      if P=0 then P:=length(S)+1;
+      Y:=Max(0,StrToInt(copy(S,1,P-1)));
+      Delete(S,1,P);
+      P:=Pos(',',S);
+      if P=0 then P:=length(S)+1;
+      R.A.X:=Max(0,StrToInt(copy(S,1,P-1)));
+      Delete(S,1,P);
+      P:=Pos(',',S);
+      if P=0 then P:=length(S)+1;
+      R.A.Y:=Max(0,StrToInt(copy(S,1,P-1)));
+      Delete(S,1,P);
+      P:=Pos(',',S);
+      if P=0 then P:=length(S)+1;
+      R.B.X:=Max(0,StrToInt(copy(S,1,P-1)));
+      Delete(S,1,P);
+      P:=Pos(',',S);
+      if P=0 then P:=length(S)+1;
+      R.B.Y:=Max(0,StrToInt(copy(S,1,P-1)));
+      if (R.A.X<R.B.X) and (R.A.Y<R.B.Y) then
+        TryToOpenFile(@R,S1,X,Y)
+      else
+        TryToOpenFile(nil,S1,X,Y);
+      { remove it because otherwise we allways keep old files }  
+      INIFile^.DeleteEntry(secFiles,ieOpenFile+IntToStr(I));
+    end;
   Dispose(INIFile, Done);
   Dispose(INIFile, Done);
  end;
  end;
   ReadINIFile:=OK;
   ReadINIFile:=OK;
@@ -301,11 +343,14 @@ end;
 function WriteINIFile: boolean;
 function WriteINIFile: boolean;
 var INIFile: PINIFile;
 var INIFile: PINIFile;
     S: string;
     S: string;
+    R : TRect;
     S1,S2,S3: string;
     S1,S2,S3: string;
     W: word;
     W: word;
     BreakPointCount:longint;
     BreakPointCount:longint;
-    I: integer;
+    I,OpenFileCount: integer;
     OK: boolean;
     OK: boolean;
+    PW,PPW : PSourceWindow;
+
 procedure ConcatName(P: PString); {$ifndef FPC}far;{$endif}
 procedure ConcatName(P: PString); {$ifndef FPC}far;{$endif}
 begin
 begin
   if (S<>'') then S:=S+';';
   if (S<>'') then S:=S+';';
@@ -323,6 +368,31 @@ begin
          S:='';
          S:='';
       INIFile^.SetEntry(secFiles,ieRecentFile+IntToStr(I),S);
       INIFile^.SetEntry(secFiles,ieRecentFile+IntToStr(I),S);
     end;
     end;
+
+    PW:=FirstEditorWindow;
+    PPW:=PW;
+    I:=1;
+    while assigned(PW) do
+      begin
+        If PW^.HelpCtx=hcSourceWindow then
+          begin
+            With PW^.editor^ do
+              S:=FileName+','+IntToStr(CurPos.X)+','+IntToStr(CurPos.Y);
+            PW^.GetBounds(R);
+            S:=S+','+IntToStr(R.A.X)+','+IntToStr(R.A.Y)+','+
+              IntToStr(R.B.X)+','+IntToStr(R.B.Y);
+            INIFile^.SetEntry(secFiles,ieOpenFile+IntToStr(I),S);
+            Inc(I);
+            OpenFileCount:=I-1;
+          end;
+          
+        PW:=PSourceWindow(PW^.next);
+        While assigned(PW) and (PW<>PPW) and (PW^.HelpCtx<>hcSourceWindow) do
+          PW:=PSourceWindow(PW^.next);
+        If PW=PPW then                                                                                                                                                                                                                                         
+          break;
+      end;
+  INIFile^.SetIntEntry(secFiles,ieOpenFileCount,OpenFileCount);
   { Run }
   { Run }
   INIFile^.SetEntry(secRun,ieRunParameters,GetRunParameters);
   INIFile^.SetEntry(secRun,ieRunParameters,GetRunParameters);
   { Compile }
   { Compile }
@@ -391,11 +461,15 @@ end;
 end.
 end.
 {
 {
   $Log$
   $Log$
-  Revision 1.14  1999-03-01 15:41:55  peter
+  Revision 1.15  1999-03-05 17:53:02  pierre
+   + saving and opening of open files on exit
+
+  Revision 1.14  1999/03/01 15:41:55  peter
     + Added dummy entries for functions not yet implemented
     + Added dummy entries for functions not yet implemented
     * MenuBar didn't update itself automatically on command-set changes
     * MenuBar didn't update itself automatically on command-set changes
     * Fixed Debugging/Profiling options dialog
     * Fixed Debugging/Profiling options dialog
-    * TCodeEditor converts spaces to tabs at save only if efUseTabChars is
 set
+    * TCodeEditor converts spaces to tabs at save only if efUseTabChars is
+ set
     * efBackSpaceUnindents works correctly
     * efBackSpaceUnindents works correctly
     + 'Messages' window implemented
     + 'Messages' window implemented
     + Added '$CAP MSG()' and '$CAP EDIT' to available tool-macros
     + Added '$CAP MSG()' and '$CAP EDIT' to available tool-macros

+ 23 - 1
ide/text/wini.pas

@@ -45,6 +45,7 @@ type
       function    GetName: string;
       function    GetName: string;
       function    AddEntry(const S: string): PINIEntry;
       function    AddEntry(const S: string): PINIEntry;
       function    SearchEntry(Tag: string): PINIEntry; virtual;
       function    SearchEntry(Tag: string): PINIEntry; virtual;
+      procedure   DeleteEntry(Tag: string);
       procedure   ForEachEntry(EnumProc: pointer); virtual;
       procedure   ForEachEntry(EnumProc: pointer); virtual;
       destructor  Done; virtual;
       destructor  Done; virtual;
     private
     private
@@ -67,6 +68,7 @@ type
       function    GetIntEntry(const Section, Tag: string; Default: longint): longint; virtual;
       function    GetIntEntry(const Section, Tag: string; Default: longint): longint; virtual;
       procedure   SetIntEntry(const Section, Tag: string; Value: longint); virtual;
       procedure   SetIntEntry(const Section, Tag: string; Value: longint); virtual;
       procedure   DeleteSection(const Section: string); virtual;
       procedure   DeleteSection(const Section: string); virtual;
+      procedure   DeleteEntry(const Section, Tag: string);
       destructor  Done; virtual;
       destructor  Done; virtual;
     private
     private
       ReadOnly: boolean;
       ReadOnly: boolean;
@@ -229,6 +231,15 @@ begin
   SearchEntry:=Entries^.FirstThat(@MatchingEntry);
   SearchEntry:=Entries^.FirstThat(@MatchingEntry);
 end;
 end;
 
 
+procedure TINISection.DeleteEntry(Tag: string);
+var
+  P : PIniEntry; 
+begin
+  P:=SearchEntry(Tag);
+  if assigned(P) then
+    Entries^.Free(P);
+end;
+
 destructor TINISection.Done;
 destructor TINISection.Done;
 begin
 begin
   inherited Done;
   inherited Done;
@@ -442,6 +453,14 @@ begin
     Sections^.Free(P);
     Sections^.Free(P);
 end;
 end;
 
 
+procedure TINIFile.DeleteEntry(const Section, Tag: string);
+var P: PINISection;
+begin
+  P:=SearchSection(Section);
+  if P<>nil then
+    P^.DeleteEntry(Tag);
+end;
+                                                                                                                                                                                                                                                               
 destructor TINIFile.Done;
 destructor TINIFile.Done;
 begin
 begin
   if IsModified then
   if IsModified then
@@ -456,7 +475,10 @@ end;
 END.
 END.
 {
 {
   $Log$
   $Log$
-  Revision 1.6  1999-03-01 15:42:15  peter
+  Revision 1.7  1999-03-05 17:53:03  pierre
+   + saving and opening of open files on exit
+
+  Revision 1.6  1999/03/01 15:42:15  peter
     + Added dummy entries for functions not yet implemented
     + Added dummy entries for functions not yet implemented
     * MenuBar didn't update itself automatically on command-set changes
     * MenuBar didn't update itself automatically on command-set changes
     * Fixed Debugging/Profiling options dialog
     * Fixed Debugging/Profiling options dialog