-
Notifications
You must be signed in to change notification settings - Fork 0
/
SWSharedInspector.m
105 lines (78 loc) · 2.87 KB
/
SWSharedInspector.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
//
// SWSharedInspector.m
// This file is part of the "SWApplicationSupport" project, and is distributed under the MIT License.
//
// Created by Samuel Williams on 21/03/06.
// Copyright 2006 Samuel Williams. All rights reserved.
//
#import "SWSharedInspector.h"
@interface SWSharedInspector (Private)
- (void)setMainWindow:(NSWindow *)mainWindow;
+ (id*)staticInspector;
@end
@implementation SWSharedInspector
/*
+ (id*) staticInspector {
static id inspector = nil;
return &inspector;
}
*/
- (void) _setupNotifications {
//[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(mainWindowClosed:) name:NSWindowWillCloseNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(mainWindowChanged:) name:NSWindowDidBecomeMainNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(mainWindowResigned:) name:NSWindowDidResignMainNotification object:nil];
}
+ (id) sharedInspector {
id *sharedInspector = [[self class] staticInspector];
if (! *sharedInspector) {
*sharedInspector = [[[self class] alloc] init];
[*sharedInspector _setupNotifications];
}
NSAssert (*sharedInspector != nil, @"Shared Inspector failed to initialize!");
return *sharedInspector;
}
- (void) windowWillClose: (id)notification {
//NSLog (@"Shared Inspector will close");
}
- (void) dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
[super dealloc];
}
- (void)mainWindowClosed:(NSNotification *)notification {
NSLog (@"%@ (Shared Inspector) mainWindowClosed", [self className]);
[self setMainWindow:nil];
}
- (void)mainWindowChanged:(NSNotification *)notification {
NSLog (@"%@ (Shared Inspector) mainWindowChanged", [self className]);
[self setMainWindow:[notification object]];
}
- (void)mainWindowResigned:(NSNotification *)notification {
NSLog (@"%@ (Shared Inspector) mainWindowResigned", [self className]);
[self setMainWindow:nil];
}
- (void)setMainWindow:(NSWindow *)mainWindow {
NSWindowController *controller = nil;
if (mainWindow)
controller = [mainWindow windowController];
if (controller && [controller document]) {
[self setDocument:[controller document]];
[self showWindow: self];
} else {
[self setDocument:nil];
[self close];
}
}
- (void) show {
[self setDocument: [[NSDocumentController sharedDocumentController] currentDocument]];
[self showWindow: self];
} // show
- (void) windowDidLoad {
[super windowDidLoad];
//NSLog (@"%@ (Shared Inspector) windowDidLoad", [self className]);
//[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(closeInspector:) name:NSApplicationWillTerminateNotification object:nil];
[self setShouldCascadeWindows: NO];
[self setWindowFrameAutosaveName: [self className]];
[self setShouldCloseDocument: NO];
//[self setDocument: [self document]];
}
@end