Skip to content

Commit c28ce65

Browse files
committed
ADD: getMacOSFileUniqueIcon() on macOS
1 parent 2bdc88e commit c28ce65

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/platform/unix/darwin/umydarwin.pas

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ procedure openNewInstance();
7272

7373
function getMacOSDisplayNameFromPath(const path: String): String;
7474

75+
function getMacOSFileUniqueIcon(const path: String ): NSImage;
76+
7577
// Workarounds for FPC RTL Bug
7678
// copied from ptypes.inc and modified fstypename only
7779
{$if defined(cpuarm) or defined(cpuaarch64) or defined(iphonesim)}
@@ -935,6 +937,25 @@ function getMacOSDisplayNameFromPath(const path: String): String;
935937
Result:= displayName.UTF8String;
936938
end;
937939

940+
function hasUniqueIcon( const path: String ): Boolean;
941+
var
942+
pathRef: FSRef;
943+
catalogInfo: FSCatalogInfo;
944+
pFinderInfo: FileInfoPtr;
945+
begin
946+
FSPathMakeRef( pchar(path), pathRef, nil );
947+
FSGetCatalogInfo( pathRef, kFSCatInfoFinderInfo, @catalogInfo, nil, nil, nil );
948+
pFinderInfo:= FileInfoPtr( @catalogInfo.finderInfo );
949+
Result:= (pFinderInfo^.finderFlags and kHasCustomIcon) <> 0;
950+
end;
951+
952+
function getMacOSFileUniqueIcon( const path: String ): NSImage;
953+
begin
954+
Result:= nil;
955+
if hasUniqueIcon(path) then
956+
Result:= NSWorkspace.sharedWorkspace.iconForFile( StringToNSString(path) );
957+
end;
958+
938959
initialization
939960
Initialize;
940961

0 commit comments

Comments
 (0)