UPD: remove circle references between uDarwinFinderModel and uDarwinFile

This commit is contained in:
rich2014 2026-01-03 10:18:52 +08:00
commit cff28911e5
4 changed files with 114 additions and 90 deletions

View file

@ -332,7 +332,7 @@ end;"/>
<PackageName Value="Image32"/>
</Item13>
</RequiredPackages>
<Units Count="299">
<Units Count="300">
<Unit0>
<Filename Value="doublecmd.lpr"/>
<IsPartOfProject Value="True"/>
@ -2159,6 +2159,11 @@ end;"/>
<IsPartOfProject Value="True"/>
<UnitName Value="uDarwinClipboard"/>
</Unit298>
<Unit299>
<Filename Value="platform\unix\darwin\udarwinfileproperty.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="uDarwinFileProperty"/>
</Unit299>
</Units>
</ProjectOptions>
<CompilerOptions>

View file

@ -148,7 +148,7 @@ uses
{$IFDEF UNIX}
BaseUnix, uUsersGroups, LazUTF8, DCUnix, uMyUnix,
{$IFDEF DARWIN}
uDarwinFile,
uDarwinFile, uDarwinFileProperty,
{$ENDIF}
{$IFDEF LINUX}
statx,
@ -431,7 +431,7 @@ begin
end;
{$IFDEF DARWIN}
if pSearchRecord^.Name<>'..' then
MacOSSpecificProperty := TDarwinFileUtil.getSpecificProperty(AFilePath);
MacOSSpecificProperty := TDarwinFilePropertyUtil.getSpecificProperty(AFilePath);
{$ENDIF}
end;
@ -489,7 +489,7 @@ begin
{$ENDIF}
{$IFDEF DARWIN}
Result.MacOSSpecificProperty := TDarwinFileUtil.getSpecificProperty(AFilePath);
Result.MacOSSpecificProperty := TDarwinFilePropertyUtil.getSpecificProperty(AFilePath);
{$ENDIF}
// Set name after assigning Attributes property, because it is used to get extension.
@ -764,7 +764,7 @@ begin
{$IFDEF DARWIN}
if (AFile.Name<>'..') and (fpMacOSSpecific in PropertiesToSet) then
MacOSSpecificProperty := TDarwinFileUtil.getSpecificProperty(sFullPath);
MacOSSpecificProperty := TDarwinFilePropertyUtil.getSpecificProperty(sFullPath);
{$ENDIF}
PropertiesToSet:= PropertiesToSet * fpVariantAll;

View file

@ -9,7 +9,6 @@ interface
uses
Classes, SysUtils,
uDebug, uLog,
uFileProperty,
MacOSAll, CocoaAll, Cocoa_Extra, CocoaUtils,
uDarwinUtil;
@ -32,7 +31,6 @@ type
class function unmountAndEject( const path: String ): Boolean;
class function resolveAlias( const path: String ): String;
public
class function getSpecificProperty( const path: String ): TFileMacOSSpecificProperty;
class function getDisplayName( const path: String ): String;
class function getUniqueIcon( const path: String ): NSImage;
class function getDescription( const path: String ): String;
@ -47,9 +45,6 @@ type
implementation
uses
uDarwinFinderModel;
const
ICON_SPECIAL_FOLDER_EXT_STRING = '.app;.musiclibrary;.imovielibrary;.tvlibrary;.photoslibrary;.theater;.saver;.xcode;.xcodeproj;.xcworkspace;.playground;.scptd;.action;.workflow;.prefpane;.appex;.kext;.xpc;.bundle;.qlgenerator;.mdimporter;.systemextension;.fcpbundle;.fcpxmld;';
ICON_SPECIAL_PARENT_FOLDER_STRING = '/;/System;/Applications;/Volumes;/Users;~;~/Music;~/Pictures;~/Movies;';
@ -119,86 +114,6 @@ begin
Result:= TUnmountManager.unmount( path, True );
end;
class function TDarwinFileUtil.getSpecificProperty(const path: String
): TFileMacOSSpecificProperty;
var
url: NSURL;
function toPrimaryColors(const tagNames: NSArray): TFileFinderTagPrimaryColors;
var
visualTagNames: NSMutableArray;
tagName: NSString;
tag: TFinderTag;
iSource: NSUInteger;
iDest: Integer;
colorIndex: Integer;
begin
visualTagNames:= NSMutableArray.new;
for iSource:= 0 to tagNames.count-1 do begin
tagName:= NSString( tagNames.objectAtIndex(iSource) );
tag:= TFinderTags.getTagOfName( tagName );
if tag.colorIndex <= 0 then
continue;
visualTagNames.addObject( tagName );
end;
iSource:= 0;
if visualTagNames.count > 3 then
iSource:= visualTagNames.count - 3;
for iDest:=0 to 2 do begin
colorIndex:= -1;
if iSource < visualTagNames.count then begin
tagName:= NSString( visualTagNames.objectAtIndex(iSource) );
tag:= TFinderTags.getTagOfName( tagName );
colorIndex:= tag.colorIndex;
end;
Result.indexes[iDest]:= colorIndex;
inc( iSource );
end;
visualTagNames.release;
end;
function getTagPrimaryColors: TFileFinderTagPrimaryColors;
var
tagNames: NSArray;
begin
Result.intValue:= -1;
tagNames:= TDarwinFinderModelUtil.getTagNamesOfFile( url );
if tagNames = nil then
Exit;
Result:= toPrimaryColors( tagNames );
end;
function isSeedFile: Boolean;
var
name: NSString;
status: NSString;
error: NSError = nil;
ok: Boolean;
begin
name:= url.lastPathComponent;
if name.isEqualToString(NSSTR('..')) then
Exit( False );
if name.hasPrefix(NSSTR('.')) and name.hasSuffix(NSSTR('.icloud')) then
Exit( True );
ok:= url.getResourceValue_forKey_error( @status, NSURLUbiquitousItemDownloadingStatusKey, @error );
if NOT ok then
logDarwinError( 'TDarwinFileUtil.getSpecificProperty.isSeedFile()', error );
if status = nil then
Exit( False );
Result:= NOT status.isEqualToString( NSURLUbiquitousItemDownloadingStatusCurrent );
end;
begin
Result:= TFileMacOSSpecificProperty.Create;
url:= NSURL.fileURLWithPath( StringToNSString(path) );
Result.FinderTagPrimaryColors:= getTagPrimaryColors;
Result.IsiCloudSeedFile:= isSeedFile;
end;
class function TDarwinFileUtil.getDisplayName(const path: String): String;
var
cocoaPath: NSString;

