mirror of
https://github.com/doublecmd/doublecmd.git
synced 2026-06-21 09:58:13 +00:00
ADD: support NSImage cache in TDarwinImageCacheManager on macOS
This commit is contained in:
parent
68304a6949
commit
2596a2582d
5 changed files with 67 additions and 11 deletions
|
|
@ -146,7 +146,7 @@ var
|
|||
iconPath: String;
|
||||
begin
|
||||
iconPath:= mbExpandFileName( ICON_PATH );
|
||||
Result:= darwinImageCacheForPath.copyImageForFileContent( iconPath, iconSize, True );
|
||||
Result:= darwinImageCacheForPath.copyBitmapForFileContent( iconPath, iconSize, True );
|
||||
end;
|
||||
{$ELSE}
|
||||
begin
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ begin
|
|||
|
||||
{$IFDEF DARWIN}
|
||||
if path = PathDelim then
|
||||
Result:= darwinImageCacheForExt.copyIconForFileExt( FCurrentAddress, iconSize );
|
||||
Result:= darwinImageCacheForExt.copyBitmapForFileExt( FCurrentAddress, iconSize );
|
||||
{$ENDIF}
|
||||
end;
|
||||
|
||||
|
|
|
|||
|
|
@ -152,7 +152,7 @@ function TSmartFolderSearchResultFileSource.GetCustomIcon(
|
|||
const path: String;
|
||||
const iconSize: Integer ): TBitmap;
|
||||
begin
|
||||
Result:= darwinImageCacheForExt.copyIconForFileExt( 'savedSearch', iconSize );
|
||||
Result:= darwinImageCacheForExt.copyBitmapForFileExt( 'savedSearch', iconSize );
|
||||
end;
|
||||
|
||||
{ TDarwinSearchResultHandler }
|
||||
|
|
|
|||
|
|
@ -53,18 +53,23 @@ type
|
|||
|
||||
procedure onThemeChanged;
|
||||
|
||||
function copyIconForFileExt(
|
||||
function copyBitmapForFileExt(
|
||||
const path: String;
|
||||
const size: Integer ): TBitmap;
|
||||
|
||||
function copyImageForFileContent(
|
||||
function copyBitmapForFileContent(
|
||||
const path: String;
|
||||
const size: Integer;
|
||||
const autoDark: Boolean = False ): TBitmap;
|
||||
|
||||
function copyImageForNSImage(
|
||||
function copyBitmapForNSImage(
|
||||
const key: String;
|
||||
const image: NSImage ): TBitmap;
|
||||
|
||||
function getNSImageForFileContent(
|
||||
const path: String;
|
||||
const size: Integer;
|
||||
const autoDark: Boolean = False ): NSImage;
|
||||
end;
|
||||
|
||||
var
|
||||
|
|
@ -73,6 +78,31 @@ var
|
|||
|
||||
implementation
|
||||
|
||||
type
|
||||
|
||||
{ TNSImageCacheItem }
|
||||
|
||||
TNSImageCacheItem = class
|
||||
private
|
||||
_image: NSImage;
|
||||
public
|
||||
constructor Create( const image: NSImage );
|
||||
destructor Destroy; override;
|
||||
end;
|
||||
|
||||
{ TNSImageCacheItem }
|
||||
|
||||
constructor TNSImageCacheItem.Create( const image: NSImage );
|
||||
begin
|
||||
_image:= image;
|
||||
_image.retain;
|
||||
end;
|
||||
|
||||
destructor TNSImageCacheItem.Destroy;
|
||||
begin
|
||||
_image.release;
|
||||
end;
|
||||
|
||||
class function TDarwinImageUtil.filt(
|
||||
const filterName: NSString;
|
||||
const sourceImage: NSImage ): NSImage;
|
||||
|
|
@ -242,7 +272,7 @@ begin
|
|||
end;
|
||||
end;
|
||||
|
||||
function TDarwinImageCacheManager.copyIconForFileExt(
|
||||
function TDarwinImageCacheManager.copyBitmapForFileExt(
|
||||
const path: String;
|
||||
const size: Integer ): TBitmap;
|
||||
var
|
||||
|
|
@ -274,7 +304,7 @@ begin
|
|||
end;
|
||||
end;
|
||||
|
||||
function TDarwinImageCacheManager.copyImageForFileContent(
|
||||
function TDarwinImageCacheManager.copyBitmapForFileContent(
|
||||
const path: String;
|
||||
const size: Integer;
|
||||
const autoDark: Boolean = False ): TBitmap;
|
||||
|
|
@ -302,7 +332,7 @@ begin
|
|||
end;
|
||||
end;
|
||||
|
||||
function TDarwinImageCacheManager.copyImageForNSImage(
|
||||
function TDarwinImageCacheManager.copyBitmapForNSImage(
|
||||
const key: String;
|
||||
const image: NSImage ): TBitmap;
|
||||
var
|
||||
|
|
@ -327,6 +357,32 @@ begin
|
|||
end;
|
||||
end;
|
||||
|
||||
function TDarwinImageCacheManager.getNSImageForFileContent(
|
||||
const path: String;
|
||||
const size: Integer;
|
||||
const autoDark: Boolean = False ): NSImage;
|
||||
var
|
||||
item: TNSImageCacheItem;
|
||||
image: NSImage;
|
||||
begin
|
||||
Result:= nil;
|
||||
|
||||
_lockObject.Acquire;
|
||||
try
|
||||
item:= TNSImageCacheItem(_images[path]);
|
||||
if _images[path] = nil then begin
|
||||
image:= TDarwinImageUtil.getBestFromFileContentWithSize( path, size, autoDark );
|
||||
item:= TNSImageCacheItem.Create( image );
|
||||
_images[path]:= item;
|
||||
end;
|
||||
finally
|
||||
_lockObject.Release;
|
||||
end;
|
||||
|
||||
if Assigned( item ) then
|
||||
Result:= item._image;
|
||||
end;
|
||||
|
||||
initialization
|
||||
darwinImageCacheForPath:= TDarwinImageCacheManager.Create;
|
||||
TCocoaThemeServices.addObserver( darwinImageCacheForPath );
|
||||
|
|
|
|||
|
|
@ -719,12 +719,12 @@ begin
|
|||
Result:= nil;
|
||||
if path = GetRootDir(path) then begin
|
||||
TiCloudDriveFileSource.GetMainIcon( iconPath );
|
||||
Result:= darwinImageCacheForPath.copyImageForFileContent( iconPath, iconSize );
|
||||
Result:= darwinImageCacheForPath.copyBitmapForFileContent( iconPath, iconSize );
|
||||
end else begin
|
||||
realPath:= self.GetRealPath( path );
|
||||
image:= getAppIconByPath( realPath );
|
||||
if image <> nil then
|
||||
Result:= darwinImageCacheForPath.copyImageForNSImage( realPath, image );
|
||||
Result:= darwinImageCacheForPath.copyBitmapForNSImage( realPath, image );
|
||||
end;
|
||||
end;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue