-
Notifications
You must be signed in to change notification settings - Fork 15
/
SdefObjectInspector.m
95 lines (78 loc) · 2.36 KB
/
SdefObjectInspector.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
/*
* SdefObjectInspector.m
* Sdef Editor
*
* Created by Rainbow Team.
* Copyright © 2006 - 2007 Shadow Lab. All rights reserved.
*/
#import "SdefObjectInspector.h"
#import "SdefObjects.h"
#import "SdefDocument.h"
#import "SdefWindowController.h"
@implementation SdefObjectInspector
+ (id)sharedInspector {
static id inspector = nil;
if (!inspector) {
inspector = [[self alloc] init];
}
return inspector;
}
- (id)init {
if (self = [super initWithWindowNibName:@"SdefInspector"]) {
[self setWindowFrameAutosaveName:@"SdefObjectInspector"];
needsUpdate = NO;
}
return self;
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
#pragma mark -
- (void)windowDidUpdate:(NSNotification *)notification {
if (needsUpdate && [NSApp isActive]) {
[self willChangeValueForKey:@"content"];
[self didChangeValueForKey:@"content"];
needsUpdate = NO;
}
}
- (SdefObject *)content {
return [sd_doc selection];
}
- (SdefDocument *)displayedDocument {
return sd_doc;
}
- (void)setDisplayedDocument:(SdefDocument *)aDocument {
if (sd_doc != aDocument) {
sd_doc = aDocument;
needsUpdate = YES;
}
}
- (void)setMainWindow:(NSWindow *)mainWindow {
if ([NSApp isActive]) {
NSWindowController *controller = [mainWindow windowController];
if (controller && [controller isKindOfClass:[SdefWindowController class]]) {
[self setDisplayedDocument:[controller document]];
} else {
[self setDisplayedDocument:nil];
}
}
}
- (void)windowDidLoad {
[super windowDidLoad];
[self setMainWindow:[NSApp mainWindow]];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(mainWindowChanged:) name:NSWindowDidBecomeMainNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(mainWindowResigned:) name:NSWindowDidResignMainNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(selectionChanged:) name:SdefDictionarySelectionDidChangeNotification object:nil];
}
- (void)mainWindowChanged:(NSNotification *)aNotification {
[self setMainWindow:[aNotification object]];
}
- (void)mainWindowResigned:(NSNotification *)aNotification {
[self setMainWindow:nil];
}
- (void)selectionChanged:(NSNotification *)aNotification {
if ([aNotification object] == sd_doc) {
needsUpdate = YES;
}
}
@end