From 30a547b8f4f9f01b8270d653c7ac3784a8ce981c Mon Sep 17 00:00:00 2001 From: Tomas Bzatek Date: Wed, 11 Jun 2008 21:01:51 +0200 Subject: Allow optional sorting directories like files --- UCoreUtils.pas | 46 ++++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 22 deletions(-) (limited to 'UCoreUtils.pas') diff --git a/UCoreUtils.pas b/UCoreUtils.pas index 6ee28d4..3dc91f0 100644 --- a/UCoreUtils.pas +++ b/UCoreUtils.pas @@ -58,6 +58,7 @@ function GetSignalString(SignalNo: integer): string; function FormatSize(Value: Int64; Base: integer; OverrideSizeFormat: integer = -1): string; function FormatDate(Value: TTimeT; const FormatTime, FormatDate: boolean; OverrideTimeFormat: integer = -1; OverrideDateFormat: integer = -1; OverrideDateTimeFormat: integer = -1; OverrideCustomDateFormat: string = ''; OverrideCustomTimeFormat: string = ''): string; +function StripDate(Value: TTimeT): TTimeT; function AttrToStr(const Mode: Cardinal; IncludeFileType: boolean = True): string; function AttrToOctal(const Mode: Cardinal): integer; @@ -347,6 +348,13 @@ begin if FormatDate then Result := DateString; end; +function StripDate(Value: TTimeT): TTimeT; +var time_tm: Ptm; +begin + time_tm := localtime(@Value); + Result := time_tm^.tm_hour*60*60 + time_tm^.tm_min*60 + time_tm^.tm_sec; +end; + (********************************************************************************************************************************) function AttrToStr(const Mode: Cardinal; IncludeFileType: boolean = True): string; @@ -1378,42 +1386,36 @@ begin if Data2^.UpDir then Result := 1*mp else if Data1^.IsDir and (not Data2^.IsDir) then Result := -1*mp else if Data2^.IsDir and (not Data1^.IsDir) then Result := 1*mp else + if Data1^.IsDir and Data2^.IsDir and (not ConfSortDirectoriesLikeFiles) + then Result := CompareTextsEx(Data1^.FDisplayName, Data2^.FDisplayName)*mp else + case SortColumnID of - 1, 2 : begin - Result := CompareTextsEx(Data1^.FDisplayName, Data2^.FDisplayName); - if Data1^.IsDir and Data2^.IsDir then Result := Result * mp; - end; - 3 : if Data1^.IsDir and Data2^.IsDir then Result := CompareTextsEx(Data1^.FDisplayName, Data2^.FDisplayName)*mp else begin + 1, 2 : Result := CompareTextsEx(Data1^.FDisplayName, Data2^.FDisplayName); + 3 : begin SeparateExt(String(Data1^.FDisplayName), s1, s2); SeparateExt(String(Data2^.FDisplayName), s3, s4); if WideUpperCase(s2) <> WideUpperCase(s4) then Result := CompareTextsEx(PChar(s2), PChar(s4)) else Result := CompareTextsEx(PChar(s1), PChar(s3)); end; - 4 : if Data1^.IsDir and Data2^.IsDir then Result := CompareTextsEx(Data1^.FDisplayName, Data2^.FDisplayName)*mp else - if Data1^.Size > Data2^.Size then Result := -1 else + 4 : if Data1^.Size > Data2^.Size then Result := -1 else if Data1^.Size < Data2^.Size then Result := 1 else Result := CompareTextsEx(Data1^.FDisplayName, Data2^.FDisplayName); - 5, 6 : if Data1^.IsDir and Data2^.IsDir then Result := CompareTextsEx(Data1^.FDisplayName, Data2^.FDisplayName)*mp else - if Data1^.ModifyTime > Data2^.ModifyTime then Result := -1 else - if Data1^.ModifyTime < Data2^.ModifyTime then Result := 1 else + 5, 6 : if Data1^.ModifyTime > Data2^.ModifyTime then Result := -1 else + if Data1^.ModifyTime < Data2^.ModifyTime then Result := 1 else + Result := CompareTextsEx(Data1^.FDisplayName, Data2^.FDisplayName); + 7 : if StripDate(Data1^.ModifyTime) > StripDate(Data2^.ModifyTime) then Result := -1 else + if StripDate(Data1^.ModifyTime) < StripDate(Data2^.ModifyTime) then Result := 1 else Result := CompareTextsEx(Data1^.FDisplayName, Data2^.FDisplayName); - 7 : if Data1^.IsDir and Data2^.IsDir then Result := CompareTextsEx(Data1^.FDisplayName, Data2^.FDisplayName)*mp else - if Frac(Data1^.ModifyTime) > Frac(Data2^.ModifyTime) then Result := -1 else - if Frac(Data1^.ModifyTime) < Frac(Data2^.ModifyTime) then Result := 1 else - Result := CompareTextsEx(Data1^.FDisplayName, Data2^.FDisplayName); - 8 : if Data1^.IsDir and Data2^.IsDir then Result := CompareTextsEx(Data1^.FDisplayName, Data2^.FDisplayName)*mp else - if Data1^.UID > Data2^.UID then Result := -1 else + 8 : if Data1^.UID > Data2^.UID then Result := -1 else if Data1^.UID < Data2^.UID then Result := 1 else Result := CompareTextsEx(Data1^.FDisplayName, Data2^.FDisplayName); - 9 : if Data1^.IsDir and Data2^.IsDir then Result := CompareTextsEx(Data1^.FDisplayName, Data2^.FDisplayName)*mp else - if Data1^.GID > Data2^.GID then Result := -1 else + 9 : if Data1^.GID > Data2^.GID then Result := -1 else if Data1^.GID < Data2^.GID then Result := 1 else Result := CompareTextsEx(Data1^.FDisplayName, Data2^.FDisplayName); - 10 : if Data1^.IsDir and Data2^.IsDir then Result := CompareTextsEx(Data1^.FDisplayName, Data2^.FDisplayName)*mp else - if Data1^.Mode > Data2^.Mode then Result := -1 else - if Data1^.Mode < Data2^.Mode then Result := 1 else - Result := CompareTextsEx(Data1^.FDisplayName, Data2^.FDisplayName); + 10 : if Data1^.Mode > Data2^.Mode then Result := -1 else + if Data1^.Mode < Data2^.Mode then Result := 1 else + Result := CompareTextsEx(Data1^.FDisplayName, Data2^.FDisplayName); else Result := 0; end; end; -- cgit v1.2.3