UPD: refactoring Application related from uMyDarwin to uDarwinApplication again

(cherry picked from commit ec2bf46f7f)
This commit is contained in:
rich2014 2025-12-10 21:20:52 +08:00 committed by Alexander Koblov
commit 2979f4c02e
5 changed files with 70 additions and 73 deletions

View file

@ -163,7 +163,7 @@ begin
{$ENDIF}
{$IF DEFINED(darwin)}
FixMacFormatSettings;
TDarwinApplicationUtil.fixFormatSettings;
TDarwinApplicationUtil.setTheme( gAppMode );
{$ENDIF}

View file

@ -7372,7 +7372,7 @@ end;
procedure TfrmMain.OpenNewWindow(Sender: TObject);
begin
uMyDarwin.openNewInstance;
TDarwinApplicationUtil.openNewInstance;
end;
{$ENDIF}

View file

@ -10,7 +10,8 @@ uses
LCLType, Forms, Menus,
fMain, uDCUtils, uLng,
uFileView, uBriefFileView, uColumnsFileView, uThumbFileView,
uMyDarwin, uDarwinUtil, uDarwinFileUtil, uDarwinFinder, uDarwinFinderModel, uDarwinFileView,
uMyDarwin, uDarwinUtil, uDarwinApplication, uDarwinFileUtil,
uDarwinFinder, uDarwinFinderModel, uDarwinFileView,
CocoaAll, CocoaConfig, CocoaToolBar, Cocoa_Extra;
procedure initCocoaModernFormConfig;
@ -83,12 +84,12 @@ end;
procedure finderRevealAction( const Sender: id );
begin
performMacOSService( 'Finder/Reveal' );
TDarwinApplicationUtil.performService( 'Finder/Reveal' );
end;
procedure finderInfoAction( const Sender: id );
begin
performMacOSService( 'Finder/Show Info' );
TDarwinApplicationUtil.performService( 'Finder/Show Info' );
end;
procedure compareAction( const Sender: id );
@ -399,7 +400,7 @@ end;
procedure privilegeAction( const Sender: id );
begin
openSystemSecurityPreferences_PrivacyAllFiles;
TDarwinApplicationUtil.openSystemSecurityPreferences_PrivacyAllFiles;
end;
const

View file

@ -7,7 +7,7 @@ interface
uses
Classes, SysUtils, fgl,
CocoaAll, CocoaInt, Cocoa_Extra, CocoaUtils, CocoaConst,
MacOSAll, CocoaAll, CocoaInt, Cocoa_Extra, CocoaUtils, CocoaConst,
uDarwinUtil;
type
@ -53,14 +53,18 @@ type
class procedure themeNotify;
public
class procedure initServiceProvider(
serveCallback: TDarwinServiceProviderCallBack;
isReadyFunc: TDarwinServiceMenuIsReadyFunc;
getFilenamesFunc: TDarwinServiceMenuGetFilenamesFunc );
const serveCallback: TDarwinServiceProviderCallBack;
const isReadyFunc: TDarwinServiceMenuIsReadyFunc;
const getFilenamesFunc: TDarwinServiceMenuGetFilenamesFunc );
class procedure performService( const serviceName: String );
class procedure openSystemSecurityPreferences_PrivacyAllFiles;
public
class procedure addThemeObserver( const observer: TDarwinThemeObserver );
class procedure setTheme( const mode: Integer );
class function isDarkTheme: Boolean;
public
class procedure fixFormatSettings;
class procedure openNewInstance;
end;
implementation
@ -179,10 +183,36 @@ begin
Result:= appearanceName.isEqualToString(NSSTR_DARK_NAME) or appearanceName.isEqualToString(NSSTR_DARK_NAME_VIBRANT);
end;
class procedure TDarwinApplicationUtil.fixFormatSettings;
var
S: String;
ALocale: CFLocaleRef;
begin
ALocale:= CFLocaleCopyCurrent;
if Assigned(ALocale) then
begin
S:= CFStringToStr(CFLocaleGetValue(ALocale, kCFLocaleGroupingSeparator));
if Length(S) = 0 then
begin
DefaultFormatSettings.ThousandSeparator:= #0;
end;
CFRelease(ALocale);
end;
end;
class procedure TDarwinApplicationUtil.openNewInstance;
begin
NSWorkspace.sharedWorkspace.launchApplicationAtURL_options_configuration_error(
NSBundle.mainBundle.bundleURL,
NSWorkspaceLaunchNewInstance,
nil,
nil);
end;
class procedure TDarwinApplicationUtil.initServiceProvider(
serveCallback: TDarwinServiceProviderCallBack;
isReadyFunc: TDarwinServiceMenuIsReadyFunc;
getFilenamesFunc: TDarwinServiceMenuGetFilenamesFunc );
const serveCallback: TDarwinServiceProviderCallBack;
const isReadyFunc: TDarwinServiceMenuIsReadyFunc;
const getFilenamesFunc: TDarwinServiceMenuGetFilenamesFunc);
var
DCApp: TDCCocoaApplication Absolute NSApp;
sendTypes: NSArray;
@ -205,6 +235,29 @@ begin
DCApp.registerServicesMenuSendTypes_returnTypes( sendTypes, returnTypes );
end;
class procedure TDarwinApplicationUtil.performService(const serviceName: String
);
var
pboard: NSPasteboard;
ok: Boolean;
begin
pboard:= NSPasteboard.pasteboardWithUniqueName;
ok:= TDCCocoaApplication(NSApp).writeSelectionToPasteboard_types(
pboard , nil );
if ok then
NSPerformService( NSSTR(serviceName), pboard );
end;
class procedure TDarwinApplicationUtil.openSystemSecurityPreferences_PrivacyAllFiles;
const
Privacy_AllFiles = 'x-apple.systempreferences:com.apple.preference.security?Privacy_AllFiles';
var
url: NSURL;
begin
url:= NSURL.URLWithString( NSSTR(Privacy_AllFiles) );
NSWorkspace.sharedWorkspace.openURL( url );
end;
initialization
TDarwinApplicationUtil.init;

