Revision: 12410
          http://sourceforge.net/p/skim-app/code/12410
Author:   hofman
Date:     2021-09-18 09:24:17 +0000 (Sat, 18 Sep 2021)
Log Message:
-----------
Observe colors of color swatch rather than user defaults

Modified Paths:
--------------
    trunk/SKDisplayPreferences.m

Modified: trunk/SKDisplayPreferences.m
===================================================================
--- trunk/SKDisplayPreferences.m        2021-09-17 21:47:49 UTC (rev 12409)
+++ trunk/SKDisplayPreferences.m        2021-09-18 09:24:17 UTC (rev 12410)
@@ -64,11 +64,16 @@
 - (void)dealloc {
     if (RUNNING_AFTER(10_13)) {
         @try {
-            [[NSUserDefaultsController sharedUserDefaultsController] 
removeObserver:self forKeys:[NSArray arrayWithObjects:SKBackgroundColorKey, 
SKFullScreenBackgroundColorKey, SKDarkBackgroundColorKey, 
SKDarkFullScreenBackgroundColorKey, SKSwatchColorsKey, nil] 
context:&SKDisplayPreferencesDefaultsObservationContext];
-            [colorSwatch unbind:@"colors"];
+            [[NSUserDefaultsController sharedUserDefaultsController] 
removeObserver:self forKeys:[NSArray arrayWithObjects:SKBackgroundColorKey, 
SKFullScreenBackgroundColorKey, SKDarkBackgroundColorKey, 
SKDarkFullScreenBackgroundColorKey, nil] 
context:&SKDisplayPreferencesDefaultsObservationContext];
         }
         @catch(id e) {}
     }
+    @try {
+        [colorSwatch unbind:@"colors"];
+        [colorSwatch removeObserver:self forKeyPath:@"selectedColorIndex" 
context:&SKDisplayPreferencesColorSwatchObservationContext];
+        [colorSwatch removeObserver:self forKeyPath:@"colors" 
context:&SKDisplayPreferencesColorSwatchObservationContext];
+    }
+    @catch(id e) {}
     SKDESTROY(normalColorWell);
     SKDESTROY(fullScreenColorWell);
     SKDESTROY(colorSwatch);
@@ -90,6 +95,7 @@
     [colorSwatch setSelects:YES];
     [colorSwatch setFrame:NSOffsetRect([colorSwatch frame], 0.0, 1.0)];
     [colorSwatch addObserver:self forKeyPath:@"selectedColorIndex" options:0 
context:&SKDisplayPreferencesColorSwatchObservationContext];
+    [colorSwatch addObserver:self forKeyPath:@"colors" options:0 
context:&SKDisplayPreferencesColorSwatchObservationContext];
     
     if (RUNNING_AFTER(10_13)) {
         [normalColorWell unbind:NSValueBinding];
@@ -101,7 +107,7 @@
         
         [self updateBackgroundColors];
         
-        [[NSUserDefaultsController sharedUserDefaultsController] 
addObserver:self forKeys:[NSArray arrayWithObjects:SKBackgroundColorKey, 
SKFullScreenBackgroundColorKey, SKDarkBackgroundColorKey, 
SKDarkFullScreenBackgroundColorKey, SKSwatchColorsKey, nil] 
context:&SKDisplayPreferencesDefaultsObservationContext];
+        [[NSUserDefaultsController sharedUserDefaultsController] 
addObserver:self forKeys:[NSArray arrayWithObjects:SKBackgroundColorKey, 
SKFullScreenBackgroundColorKey, SKDarkBackgroundColorKey, 
SKDarkFullScreenBackgroundColorKey, nil] 
context:&SKDisplayPreferencesDefaultsObservationContext];
         [NSApp addObserver:self forKeyPath:@"effectiveAppearance" options:0 
context:&SKDisplayPreferencesDefaultsObservationContext];
     }
 }
@@ -152,9 +158,7 @@
 
 - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object 
change:(NSDictionary *)change context:(void *)context {
     if (context == &SKDisplayPreferencesDefaultsObservationContext) {
-        if ([[keyPath substringFromIndex:7] isEqualToString:SKSwatchColorsKey])
-            [addRemoveColorButton setEnabled:([colorSwatch selectedColorIndex] 
!= -1 && [[colorSwatch colors] count] > 1) forSegment:1];
-        else if (changingColors == NO)
+        if (changingColors == NO)
             [self updateBackgroundColors];
     } else if (context == &SKDisplayPreferencesColorSwatchObservationContext) {
         [addRemoveColorButton setEnabled:([colorSwatch selectedColorIndex] != 
-1 && [[colorSwatch colors] count] > 1) forSegment:1];

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.



_______________________________________________
Skim-app-commit mailing list
Skim-app-commit@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to