This repository has been archived by the owner on Oct 9, 2018. It is now read-only.
/
MWInspectorViewController.m
246 lines (183 loc) · 6.15 KB
/
MWInspectorViewController.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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
//
// MWInspectorViewController.m
// NewEditor
//
// Created by David Cox on 11/5/07.
// Copyright 2007 __MyCompanyName__. All rights reserved.
//
#import "MWInspectorViewController.h"
#import "MWCustomInspectorSubviewController.h"
#import "MWXMLElementAdditions.h"
@implementation MWInspectorViewController
-(id)init{
current_view_index = 1;
[self setAttributeFilter:[NSPredicate predicateWithFormat:@"!(%K BEGINSWITH \"_\")", @"name"]];
return self;
}
- (void)awakeFromNib{
}
- (int)currentViewIndex{
return current_view_index;
}
- (IBAction)update:(id)sender {
NSArray *selected = [experiment_controller selectedObjects];
if([selected count] == 0){
[self setCurrentViewIndex:MWGenericInspectorKey];
return;
}
NSXMLElement *current_element = [selected objectAtIndex:0];
if([current_element hasAttribute:@"_inspector"]){
[self setCurrentViewIndex:MWCustomInspectorKey];
} else {
[self setCurrentViewIndex:[self currentViewIndex]];
}
}
- (void)setCurrentViewIndex:(int)ind{
NSArray *selected;
NSXMLElement *current_element;
NSLog(@"Set index %d", ind);
current_view_index = ind;
switch([self currentViewIndex]){
case MWCustomInspectorKey:
selected = [experiment_controller selectedObjects];
current_element = [selected objectAtIndex:0];
NSXMLNode *att = [current_element attributeForName:@"_inspector"];
if(att){
NSString *inspector_nib = [att stringValue];
if(inspector_nib == Nil){
return [self setCurrentViewIndex:MWGenericInspectorKey];
}
NSLog(@"Inspector nib: %@", inspector_nib);
if(![self loadNib:inspector_nib]){
return [self setCurrentViewIndex:MWGenericInspectorKey];
}
// custom_view should have be set from inside the loaded Nib
if(custom_view == Nil){
return [self setCurrentViewIndex:MWGenericInspectorKey];
}
NSSize custom_inspector_size = [custom_view frame].size;
NSSize new_window_size = custom_inspector_size;
new_window_size.height += 40;
NSRect new_window_frame = [inspector_panel frame];
new_window_frame.size = new_window_size;
[inspector_panel setFrame:new_window_frame display:YES
animate:YES];
[inspector_view setInspectorView:custom_view];
} else {
return [self setCurrentViewIndex:MWGenericInspectorKey];
}
break;
case MWXMLInspectorKey:
[inspector_view setInspectorView:xml_view];
return;
case MWGenericInspectorKey:
[inspector_view setInspectorView:generic_view];
return;
}
}
- (IBAction)switchView:(id)sender{
[self setCurrentViewIndex:[sender selectedSegment]];
}
- (BOOL)loadNib:(NSString *)name{
// TODO: error check name
if (![NSBundle loadNibNamed:name owner:self]){
NSLog(@"Warning! Could not load nib file.\n");
return NO;
}
// experiment_selection_controller should have been set from inside of the
if(selected_object_controller == Nil){
return NO;
}
NSDictionary *options =
[NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES], NSConditionallySetsEditableBindingOption,
[NSNumber numberWithBool:YES], NSContinuouslyUpdatesValueBindingOption,
nil];
// Hook up the bindings programmatically
[selected_object_controller bind:@"contentObject"
toObject:experiment_controller
withKeyPath:@"selection.object"
options:options];
/*[selected_object_controller bind:@"managedObjectContext"
toObject:experiment_controller
withKeyPath:@""
options:nil];*/
/* [selected_object_controller addObserver:experiment_controller
forKeyPath:@"content"
options:(NSKeyValueObservingOptionNew |
NSKeyValueObservingOptionOld)
context:NULL];*/
return YES;
}
- (NSPredicate *)attributeFilter {
return attributeFilter;
}
- (void)setAttributeFilter: (NSPredicate *)_pred{
attributeFilter = _pred;
}
- (NSArray *)control:(NSControl *)control
textView:(NSTextView *)textView
completions:(NSArray *)words
forPartialWordRange:(NSRange)charRange
indexOfSelectedItem:(int *)index{
return [experiment_controller control:control
textView:textView
completions:words
forPartialWordRange:charRange
indexOfSelectedItem:index];
}
- (NSInteger)numberOfItemsInComboBox:(NSComboBox *)control
{
return[ experiment_controller numberOfItemsInComboBox:control];
}
- (id)comboBox:(NSComboBox *)control objectValueForItemAtIndex:(NSInteger)index
{
return [experiment_controller comboBox:control
objectValueForItemAtIndex:index];
}
- (NSString *)comboBox:(NSComboBox *)control
completedString:(NSString *)uncompletedString
{
return [experiment_controller comboBox:control
completedString:uncompletedString];
}
- (IBAction)addAttribute:(id)sender {
if(attributesController != Nil){
int n = 0;
NSArray *attributes = [attributesController arrangedObjects];
BOOL okay = NO;
NSString *new_attribute_name;
while(!okay){
okay = YES;
new_attribute_name = [NSString stringWithFormat:@"new_attribute_%d", n++];
int i;
for(i = 0; i < [attributes count]; i++){
NSString *name = [[attributes objectAtIndex:i] name];
if([name isEqualToString:new_attribute_name]){
okay = NO;
break;
}
}
}
NSXMLNode *node = [NSXMLNode attributeWithName:new_attribute_name stringValue:@""];
[attributesController addObject:node];
}
}
/*#pragma mark -
#pragma mark Textfield Autocompletion Delegate Methods
- (NSArray *)control:(NSControl *)control
textView:(NSTextView *)textView
completions:(NSArray *)words
forPartialWordRange:(NSRange)charRange
indexOfSelectedItem:(int *)index{
// TODO: also check for a xPathForPartialTag: withNodeID: selector
// get the node ID from the currently selected
if(![control respondsToSelector:@selector(xPathForPartialTag:)]){
return [NSArray array];
}
NSError *outError;
NSString *partialword = [[control stringValue] substringWithRange:charRange];
NSString *xPath = [control xPathForPartialTag:partialword];
return [experiment_controller completionsForXPath:xPath];
}*/
@end