-
Notifications
You must be signed in to change notification settings - Fork 1
/
TWEditorController.m
235 lines (186 loc) · 5.71 KB
/
TWEditorController.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
/*
Copyright (C) 2013 Quentin Mathe
Author: Quentin Mathe <[email protected]>
Date: April 2013
License: Modified BSD (see COPYING)
*/
#import "TWEditorController.h"
#import "TWAppController.h"
#import "TWLayoutItemFactory.h"
@implementation TWEditorController
@synthesize contentViewItem, sourceListItem, viewPopUpItem;
- (id) init
{
SUPERINIT;
[self setCurrentObjectType: nil];
return self;
}
- (void) dealloc
{
DESTROY(contentViewItem);
DESTROY(sourceListItem);
DESTROY(viewPopUpItem);
DESTROY(statusLabelItem);
[super dealloc];
}
- (NSArray *) trackedItemPropertyNames
{
return A(@"contentViewItem", @"viewPopUpItem");
//return A(@"contentViewItem", @"sourceListItem", @"viewPopUpItem", @"statusLabelItem");
}
- (COEditingContext *)editingContext
{
if ([[self persistentObjectContext] respondsToSelector: @selector(parentContext)])
{
return [(COPersistentRoot *)[self persistentObjectContext] parentContext];
}
return (COEditingContext *)[self persistentObjectContext];
}
- (ETLayoutItemGroup *) bodyItem
{
return [[self sourceListItem] parentItem];
}
- (ETLayoutItemGroup *) inspectorItem
{
return (ETLayoutItemGroup *)[[self bodyItem] itemForIdentifier: @"inspector"];
}
#pragma mark -
#pragma mark Selection
- (id) selectedObjectInContentView
{
id selectedObject = [[[[self contentViewItem] selectedItemsInLayout] firstObject] representedObject];
if (selectedObject == nil)
{
selectedObject = [[self contentViewItem] representedObject];
}
return selectedObject;
}
- (NSArray *) selectedObjectsInSourceList
{
return [[[[self sourceListItem] selectedItemsInLayout] mappedCollection] representedObject];
}
#pragma mark -
#pragma mark Notifications
- (void) sourceListSelectionDidChange: (NSNotification *)aNotif
{
}
#pragma mark -
#pragma mark Presentation
- (BOOL) isInspectorHidden
{
return ([self inspectorItem] == nil);
}
- (void) showInspector
{
NSSize size = NSMakeSize([[TWLayoutItemFactory factory] defaultInspectorWidth], [[self bodyItem] height]);
ETLayoutItemGroup *inspectorItem =
[[TWLayoutItemFactory factory] inspectorWithObject: [self selectedObjectInContentView]
size: size
controller: self];
[[self contentViewWrapperItem] setWidth: [[self contentViewWrapperItem] width] - [inspectorItem width]];
[[self bodyItem] addItem: inspectorItem];
}
- (void) hideInspector
{
ETAssert([[self bodyItem] containsItem: [self inspectorItem]]);
[[self bodyItem] removeItem: [self inspectorItem]];
}
#pragma mark -
#pragma mark Object Insertion and Deletion Actions
- (IBAction) add: (id)sender
{
[[contentViewItem controller] add: sender];
}
- (IBAction) insert: (id)sender
{
[[contentViewItem controller] insert: sender];
}
- (IBAction) remove: (id)sender
{
[[contentViewItem controller] remove: sender];
}
#pragma mark -
#pragma mark Presentation Actions
- (void) changePresentationViewToMenuItem: (NSMenuItem *)aMenuItem
{
ETLayout *templateLayout = [aMenuItem representedObject];
[contentViewItem setLayout: AUTORELEASE([templateLayout copy])];
[[contentViewItem layout] setDelegate: [contentViewItem controller]];
}
- (NSString *) currentPresentationTitle
{
return [[[[ETApp layoutItem] controller] ifResponds] currentPresentationTitle];
}
- (void) setCurrentPresentationTitle: (NSString *)aTitle
{
[[[[ETApp layoutItem] controller] ifResponds] setCurrentPresentationTitle: aTitle];
}
- (void) updateForNewSelectedItemTitle: (NSString *)newTitle
oldTitle: (NSString *)oldTitle
inMenu: (NSMenu *)aMenu
{
BOOL hasExpectedAppController = ([self currentPresentationTitle] != nil);
if (hasExpectedAppController == NO)
return;
[[aMenu itemWithTitle: oldTitle] setState: NSOffState];
[[aMenu itemWithTitle: newTitle] setState: NSOnState];
}
- (IBAction) changePresentationViewFromPopUp: (id)sender
{
ETAssert(viewPopUpItem != nil);
[self changePresentationViewToMenuItem: [[viewPopUpItem view] selectedItem]];
NSString *newSelectedTitle = [[[viewPopUpItem view] selectedItem] title];
[self updateForNewSelectedItemTitle: newSelectedTitle
oldTitle: [self currentPresentationTitle]
inMenu: [[ETApp viewMenuItem] submenu]];
[self setCurrentPresentationTitle: newSelectedTitle];
}
- (IBAction) changePresentationViewFromMenuItem: (id)sender
{
[self updateForNewSelectedItemTitle: [sender title]
oldTitle: [self currentPresentationTitle]
inMenu: [sender menu]];
[self changePresentationViewToMenuItem: sender];
[self setCurrentPresentationTitle: [sender title]];
[(NSPopUpButton *)[viewPopUpItem view] selectItemWithTitle: [self currentPresentationTitle]];
}
- (IBAction) changeInspectorViewFromMenuItem: (id)sender
{
// TODO: Implement
[self doesNotRecognizeSelector: _cmd];
}
- (IBAction) toggleInspector: (id)sender
{
BOOL isInspectorHidden = ([self inspectorItem] == nil);
if (isInspectorHidden)
{
[self showInspector];
}
else
{
[self hideInspector];
}
}
#pragma mark -
#pragma mark Other Object Actions
- (IBAction) search: (id)sender
{
// TODO: Implement
[self doesNotRecognizeSelector: _cmd];
}
- (IBAction) open: (id)sender
{
// TODO: Implement
[self doesNotRecognizeSelector: _cmd];
}
- (IBAction) browseHistory: (id)sender
{
if ([[self selectedObjectInContentView] isPersistent] == NO)
return;
COTrack *track = [[self selectedObjectInContentView] commitTrack];
ETLayoutItemGroup *browser =
[[ETLayoutItemFactory factory] historyBrowserWithRepresentedObject: track
title: nil];
[[[ETLayoutItemFactory factory] windowGroup] addItem: browser];
}
@end