View file

@ -0,0 +1,104 @@
unit uDarwinFileProperty;
{$mode delphi}
{$modeswitch objectivec2}
interface
uses
Classes, SysUtils,
CocoaAll,
uFileProperty, uDarwinFinderModel, uDarwinUtil;
type
{ TDarwinFilePropertyUtil }
TDarwinFilePropertyUtil = class
class function getSpecificProperty( const path: String ): TFileMacOSSpecificProperty;
end;
implementation
class function TDarwinFilePropertyUtil.getSpecificProperty(const path: String
): TFileMacOSSpecificProperty;
var
url: NSURL;
function toPrimaryColors(const tagNames: NSArray): TFileFinderTagPrimaryColors;
var
visualTagNames: NSMutableArray;
tagName: NSString;
tag: TFinderTag;
iSource: NSUInteger;
iDest: Integer;
colorIndex: Integer;
begin
visualTagNames:= NSMutableArray.new;
for iSource:= 0 to tagNames.count-1 do begin
tagName:= NSString( tagNames.objectAtIndex(iSource) );
tag:= TFinderTags.getTagOfName( tagName );
if tag.colorIndex <= 0 then
continue;
visualTagNames.addObject( tagName );
end;
iSource:= 0;
if visualTagNames.count > 3 then
iSource:= visualTagNames.count - 3;
for iDest:=0 to 2 do begin
colorIndex:= -1;
if iSource < visualTagNames.count then begin
tagName:= NSString( visualTagNames.objectAtIndex(iSource) );
tag:= TFinderTags.getTagOfName( tagName );
colorIndex:= tag.colorIndex;
end;
Result.indexes[iDest]:= colorIndex;
inc( iSource );
end;
visualTagNames.release;
end;
function getTagPrimaryColors: TFileFinderTagPrimaryColors;
var
tagNames: NSArray;
begin
Result.intValue:= -1;
tagNames:= TDarwinFinderModelUtil.getTagNamesOfFile( url );
if tagNames = nil then
Exit;
Result:= toPrimaryColors( tagNames );
end;
function isSeedFile: Boolean;
var
name: NSString;
status: NSString;
error: NSError = nil;
ok: Boolean;
begin
name:= url.lastPathComponent;
if name.isEqualToString(NSSTR('..')) then
Exit( False );
if name.hasPrefix(NSSTR('.')) and name.hasSuffix(NSSTR('.icloud')) then
Exit( True );
ok:= url.getResourceValue_forKey_error( @status, NSURLUbiquitousItemDownloadingStatusKey, @error );
if NOT ok then
logDarwinError( 'TDarwinFileUtil.getSpecificProperty.isSeedFile()', error );
if status = nil then
Exit( False );
Result:= NOT status.isEqualToString( NSURLUbiquitousItemDownloadingStatusCurrent );
end;
begin
Result:= TFileMacOSSpecificProperty.Create;
url:= NSURL.fileURLWithPath( StringToNSString(path) );
Result.FinderTagPrimaryColors:= getTagPrimaryColors;
Result.IsiCloudSeedFile:= isSeedFile;
end;
end.