-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathSSYWindowHangout.m
90 lines (69 loc) · 2.58 KB
/
SSYWindowHangout.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#import "SSYWindowHangout.h"
static NSMutableSet* static_hangout = nil ;
@interface SSYWindowHangout ()
@property (retain) NSWindowController* windowController ;
@end
@implementation SSYWindowHangout
@synthesize windowController = m_windowController ;
- (void)dealloc {
[m_windowController release] ;
[super dealloc] ;
}
- (id)initWithWindowController:(NSWindowController*)windowController {
self = [super init] ;
if (self) {
[self setWindowController:windowController] ;
}
return self ;
}
- (void)windowDidCloseNote:(NSNotification*)note {
NSWindow* window = (NSWindow*)[note object] ;
NSWindowController* windowController = [window windowController] ;
[window setWindowController:nil] ;
[windowController setWindow:nil] ;
[[NSNotificationCenter defaultCenter] removeObserver:self] ;
/*
The following line was removed in BookMacster 1.19.2, so that window
controllers would be deallocated immediately. Originally, I thought that
it was good defensive programming, but in fact there is no need for it,
and the delayed deallocation can cause, for example, observers to hang
on longer than necessary, causing trouble when things are torn down.
*/
//[[self retain] autorelease] ;
[static_hangout removeObject:self] ;
if ([static_hangout count] == 0) {
[static_hangout release] ;
static_hangout = nil ;
}
}
+ (void)hangOutWindowController:(NSWindowController*)windowController {
NSWindow* window = [windowController window] ;
if (!window) {
NSLog(@"Internal Error 614-0595. %s Trouble ahead with %@",
__PRETTY_FUNCTION__,
windowController) ;
}
else {
if (!static_hangout) {
static_hangout = [[NSMutableSet alloc] init] ;
}
SSYWindowHangout* hangout = [[self alloc] initWithWindowController:windowController] ;
[static_hangout addObject:hangout] ;
[hangout release] ;
NSNotificationCenter* noter = [NSNotificationCenter defaultCenter] ;
[noter addObserver:hangout
selector:@selector(windowDidCloseNote:)
name:NSWindowWillCloseNotification
object:window] ;
}
}
+ (NSWindowController*)hungOutWindowControllerOfClass:(Class)class {
for (SSYWindowHangout* hangout in static_hangout) {
NSWindowController* windowController = [hangout windowController] ;
if ([windowController isKindOfClass:class]) {
return windowController ;
}
}
return nil ;
}
@end