Revision: 29164
          http://sourceforge.net/p/bibdesk/svn/29164
Author:   hofman
Date:     2025-04-21 15:53:35 +0000 (Mon, 21 Apr 2025)
Log Message:
-----------
only register for key and main change notifications when we have a window and 
the background color is nil

Modified Paths:
--------------
    trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFileView.m

Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFileView.m
===================================================================
--- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFileView.m      2025-04-21 
15:34:31 UTC (rev 29163)
+++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFileView.m      2025-04-21 
15:53:35 UTC (rev 29164)
@@ -266,6 +266,8 @@
 - (void)_stopPreviewing;
 - (void)_updatePreviewer;
 - (void)handlePreviewerWillClose:(NSNotification *)aNote;
+- (void)_registerForKeyOrMainStateNotifications;
+- (void)_unregisterForKeyOrMainStateNotifications;
 
 @end
 
@@ -495,6 +497,12 @@
 - (void)setBackgroundColor:(NSColor *)aColor;
 {
     if (_backgroundColor != aColor) {
+        if ([self window]) {
+            if (_backgroundColor == nil)
+                [self _unregisterForKeyOrMainStateNotifications];
+            else if (aColor == nil)
+                [self _registerForKeyOrMainStateNotifications];
+        }
         _backgroundColor = [aColor copy];
         [_backgroundView setBackgroundColor:_backgroundColor];
     }
@@ -1116,11 +1124,19 @@
     }
 }
 
-- (void)viewWillMoveToWindow:(NSWindow *)newWindow {
+- (void)_registerForKeyOrMainStateNotifications {
     NSWindow *window = [self window];
-    if (newWindow == nil && [[_sliderWindow parentWindow] isEqual:window]) {
-        [_sliderWindow orderOut:nil];
+    if (window) {
+        NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
+        [nc addObserver:self 
selector:@selector(_handleKeyOrMainStateNotification:) 
name:NSWindowDidBecomeMainNotification object:window];
+        [nc addObserver:self 
selector:@selector(_handleKeyOrMainStateNotification:) 
name:NSWindowDidResignMainNotification object:window];
+        [nc addObserver:self 
selector:@selector(_handleKeyOrMainStateNotification:) 
name:NSWindowDidBecomeKeyNotification object:window];
+        [nc addObserver:self 
selector:@selector(_handleKeyOrMainStateNotification:) 
name:NSWindowDidResignKeyNotification object:window];
     }
+}
+
+- (void)_unregisterForKeyOrMainStateNotifications {
+    NSWindow *window = [self window];
     if (window) {
         NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
         [nc removeObserver:self name:NSWindowDidBecomeMainNotification 
object:window];
@@ -1128,18 +1144,23 @@
         [nc removeObserver:self name:NSWindowDidBecomeKeyNotification 
object:window];
         [nc removeObserver:self name:NSWindowDidResignKeyNotification 
object:window];
     }
+}
+
+- (void)viewWillMoveToWindow:(NSWindow *)newWindow {
+    NSWindow *window = [self window];
+    if (newWindow == nil && [[_sliderWindow parentWindow] isEqual:window]) {
+        [_sliderWindow orderOut:nil];
+    }
+    if (window && _backgroundColor == nil) {
+        [self _unregisterForKeyOrMainStateNotifications];
+    }
     [super viewWillMoveToWindow:newWindow];
 }
 
 - (void)viewDidMoveToWindow {
     // for redrawing background color
-    NSWindow *window = [self window];
-    if (window) {
-        NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
-        [nc addObserver:self 
selector:@selector(_handleKeyOrMainStateNotification:) 
name:NSWindowDidBecomeMainNotification object:window];
-        [nc addObserver:self 
selector:@selector(_handleKeyOrMainStateNotification:) 
name:NSWindowDidResignMainNotification object:window];
-        [nc addObserver:self 
selector:@selector(_handleKeyOrMainStateNotification:) 
name:NSWindowDidBecomeKeyNotification object:window];
-        [nc addObserver:self 
selector:@selector(_handleKeyOrMainStateNotification:) 
name:NSWindowDidResignKeyNotification object:window];
+    if ([self window] && _backgroundColor == nil) {
+        [self _registerForKeyOrMainStateNotifications];
     }
     [super viewDidMoveToWindow];
 }

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



_______________________________________________
Bibdesk-commit mailing list
Bibdesk-commit@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit

Reply via email to