diff options
author | Max <post@wickenrode.com> | 2015-08-29 20:31:51 +0200 |
---|---|---|
committer | Max <post@wickenrode.com> | 2015-08-29 20:31:51 +0200 |
commit | 6f00eaa2e639fa852793fe338627e089586463f2 (patch) | |
tree | 03aaa00253515ac488a6181d315c4916eef1b3aa | |
parent | 4552d5daa1bcb094ce2681e594fca69379a469d0 (diff) | |
download | sequelpro-6f00eaa2e639fa852793fe338627e089586463f2.tar.gz sequelpro-6f00eaa2e639fa852793fe338627e089586463f2.tar.bz2 sequelpro-6f00eaa2e639fa852793fe338627e089586463f2.zip |
Add some further debug code for _scrollViewDidChangeBounds:
-rw-r--r-- | Source/SPObjectAdditions.m | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/Source/SPObjectAdditions.m b/Source/SPObjectAdditions.m index 017efd6e..55e95437 100644 --- a/Source/SPObjectAdditions.m +++ b/Source/SPObjectAdditions.m @@ -28,6 +28,9 @@ // // More info at <https://github.com/sequelpro/sequelpro> +#import <objc/runtime.h> +static NSMutableDictionary *gScrollViewListeners; + @implementation NSObject (SPObjectAdditions) /** @@ -92,7 +95,53 @@ retryDescribe: [msg appendFormat:@"self: %p (class <%@>)\n\n",self,[self className]]; + NSString *key = [NSString stringWithFormat:@"snd=%p,obs=%p",obj,self]; + + [msg appendFormat:@"registration info for pair (%@):\n %@",key,[gScrollViewListeners objectForKey:key]]; + @throw [NSException exceptionWithName:NSInternalInconsistencyException reason:msg userInfo:nil]; } @end + + +@implementation NSNotificationCenter (SPScrollViewDebug) + ++ (void)load +{ + static dispatch_once_t onceToken; + + dispatch_once(&onceToken, ^{ + gScrollViewListeners = [[NSMutableDictionary alloc] init]; + + Class notificationCenter = [self class]; + + SEL orig = @selector(addObserver:selector:name:object:); + SEL exch = @selector(sp_addObserver:selector:name:object:); + + Method origM = class_getInstanceMethod(notificationCenter, orig); + Method exchM = class_getInstanceMethod(notificationCenter, exch); + + method_exchangeImplementations(origM, exchM); + }); + +} + +- (void)sp_addObserver:(id)notificationObserver selector:(SEL)notificationSelector name:(NSString *)notificationName object:(id)notificationSender +{ + if(notificationSelector == @selector(_scrollViewDidChangeBounds:) && [notificationName isEqualToString:NSViewBoundsDidChangeNotification]) { + NSString *key = [NSString stringWithFormat:@"snd=%p,obs=%p",notificationSender,notificationObserver]; + NSMutableString *val = [NSMutableString string]; + [val appendFormat:@"observer: %1$p (class %2$@) description: %1$@\n",notificationObserver,[notificationObserver className]]; + if([notificationObserver isKindOfClass:[NSView class]]) { + [val appendFormat:@" view info: id=%@, tag=%ld\n",[(NSView *)notificationObserver identifier], [(NSView *)notificationObserver tag]]; + } + [val appendFormat:@"\nbacktrace:\n%@\n\n",[NSThread callStackSymbols]]; + + [gScrollViewListeners setObject:val forKey:key]; + } + // not recursive! method is swizzled. + [self sp_addObserver:notificationObserver selector:notificationSelector name:notificationName object:notificationSender]; +} + +@end |