Explorar o código

UPD: currently active file is remembered across restarts

Dmitry Frank %!s(int64=11) %!d(string=hai) anos
pai
achega
123bc4a309
Modificáronse 2 ficheiros con 26 adicións e 1 borrados
  1. 16 1
      src/fileviews/ufileview.pas
  2. 10 0
      src/fileviews/ufileviewhistory.pas

+ 16 - 1
src/fileviews/ufileview.pas

@@ -1450,7 +1450,9 @@ begin
     FFlatView:= False;
     EnableWatcher(False);
 
-  //-- before changing path, remember currently active filename
+    //-- before changing path, remember currently active filename
+    //   TODO: move this call to some generic place that is called
+    //         ALWAYS when currently selected file is changed
     FHistory.SetFilenameForCurrentPath(GetActiveFileName());
     FHistory.AddPath(NewPath); // Sets CurrentPath.
     AfterChangePath;
@@ -2399,6 +2401,12 @@ begin
 
   if Assigned(FileSource) then
     FileSource.AddReloadEventListener(@ReloadEvent);
+
+  //TODO: probably it's not the best place for calling SetActiveFile() :
+  //      initially-active file should be set in the same place where
+  //      initial path is set
+  SetActiveFile(FHistory.CurrentFilename);
+
   // No automatic reload here.
 end;
 
@@ -2439,6 +2447,11 @@ var
   PathIndex: Integer;
   ASorting: TFileSortings;
 begin
+  //-- remember currently active filename
+  //   TODO: move this call to some generic place that is called
+  //         ALWAYS when currently selected file is changed
+  FHistory.SetFilenameForCurrentPath(GetActiveFileName());
+
   AConfig.ClearNode(ANode);
 
   // Sorting.
@@ -3098,6 +3111,8 @@ var
   FilenameFromHistory: String;
 begin
   //-- before changing path, remember currently active filename
+  //   TODO: move this call to some generic place that is called
+  //         ALWAYS when currently selected file is changed
   FHistory.SetFilenameForCurrentPath(GetActiveFileName());
 
   IsNewFileSource := not FHistory.FileSource[aFileSourceIndex].Equals(FHistory.CurrentFileSource);

+ 10 - 0
src/fileviews/ufileviewhistory.pas

@@ -47,6 +47,7 @@ type
     function GetCount: Integer; // = FileSourcesCount
     function GetCurrentFileSource: IFileSource;
     function GetCurrentPath: UTF8String;
+    function GetCurrentFilename: UTF8String;
     function GetFileSource(Index: Integer): IFileSource;
     function GetPath(FileSourceIndex, PathIndex: Integer): UTF8String;
     function GetFilename(FileSourceIndex, FilenameIndex: Integer): UTF8String;
@@ -71,6 +72,7 @@ type
     property CurrentFileSource: IFileSource read GetCurrentFileSource;
     property CurrentFileSourceIndex: Integer read FCurrentFileSource write FCurrentFileSource;
     property CurrentPath: UTF8String read GetCurrentPath;
+    property CurrentFilename: UTF8String read GetCurrentFilename;
     property CurrentPathIndex: Integer read FCurrentPath write FCurrentPath;
     property FileSource[Index: Integer]: IFileSource read GetFileSource;
     property Path[FileSourceIndex, PathIndex: Integer]: UTF8String read GetPath;
@@ -162,6 +164,14 @@ begin
     Result := EmptyStr;
 end;
 
+function TFileViewHistory.GetCurrentFilename: UTF8String;
+begin
+  if (FCurrentFileSource >= 0) and (FCurrentPath >= 0) then
+    Result := PFileViewHistoryEntry(FHistory[FCurrentFileSource])^.FilenamesList[FCurrentPath]
+  else
+    Result := EmptyStr;
+end;
+
 function TFileViewHistory.GetFileSource(Index: Integer): IFileSource;
 begin
   Result := PFileViewHistoryEntry(FHistory.Items[Index])^.FileSource;