-
Notifications
You must be signed in to change notification settings - Fork 1
/
ETDocumentEditorController.m
163 lines (133 loc) · 4.27 KB
/
ETDocumentEditorController.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
/*
Copyright (C) 2013 Quentin Mathe
Author: Quentin Mathe <[email protected]>
Date: December 2013
License: Modified BSD (see COPYING)
*/
#import "ETDocumentEditorController.h"
#import "ETWorktableController.h"
#import "ETDocumentEditorConstants.h"
#import "ETDocumentEditorItemFactory.h"
@implementation ETDocumentEditorController
@synthesize documentItem = _documentItem, inspectorItem = _inspectorItem;
- (void) dealloc
{
DESTROY(_documentItem);
DESTROY(_inspectorItem);
[super dealloc];
}
#pragma mark - Accessing UI Objects
- (void) setDocumentItem: (ETLayoutItemGroup *)anItem
{
[self stopObserveObject: anItem forNotificationName: ETItemGroupSelectionDidChangeNotification];
ASSIGN(_documentItem, anItem);
[self setInitialFocusedItem: anItem];
[self startObserveObject: anItem
forNotificationName: ETItemGroupSelectionDidChangeNotification
selector: @selector(documentItemSelectionDidChange:)];
ASSIGN(_inspectorItem,
[[ETDocumentEditorItemFactory factory] inspectorWithObject: _documentItem
controller: self]);
}
- (ETLayoutItemGroup *) topBarItem
{
return (id)[[self content] itemForIdentifier: @"editorTopBar"];
}
#pragma mark - Notifications
/** The selection inside the document has changed. */
- (void) documentItemSelectionDidChange: (NSNotification *)notif
{
// TODO: [self updateInspector];
}
#pragma mark - User Interface Item Validation
- (NSSet *) validatableItems
{
return [NSSet setWithArray: [[self topBarItem] items]];
}
- (BOOL) validateItem: (ETLayoutItem *)anItem
{
return [self validateUserInterfaceItem: (id)anItem];
}
- (BOOL) validateUserInterfaceItem: (id <NSValidatedUserInterfaceItem>)anItem
{
/*if (sel_isEqual([anItem action], @selector(addNewObject:)))
{
if ([self isSingleSelectionInSourceList])
{
return ([self currentObjectType] != nil);
}
return NO;
}
else if (sel_isEqual([anItem action], @selector(delete:))
|| sel_isEqual([anItem action], @selector(duplicate:)))
{
return ([self isSingleSelectionInSourceList] && [self hasSelectionInContentView]);
}
else if (sel_isEqual([anItem action], @selector(open:))
|| sel_isEqual([anItem action], @selector(markVersion:))
|| sel_isEqual([anItem action], @selector(revertTo:))
|| sel_isEqual([anItem action], @selector(browseHistory:))
|| sel_isEqual([anItem action], @selector(import:))
|| sel_isEqual([anItem action], @selector(export:)))
{
return [self hasSelectionInContentView];
}*/
return YES;
}
#pragma mark - History Actions
- (IBAction) markVersion: (id)sender
{
// TODO: Implement
[self doesNotRecognizeSelector: _cmd];
}
- (IBAction) revertTo: (id)sender
{
// TODO: Implement
[self doesNotRecognizeSelector: _cmd];
}
// TODO: Remove duplication accross EtoileUI applications
- (IBAction) browseHistory: (id)sender
{
if ([[self documentItem] isPersistent] == NO)
return;
id <COTrack> track = [[[self documentItem] objectGraphContext] branch];
ETLayoutItemGroup *browser =
[[ETLayoutItemFactory factory] historyBrowserWithRepresentedObject: track
title: nil];
[[[ETLayoutItemFactory factory] windowGroup] addItem: browser];
}
#pragma mark - Other Object Actions
- (IBAction) search: (id)sender
{
NSString *searchString = [sender stringValue];
ETLog(@"Search %@ with %@", [searchString description], [[[self documentItem] controller] description]);
if ([searchString isEqual: @""])
{
[[[self documentItem] controller] setFilterPredicate: nil];
}
else
{
// TODO: Improve (Full-text, SQL, more properties, Object Matching integration)
NSString *queryString =
@"(name CONTAINS %@) OR (typeDescription CONTAINS %@) OR (tagDescription CONTAINS %@)";
NSPredicate *predicate = [NSPredicate predicateWithFormat: queryString
argumentArray: A(searchString, searchString, searchString)];
[[[self documentItem] controller] setFilterPredicate: predicate];
}
}
- (IBAction) share: (id)sender
{
// TODO: Implement
[self doesNotRecognizeSelector: _cmd];
}
- (IBAction) import: (id)sender
{
// TODO: Implement
[self doesNotRecognizeSelector: _cmd];
}
- (IBAction) export: (id)sender
{
// TODO: Implement
[self doesNotRecognizeSelector: _cmd];
}
@end