mirror of
https://github.com/doublecmd/doublecmd.git
synced 2026-06-21 09:58:13 +00:00
ADD: Support for FileCreated, FileDeleted, etc., events in the file view (#0000012).
This commit is contained in:
parent
21bb48bb11
commit
f3f1a4ee8d
5 changed files with 202 additions and 9 deletions
|
|
@ -1357,7 +1357,6 @@ end;
|
|||
procedure TColumnsFileView.edtRenameExit(Sender: TObject);
|
||||
begin
|
||||
edtRename.Visible := False;
|
||||
UnMarkAll;
|
||||
|
||||
// dgPanelEnter don't called automatically (bug?)
|
||||
dgPanelEnter(dgPanel);
|
||||
|
|
|
|||
|
|
@ -94,6 +94,10 @@ type
|
|||
function Clone: TFile;
|
||||
procedure CloneTo(AFile: TFile);
|
||||
|
||||
{en
|
||||
Frees all properties except for Name (which is always required).
|
||||
}
|
||||
procedure ClearProperties;
|
||||
function ReleaseProperty(PropType: TFilePropertyType): TFileProperty;
|
||||
|
||||
{en
|
||||
|
|
@ -328,6 +332,15 @@ begin
|
|||
end;
|
||||
end;
|
||||
|
||||
procedure TFile.ClearProperties;
|
||||
var
|
||||
PropertyType: TFilePropertyType;
|
||||
begin
|
||||
for PropertyType := Succ(fpName) to High(TFilePropertyType) do
|
||||
FreeAndNil(FProperties[PropertyType]);
|
||||
FSupportedProperties := [fpName];
|
||||
end;
|
||||
|
||||
function TFile.ReleaseProperty(PropType: TFilePropertyType): TFileProperty;
|
||||
begin
|
||||
Result := FProperties[PropType];
|
||||
|
|
|
|||
|
|
@ -713,7 +713,13 @@ end;
|
|||
function TFileSystemFileSource.GetRetrievableFileProperties: TFilePropertiesTypes;
|
||||
begin
|
||||
Result := inherited GetRetrievableFileProperties
|
||||
+ [fpOwner,
|
||||
+ [fpSize,
|
||||
fpAttributes,
|
||||
fpModificationTime,
|
||||
fpCreationTime,
|
||||
fpLastAccessTime,
|
||||
uFileProperty.fpLink,
|
||||
fpOwner,
|
||||
fpType,
|
||||
fpComment
|
||||
{$IF DEFINED(MSWINDOWS)}
|
||||
|
|
|
|||
|
|
@ -97,6 +97,7 @@ type
|
|||
FOnActivate : TOnActivate;
|
||||
FOnReload : TOnReload;
|
||||
|
||||
procedure AddFile(FileName, APath: String);
|
||||
function GetCurrentAddress: String;
|
||||
function GetNotebookPage: TCustomPage;
|
||||
function GetCurrentFileSource: IFileSource;
|
||||
|
|
@ -108,6 +109,10 @@ type
|
|||
function GetPath(FileSourceIndex, PathIndex: Integer): UTF8String;
|
||||
function GetPathsCount(FileSourceIndex: Integer): Integer;
|
||||
function GetWatcherActive: Boolean;
|
||||
procedure RemoveFile(FileName: String);
|
||||
procedure RenameFile(NewFileName, OldFileName: String);
|
||||
procedure ResortFile(ADisplayFile: TDisplayFile);
|
||||
procedure UpdateFile(FileName: String);
|
||||
{en
|
||||
Assigns the built lists to the file view and displays new the file list.
|
||||
}
|
||||
|
|
@ -557,6 +562,102 @@ begin
|
|||
Result := nil;
|
||||
end;
|
||||
|
||||
procedure TFileView.AddFile(FileName, APath: String);
|
||||
var
|
||||
AFile: TFile;
|
||||
ADisplayFile: TDisplayFile;
|
||||
I: Integer;
|
||||
begin
|
||||
I := FHashedNames.Find(FileName);
|
||||
if I >= 0 then
|
||||
UpdateFile(FileName)
|
||||
else
|
||||
begin
|
||||
AFile := TFile.Create(APath);
|
||||
AFile.Name := FileName;
|
||||
ADisplayFile := TDisplayFile.Create(AFile);
|
||||
FHashedFiles.Add(ADisplayFile, nil);
|
||||
FHashedNames.Add(FileName, ADisplayFile);
|
||||
FileSource.RetrieveProperties(AFile, FilePropertiesNeeded);
|
||||
TFileSorter.InsertSort(ADisplayFile, FAllDisplayFiles, Sorting);
|
||||
ReDisplayFileList;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TFileView.RemoveFile(FileName: String);
|
||||
var
|
||||
ADisplayFile: TDisplayFile;
|
||||
I, J: Integer;
|
||||
begin
|
||||
I := FHashedNames.Find(FileName);
|
||||
if I >= 0 then
|
||||
begin
|
||||
ADisplayFile := TDisplayFile(FHashedNames.List[I]^.Data);
|
||||
FHashedNames.Remove(FileName);
|
||||
FHashedFiles.Remove(ADisplayFile);
|
||||
for J := 0 to FAllDisplayFiles.Count - 1 do
|
||||
if FAllDisplayFiles[J] = ADisplayFile then
|
||||
begin
|
||||
FAllDisplayFiles.Delete(J);
|
||||
Break;
|
||||
end;
|
||||
ReDisplayFileList;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TFileView.RenameFile(NewFileName, OldFileName: String);
|
||||
var
|
||||
ADisplayFile: TDisplayFile;
|
||||
I, J: Integer;
|
||||
begin
|
||||
I := FHashedNames.Find(OldFileName);
|
||||
if I >= 0 then
|
||||
begin
|
||||
ADisplayFile := TDisplayFile(FHashedNames.List[I]^.Data);
|
||||
ADisplayFile.FSFile.Name := NewFileName;
|
||||
FHashedNames.Remove(OldFileName);
|
||||
FHashedNames.Add(NewFileName, ADisplayFile);
|
||||
ADisplayFile.IconID := -1;
|
||||
ADisplayFile.IconOverlayID := -1;
|
||||
ADisplayFile.DisplayStrings.Clear;
|
||||
ResortFile(ADisplayFile);
|
||||
ReDisplayFileList;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TFileView.ResortFile(ADisplayFile: TDisplayFile);
|
||||
var
|
||||
I: Integer;
|
||||
begin
|
||||
for I := 0 to FAllDisplayFiles.Count - 1 do
|
||||
if FAllDisplayFiles[I] = ADisplayFile then
|
||||
begin
|
||||
FAllDisplayFiles[I] := nil; // Set to nil so that it isn't freed when deleting.
|
||||
FAllDisplayFiles.Delete(I);
|
||||
TFileSorter.InsertSort(ADisplayFile, FAllDisplayFiles, Sorting);
|
||||
Break;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TFileView.UpdateFile(FileName: String);
|
||||
var
|
||||
AFile: TFile;
|
||||
ADisplayFile: TDisplayFile;
|
||||
I: Integer;
|
||||
begin
|
||||
I := FHashedNames.Find(FileName);
|
||||
if I >= 0 then
|
||||
begin
|
||||
ADisplayFile := TDisplayFile(FHashedNames.List[I]^.Data);
|
||||
AFile := ADisplayFile.FSFile;
|
||||
AFile.ClearProperties;
|
||||
FileSource.RetrieveProperties(AFile, FilePropertiesNeeded);
|
||||
ADisplayFile.DisplayStrings.Clear;
|
||||
ResortFile(ADisplayFile);
|
||||
ReDisplayFileList;
|
||||
end;
|
||||
end;
|
||||
|
||||
function TFileView.GetCurrentAddress: String;
|
||||
begin
|
||||
if FileSourcesCount > 0 then
|
||||
|
|
@ -1613,7 +1714,21 @@ end;
|
|||
|
||||
procedure TFileView.WatcherEvent(const EventData: TFSWatcherEventData);
|
||||
begin
|
||||
Reload(EventData.Path);
|
||||
if IncludeTrailingPathDelimiter(EventData.Path) = CurrentPath then
|
||||
begin
|
||||
case EventData.EventType of
|
||||
fswFileCreated:
|
||||
Self.AddFile(EventData.FileName, EventData.Path);
|
||||
fswFileChanged:
|
||||
Self.UpdateFile(EventData.FileName);
|
||||
fswFileDeleted:
|
||||
Self.RemoveFile(EventData.FileName);
|
||||
fswFileRenamed:
|
||||
Self.RenameFile(EventData.FileName, EventData.OldFileName);
|
||||
else
|
||||
Reload(EventData.Path);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TFileView.GoToHistoryIndex(aFileSourceIndex, aPathIndex: Integer);
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ type
|
|||
private
|
||||
FSortList: TFiles;
|
||||
FDisplaySortList: TDisplayFiles;
|
||||
FFileToInsert: TDisplayFile;
|
||||
FFilesToInsert: TDisplayFiles;
|
||||
FSortings: TFileSortings;
|
||||
|
||||
|
|
@ -42,9 +43,10 @@ type
|
|||
}
|
||||
function Compare(FileSorting: TFileSorting; File1, File2: TFile): Integer;
|
||||
|
||||
Procedure QuickSort(FList: PPointerList; L, R : Longint);
|
||||
Procedure QuickSortDisplay(FList: PPointerList; L, R : Longint);
|
||||
procedure QuickSort(FList: PPointerList; L, R : Longint);
|
||||
procedure QuickSortDisplay(FList: PPointerList; L, R : Longint);
|
||||
procedure InsertSort(FilesToInsert, AlreadySortedFiles: TDisplayFiles);
|
||||
procedure InsertSort(FileToInsert: TDisplayFile; AlreadySortedFiles: TDisplayFiles);
|
||||
|
||||
{en
|
||||
Checks the files list for supported properties and removes
|
||||
|
|
@ -65,6 +67,8 @@ type
|
|||
constructor Create(Files: TDisplayFiles; Sortings: TFileSortings);
|
||||
constructor Create(FilesToInsert, AlreadySortedFiles: TDisplayFiles;
|
||||
Sortings: TFileSortings);
|
||||
constructor Create(FileToInsert: TDisplayFile; AlreadySortedFiles: TDisplayFiles;
|
||||
Sortings: TFileSortings);
|
||||
|
||||
procedure Sort;
|
||||
|
||||
|
|
@ -75,6 +79,8 @@ type
|
|||
class procedure Sort(FilesToSort: TDisplayFiles; const ASortings: TFileSortings);
|
||||
class procedure InsertSort(FilesToInsert, AlreadySortedFiles: TDisplayFiles;
|
||||
const ASortings: TFileSortings);
|
||||
class procedure InsertSort(FileToInsert: TDisplayFile; AlreadySortedFiles: TDisplayFiles;
|
||||
const ASortings: TFileSortings);
|
||||
end;
|
||||
|
||||
{en
|
||||
|
|
@ -441,6 +447,22 @@ begin
|
|||
inherited Create;
|
||||
end;
|
||||
|
||||
constructor TFileSorter.Create(FileToInsert: TDisplayFile; AlreadySortedFiles: TDisplayFiles; Sortings: TFileSortings);
|
||||
begin
|
||||
FFileToInsert := FileToInsert;
|
||||
FDisplaySortList := AlreadySortedFiles;
|
||||
FSortings := Sortings;
|
||||
|
||||
if Assigned(FDisplaySortList) and (FDisplaySortList.Count > 0) and
|
||||
Assigned(FFileToInsert) then
|
||||
begin
|
||||
CheckSupportedProperties(FDisplaySortList[0].FSFile.SupportedProperties);
|
||||
CheckSupportedProperties(FFileToInsert.FSFile.SupportedProperties);
|
||||
end;
|
||||
|
||||
inherited Create;
|
||||
end;
|
||||
|
||||
procedure TFileSorter.CheckSupportedProperties(SupportedFileProperties: TFilePropertiesTypes);
|
||||
var
|
||||
SortingIndex: Integer;
|
||||
|
|
@ -483,7 +505,14 @@ begin
|
|||
|
||||
if Length(FSortings) > 0 then
|
||||
begin
|
||||
if Assigned(FFilesToInsert) and Assigned(FDisplaySortList) then
|
||||
if Assigned(FFileToInsert) and Assigned(FDisplaySortList) then
|
||||
begin
|
||||
InsertSort(FFileToInsert, FDisplaySortList);
|
||||
{$IFDEF fileSortingTime}
|
||||
DCDebug('FileSorter: Insert sort time: ', IntToStr(DateTimeToTimeStamp(Now - fileSortingTimer).Time));
|
||||
{$ENDIF}
|
||||
end
|
||||
else if Assigned(FFilesToInsert) and Assigned(FDisplaySortList) then
|
||||
begin
|
||||
InsertSort(FFilesToInsert, FDisplaySortList);
|
||||
{$IFDEF fileSortingTime}
|
||||
|
|
@ -543,6 +572,18 @@ begin
|
|||
end;
|
||||
end;
|
||||
|
||||
class procedure TFileSorter.InsertSort(FileToInsert: TDisplayFile; AlreadySortedFiles: TDisplayFiles; const ASortings: TFileSortings);
|
||||
var
|
||||
FileListSorter: TFileSorter;
|
||||
begin
|
||||
FileListSorter := TFileSorter.Create(FileToInsert, AlreadySortedFiles, CloneAndAddNameSortingIfNeeded(ASortings));
|
||||
try
|
||||
FileListSorter.Sort;
|
||||
finally
|
||||
FreeAndNil(FileListSorter);
|
||||
end;
|
||||
end;
|
||||
|
||||
{ Return Values for ICompareByxxxx function
|
||||
|
||||
> 0 (positive) Item1 is greater than Item2
|
||||
|
|
@ -690,7 +731,7 @@ begin
|
|||
end;
|
||||
|
||||
// From FPC: lists.inc.
|
||||
Procedure TFileSorter.QuickSort(FList: PPointerList; L, R : Longint);
|
||||
procedure TFileSorter.QuickSort(FList: PPointerList; L, R : Longint);
|
||||
var
|
||||
I, J : Longint;
|
||||
P, Q : Pointer;
|
||||
|
|
@ -752,6 +793,7 @@ procedure TFileSorter.InsertSort(FilesToInsert, AlreadySortedFiles: TDisplayFile
|
|||
var
|
||||
i, j, SortedIndex: PtrInt;
|
||||
Psrc, Pdst: PPointerList;
|
||||
Pcur: Pointer;
|
||||
Cnt: Integer;
|
||||
begin
|
||||
if FFilesToInsert.Count > 0 then
|
||||
|
|
@ -767,12 +809,13 @@ begin
|
|||
SortedIndex := 0;
|
||||
for i := 0 to FilesToInsert.Count - 1 do
|
||||
begin
|
||||
Pcur := Psrc^[i];
|
||||
// This pointer might change when adding items due to reallocating memory,
|
||||
// so read it on every turn.
|
||||
Pdst := AlreadySortedFiles.List.List;
|
||||
|
||||
while (SortedIndex < Cnt) and
|
||||
(MultiCompareDisplay(Psrc^[i], Pdst^[SortedIndex]) >= 0) do
|
||||
(MultiCompareDisplay(Pcur, Pdst^[SortedIndex]) >= 0) do
|
||||
Inc(SortedIndex);
|
||||
|
||||
if SortedIndex >= Cnt then
|
||||
|
|
@ -784,7 +827,7 @@ begin
|
|||
end
|
||||
else
|
||||
begin
|
||||
AlreadySortedFiles.List.Insert(SortedIndex, Psrc^[i]);
|
||||
AlreadySortedFiles.List.Insert(SortedIndex, Pcur);
|
||||
Inc(SortedIndex);
|
||||
Inc(Cnt);
|
||||
end;
|
||||
|
|
@ -792,5 +835,22 @@ begin
|
|||
end;
|
||||
end;
|
||||
|
||||
procedure TFileSorter.InsertSort(FileToInsert: TDisplayFile; AlreadySortedFiles: TDisplayFiles);
|
||||
var
|
||||
i, j, SortedIndex: PtrInt;
|
||||
Pdst: PPointerList;
|
||||
Cnt: Integer;
|
||||
begin
|
||||
SortedIndex := 0;
|
||||
Cnt := AlreadySortedFiles.List.Count;
|
||||
Pdst := AlreadySortedFiles.List.List;
|
||||
|
||||
while (SortedIndex < Cnt) and
|
||||
(MultiCompareDisplay(FileToInsert, Pdst^[SortedIndex]) >= 0) do
|
||||
Inc(SortedIndex);
|
||||
|
||||
AlreadySortedFiles.List.Insert(SortedIndex, FileToInsert);
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue