forked from adlr/formulatepro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FPInspectorController.m
177 lines (154 loc) · 5.22 KB
/
FPInspectorController.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#import "FPInspectorController.h"
#import "FPDocumentView.h"
#import "FPLogging.h"
@implementation FPInspectorController
- (void)awakeFromNib
{
[(NSPanel *)[self window] setFloatingPanel:YES];
[(NSPanel *)[self window] setBecomesKeyOnlyIfNeeded:YES];
[self cascadeEnabledness];
// [[NSNotificationCenter defaultCenter]
// addObserver:self
// selector:@selector(windowDidBecomeKey:)
// name:NSWindowDidBecomeKeyNotification
// object:nil];
[[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(selectionChangedNotification:)
name:FPSelectionChangedNotification
object:nil];
_main_window = nil;
}
- (void)cascadeEnabledness
{
BOOL doStroke = ([_strokeCheckbox state] == NSOnState);
[_widthTextField setEnabled:doStroke];
[_widthStepper setEnabled:doStroke];
[_strokeColorWell setEnabled:doStroke];
if (doStroke) {
[_widthTextField setTextColor:[NSColor blackColor]];
[_widthLabel setTextColor:[NSColor blackColor]];
} else {
[_widthTextField setTextColor:[NSColor grayColor]];
[_widthLabel setTextColor:[NSColor grayColor]];
}
BOOL doFill = ([_fillCheckbox state] == NSOnState);
[_fillColorWell setEnabled:doFill];
}
- (IBAction)checkFill:(id)sender
{
[self cascadeEnabledness];
}
- (IBAction)checkStroke:(id)sender
{
[self cascadeEnabledness];
}
- (IBAction)setStroke:(id)sender
{
}
- (IBAction)stepStroke:(id)sender
{
}
- (IBAction)checkHideWhenPrinting:(id)sender;
{
}
- (void)disableAllGraphics
{
[_strokeCheckbox setEnabled:NO];
[_strokeColorWell setEnabled:NO];
[_fillCheckbox setEnabled:NO];
[_fillColorWell setEnabled:NO];
[_widthLabel setTextColor:[NSColor grayColor]];
[_widthStepper setEnabled:NO];
[_widthTextField setEnabled:NO];
[_hideWhenPrinting setEnabled:NO];
}
- (void)enableAllGraphics
{
[_strokeCheckbox setEnabled:YES];
[_strokeColorWell setEnabled:YES];
[_fillCheckbox setEnabled:YES];
[_fillColorWell setEnabled:YES];
[_widthLabel setTextColor:[NSColor blackColor]];
[_widthStepper setEnabled:YES];
[_widthTextField setEnabled:YES];
[_hideWhenPrinting setEnabled:YES];
}
- (void)updateFromSelectedGraphics
{
if (!_main_window) {
// disable all controls
[self disableAllGraphics];
return;
}
NSSet *selectedGraphics = [[_main_window docView] selectedGraphics];
if (0 == [selectedGraphics count]) {
// disable all controls
[self disableAllGraphics];
return;
}
if (1 == [selectedGraphics count]) {
// enable all controls
[self enableAllGraphics];
// FPGraphic *graphic = [selectedGraphics anyObject];
return;
}
}
- (void)selectionOrMainWindowChanged
{
DLog(@"there are %d graphics selected", [[[_main_window docView] selectedGraphics] count]);
[self updateFromSelectedGraphics];
}
- (void)selectionChangedNotification:(NSNotification *)notification
{
DLog(@"selection did change\n");
assert([FPDocumentWindow class] == [[notification object] class]);
FPDocumentWindow *window = [notification object];
if (window == _main_window)
[self selectionOrMainWindowChanged];
}
//- (void)windowDidBecomeKey:(id)sender
//{
// DLog(@"window did become key: 0x%08x\n", (int)sender);
//
// DLog(@"docs:\n");
// NSArray *docs = [NSApp orderedDocuments];
// for (int i = 0; i < [docs count]; i++) {
// DLog(@"%i of %i: 0x%08x\n", i, [docs count], [docs objectAtIndex:i]);
// }
//
// MyDocument *new_frontmost_doc = nil;
//// if ([docs count])
//// new_frontmost_doc = [docs objectAtIndex:0];
// if ([NSApp mainWindow])
// new_frontmost_doc = [[[NSApp mainWindow] windowController] document];
//
// if (new_frontmost_doc != _frontmost_document) {
// _frontmost_document = new_frontmost_doc;
// [self selectionDidChange];
// }
//}
- (void)mainWindowChanged:(NSNotification *)notification
{
DLog(@"got main window: 0x%08x\n", [notification object]);
if ([FPDocumentWindow class] == [[notification object] class]) {
_main_window = (FPDocumentWindow *)[notification object];
[self selectionOrMainWindowChanged];
}
}
- (void)mainWindowResigned:(NSNotification *)notification
{
DLog(@"lost main window: 0x%08x\n", [notification object]);
if ([FPDocumentWindow class] == [[notification object] class]) {
_main_window = nil;
[self selectionOrMainWindowChanged];
}
}
@end