View file

@ -46,12 +46,6 @@ const
procedure onMainMenuCreate( menu: NSMenu );
procedure FixMacFormatSettings;
procedure openSystemSecurityPreferences_PrivacyAllFiles;
procedure openNewInstance();
// Workarounds for FPC RTL Bug
// copied from ptypes.inc and modified fstypename only
{$if defined(cpuarm) or defined(cpuaarch64) or defined(iphonesim)}
@ -103,8 +97,6 @@ type
procedure PopUp( const menu: TPopupMenu; const caption: String; const paths: TStringArray );
end;
procedure performMacOSService( serviceName: String );
procedure showQuickLookPanel;
procedure showEditFinderTagsPanel( const Sender: id; const control: TWinControl );
@ -197,7 +189,7 @@ end;
procedure TMacosServiceMenuHelper.privilegeAction(Sender: TObject);
begin
openSystemSecurityPreferences_PrivacyAllFiles;
TDarwinApplicationUtil.openSystemSecurityPreferences_PrivacyAllFiles;
end;
procedure TMacosServiceMenuHelper.PopUp( const menu: TPopupMenu;
@ -305,55 +297,6 @@ begin
service.performWithItems( cocoaArray );
end;
procedure performMacOSService( serviceName: String );
var
pboard: NSPasteboard;
ok: Boolean;
begin
pboard:= NSPasteboard.pasteboardWithUniqueName;
ok:= TDCCocoaApplication(NSApp).writeSelectionToPasteboard_types(
pboard , nil );
if ok then
NSPerformService( NSSTR(serviceName), pboard );
end;
procedure FixMacFormatSettings;
var
S: String;
ALocale: CFLocaleRef;
begin
ALocale:= CFLocaleCopyCurrent;
if Assigned(ALocale) then
begin
S:= CFStringToStr(CFLocaleGetValue(ALocale, kCFLocaleGroupingSeparator));
if Length(S) = 0 then
begin
DefaultFormatSettings.ThousandSeparator:= #0;
end;
CFRelease(ALocale);
end;
end;
procedure openSystemSecurityPreferences_PrivacyAllFiles;
const
Privacy_AllFiles = 'x-apple.systempreferences:com.apple.preference.security?Privacy_AllFiles';
var
url: NSURL;
begin
url:= NSURL.URLWithString( NSSTR(Privacy_AllFiles) );
NSWorkspace.sharedWorkspace.openURL( url );
end;
procedure openNewInstance();
begin
NSWorkspace.sharedWorkspace.launchApplicationAtURL_options_configuration_error(
NSBundle.mainBundle.bundleURL,
NSWorkspaceLaunchNewInstance,
nil,
nil);
end;
procedure Initialize;
begin
MacosServiceMenuHelper:= TMacosServiceMenuHelper.Create;