Quellcode durchsuchen

FIX: MacOS: color not updated in FileView after theme changed (#702)

rich2014 vor 2 Jahren
Ursprung
Commit
7a2df05953

+ 2 - 0
src/fileviews/ufileview.pas

@@ -440,6 +440,8 @@ type
 
 
     procedure UpdateView;
     procedure UpdateView;
 
 
+    procedure UpdateColor; virtual; abstract;
+
     {en
     {en
        Moves the selection focus to the file specified by aFilePath.
        Moves the selection focus to the file specified by aFilePath.
        @param(aFilePath may be an absolute path to the file or just a file name.)
        @param(aFilePath may be an absolute path to the file or just a file name.)

+ 9 - 2
src/fileviews/ufileviewwithmainctrl.pas

@@ -221,6 +221,8 @@ type
     procedure SetFocus; override;
     procedure SetFocus; override;
     procedure SetDragCursor(Shift: TShiftState); override;
     procedure SetDragCursor(Shift: TShiftState); override;
 
 
+    procedure UpdateColor; override;
+
   published
   published
     procedure cm_RenameOnly(const Params: array of string);
     procedure cm_RenameOnly(const Params: array of string);
     procedure cm_ContextMenu(const Params: array of string);
     procedure cm_ContextMenu(const Params: array of string);
@@ -494,7 +496,7 @@ end;
 procedure TFileViewWithMainCtrl.DoActiveChanged;
 procedure TFileViewWithMainCtrl.DoActiveChanged;
 begin
 begin
   inherited DoActiveChanged;
   inherited DoActiveChanged;
-  MainControl.Color := DimColor(gBackColor);
+  UpdateColor;
   // Needed for rename on mouse
   // Needed for rename on mouse
   FMouseRename := False;
   FMouseRename := False;
 end;
 end;
@@ -577,13 +579,18 @@ end;
 
 
 procedure TFileViewWithMainCtrl.DoLoadingFileListLongTime;
 procedure TFileViewWithMainCtrl.DoLoadingFileListLongTime;
 begin
 begin
-  MainControl.Color := DimColor(gBackColor);
+  UpdateColor;
   inherited DoLoadingFileListLongTime;
   inherited DoLoadingFileListLongTime;
 end;
 end;
 
 
 procedure TFileViewWithMainCtrl.DoUpdateView;
 procedure TFileViewWithMainCtrl.DoUpdateView;
 begin
 begin
   inherited DoUpdateView;
   inherited DoUpdateView;
+  UpdateColor;
+end;
+
+procedure TFileViewWithMainCtrl.UpdateColor;
+begin
   MainControl.Color := DimColor(gBackColor);
   MainControl.Color := DimColor(gBackColor);
 end;
 end;
 
 

+ 8 - 0
src/fmain.pas

@@ -874,6 +874,7 @@ type
     procedure OnNSServiceOpenWithNewTab( filenames:TStringList );
     procedure OnNSServiceOpenWithNewTab( filenames:TStringList );
     function NSServiceMenuIsReady(): boolean;
     function NSServiceMenuIsReady(): boolean;
     function NSServiceMenuGetFilenames(): TStringList;
     function NSServiceMenuGetFilenames(): TStringList;
+    procedure NSThemeChangedHandler();
     {$ENDIF}
     {$ENDIF}
     procedure LoadWindowState;
     procedure LoadWindowState;
     procedure SaveWindowState;
     procedure SaveWindowState;
@@ -1216,6 +1217,7 @@ begin
 
 
 {$IF DEFINED(DARWIN)}
 {$IF DEFINED(DARWIN)}
   InitNSServiceProvider( @OnNSServiceOpenWithNewTab, @NSServiceMenuIsReady, @NSServiceMenuGetFilenames );
   InitNSServiceProvider( @OnNSServiceOpenWithNewTab, @NSServiceMenuIsReady, @NSServiceMenuGetFilenames );
+  InitNSThemeChangedObserver( @NSThemeChangedHandler );
 {$ENDIF}
 {$ENDIF}
 end;
 end;
 
 
@@ -6125,6 +6127,12 @@ begin
 
 
   if filenames.Count>0 then Result:= filenames;
   if filenames.Count>0 then Result:= filenames;
 end;
 end;
+
+procedure TfrmMain.NSThemeChangedHandler;
+begin
+  FrameLeft.UpdateColor;
+  FrameRight.UpdateColor;
+end;
 {$ENDIF}
 {$ENDIF}
 
 
 procedure TfrmMain.LoadWindowState;
 procedure TfrmMain.LoadWindowState;

+ 31 - 2
src/platform/unix/darwin/umydarwin.pas

@@ -28,7 +28,7 @@ unit uMyDarwin;
 interface
 interface
 
 
 uses
 uses
-  Classes, SysUtils, UnixType, MacOSAll, CocoaAll, CocoaUtils, CocoaInt, InterfaceBase, Menus, CocoaWSMenus;
+  Classes, SysUtils, UnixType, MacOSAll, CocoaAll, CocoaUtils, CocoaInt, Cocoa_Extra, InterfaceBase, Menus, CocoaWSMenus;
 
 
 // Darwin Util Function
 // Darwin Util Function
 function StringToNSString(const S: String): NSString;
 function StringToNSString(const S: String): NSString;
@@ -83,9 +83,9 @@ type TNSServiceMenuIsReady = Function(): Boolean of object;
 type TNSServiceMenuGetFilenames = Function(): TStringList of object;
 type TNSServiceMenuGetFilenames = Function(): TStringList of object;
 
 
 type TDCCocoaApplication = objcclass(TCocoaApplication)
 type TDCCocoaApplication = objcclass(TCocoaApplication)
-private
   function validRequestorForSendType_returnType (sendType: NSString; returnType: NSString): id; override;
   function validRequestorForSendType_returnType (sendType: NSString; returnType: NSString): id; override;
   function writeSelectionToPasteboard_types (pboard: NSPasteboard; types: NSArray): ObjCBOOL; message 'writeSelectionToPasteboard:types:';
   function writeSelectionToPasteboard_types (pboard: NSPasteboard; types: NSArray): ObjCBOOL; message 'writeSelectionToPasteboard:types:';
+  procedure observeValueForKeyPath_ofObject_change_context( keyPath: NSString; object_: id; change: NSDictionary; context: pointer); override;
 public
 public
   serviceMenuIsReady: TNSServiceMenuIsReady;
   serviceMenuIsReady: TNSServiceMenuIsReady;
   serviceMenuGetFilenames: TNSServiceMenuGetFilenames;
   serviceMenuGetFilenames: TNSServiceMenuGetFilenames;
@@ -112,10 +112,16 @@ procedure InitNSServiceProvider(
   isReadyFunc: TNSServiceMenuIsReady;
   isReadyFunc: TNSServiceMenuIsReady;
   getFilenamesFunc: TNSServiceMenuGetFilenames );
   getFilenamesFunc: TNSServiceMenuGetFilenames );
 
 
+// MacOS Theme
+type TNSThemeChangedHandler = Procedure() of object;
+
+procedure InitNSThemeChangedObserver( handler: TNSThemeChangedHandler );
+
 var
 var
   HasMountURL: Boolean = False;
   HasMountURL: Boolean = False;
   NSServiceProvider: TNSServiceProvider;
   NSServiceProvider: TNSServiceProvider;
   MacosServiceMenuHelper: TMacosServiceMenuHelper;
   MacosServiceMenuHelper: TMacosServiceMenuHelper;
+  NSThemeChangedHandler: TNSThemeChangedHandler;
 
 
 implementation
 implementation
 
 
@@ -226,6 +232,29 @@ begin
   FreeAndNil( filenameList );
   FreeAndNil( filenameList );
 end;
 end;
 
 
+procedure TDCCocoaApplication.observeValueForKeyPath_ofObject_change_context(
+  keyPath: NSString; object_: id; change: NSDictionary; context: pointer);
+begin
+  Inherited observeValueForKeyPath_ofObject_change_context( keyPath, object_, change, context );
+  if keyPath.isEqualToString(NSSTR('effectiveAppearance')) then
+  begin
+    NSAppearance.setCurrentAppearance( self.appearance );
+    if Assigned(NSThemeChangedHandler) then NSThemeChangedHandler;
+  end;
+end;
+
+procedure InitNSThemeChangedObserver( handler: TNSThemeChangedHandler );
+begin
+  if Assigned(NSThemeChangedHandler) then exit;
+
+  NSApp.addObserver_forKeyPath_options_context(
+    NSApp, NSSTR('effectiveAppearance'), 0, nil );
+
+  NSThemeChangedHandler:= handler;
+end;
+
+
+
 function NSArrayToList(const theArray:NSArray): TStringList;
 function NSArrayToList(const theArray:NSArray): TStringList;
 var
 var
   i: Integer;
   i: Integer;