forked from ccjensen/expandrive-nl-plugin
/
ExpanDriveOptionSheetController.m
220 lines (183 loc) · 6.02 KB
/
ExpanDriveOptionSheetController.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
//
// ExpanDriveOptionSheetController.m
// ExpanDriveNLPlugin
//
// Created by Christopher Campbell Jensen on 10/26/10.
//
#import "ExpanDriveOptionSheetController.h"
#import "Constants.h"
#define SingleActionWindowHeight 175
#define MultipleActionExtraHeight 36
@implementation ExpanDriveOptionSheetController
- (void)awakeFromNib
{
expanDrive = [SBApplication applicationWithBundleIdentifier:APPLICATIONBUNDLEIDENTIFIER];
[drivenamesPopupButton removeAllItems];
drives = [[NSArray arrayWithArray:[self retrieveDrives]] retain];
properties = [[self retrieveDiskProperties] retain];
[self populateDriveNamesPopupButton];
[self populateDrivepropertyPopupButton];
//if the sheet is being reopened, we want the current settings entered into the sheet
NSLog(@"ExpanDrivePluginOptionsSheet: loading [options]: %@", [self options]);
if ([[self options] count]) {
[self resetControlsToOptions:[self options]];
}
[self tabView:tabView willSelectTabViewItem:[tabView selectedTabViewItem]];
}
- (void)dealloc
{
[drives release];
[properties release];
[super dealloc];
}
- (void)resetControlsToOptions:(NSDictionary *)selectedOptions
{
//set all action type controls
[singleActionTypeMatrix selectCellWithTag:[[selectedOptions objectForKey:ACTIONKEY] intValue]];
[self actionChanged:singleActionTypeMatrix];
//single sheet controls
[drivenamesPopupButton selectItemWithTitle:[selectedOptions objectForKey:DRIVENAMEKEY]];
//multiple sheet controls
[drivepropertyPopupButton selectItemWithTitle:[selectedOptions objectForKey:DRIVEPROPERTYKEY]];
[drivecontainsTextField setStringValue:[selectedOptions objectForKey:DRIVECONTAINSKEY]];
[tabView selectTabViewItemWithIdentifier:[selectedOptions objectForKey:PERFORMACTIONKEY]];
}
- (IBAction)save:(id)sender
{
NSNumber *selectedTab = (NSNumber *)[[tabView selectedTabViewItem] identifier];
[options setValue:selectedTab forKey:PERFORMACTIONKEY];
[options setValue:[self valueOfActionMatrix] forKey:ACTIONKEY];
//single
[options setValue:[self valueOfDrivenamePopupButton:[selectedTab intValue]] forKey:DRIVENAMEKEY];
//multiple
[options setValue:[self valueOfDrivepropertyPopupButton:[selectedTab intValue]] forKey:DRIVEPROPERTYKEY];
[options setValue:[self valueOfDrivecontainsTextField:[selectedTab intValue]] forKey:DRIVECONTAINSKEY];
//all
//only needs the actionMatrix value
NSLog(@"ExpanDrivePluginOptionsSheet: storing [options]: %@", [self options]);
[self setOptions:[self window]];
}
- (void)updateSubmitState:(NSNumber *)tabIdentifier
{
//check if controls should be activated for current window
BOOL state;
switch ([tabIdentifier intValue]) {
case PERFORMSINGLEACTION: {
state = [drives count] ? YES : NO;
[singleActionTypeMatrix setEnabled:state];
[drivenamesPopupButton setEnabled:state];
} break;
case PERFORMMULTIPLEACTION: {
state = YES;
} break;
case PERFORMALLACTION: {
state = YES;
} break;
}
[saveButton setEnabled:state];
}
#pragma mark -
#pragma mark Set up Controls
- (void)populateDriveNamesPopupButton
{
if ([drives count]) {
for (ScriptBridgeDrive *drive in drives) {
[drivenamesPopupButton addItemWithTitle:[drive drivename]];
}
} else {
[drivenamesPopupButton addItemWithTitle:@"No drives in ExpanDrive"];
}
}
- (void)populateDrivepropertyPopupButton
{
for (NSString *property in properties) {
[drivepropertyPopupButton addItemWithTitle:property];
}
}
- (SBElementArray *)retrieveDrives
{
return [expanDrive drives];
}
- (NSArray *)retrieveDiskProperties
{
return [NSArray arrayWithObjects:@"drivename", @"server", @"url", @"remotePath", nil];
}
#pragma mark -
#pragma mark NSTabViewDelegate Methods
- (void)tabView:(NSTabView *)aTabView willSelectTabViewItem:(NSTabViewItem *)aTabViewItem
{
NSNumber *identifier = (NSNumber *)[aTabViewItem identifier];
[self updateSubmitState:identifier];
}
#pragma mark -
#pragma mark Synchronise controls
// synchronises all actionTypeMatrix's
- (IBAction)actionChanged:(id)sender
{
int tag = 0;
if ([sender isEqual:singleActionTypeMatrix]) {
tag = [[singleActionTypeMatrix selectedCell] tag];
[multipleActionTypeMatrix selectCellWithTag:tag];
[allActionTypeMatrix selectCellWithTag:tag];
} else if ([sender isEqual:multipleActionTypeMatrix]) {
tag = [[multipleActionTypeMatrix selectedCell] tag];
[singleActionTypeMatrix selectCellWithTag:tag];
[allActionTypeMatrix selectCellWithTag:tag];
} else if ([sender isEqual:allActionTypeMatrix]) {
tag = [[allActionTypeMatrix selectedCell] tag];
[singleActionTypeMatrix selectCellWithTag:tag];
[multipleActionTypeMatrix selectCellWithTag:tag];
}
}
#pragma mark -
#pragma mark Get current values of controls
- (NSNumber *)valueOfActionMatrix
{
NSNumber *selectedTab = (NSNumber *)[[tabView selectedTabViewItem] identifier];
int value = 0;
switch ([selectedTab intValue]) {
case PERFORMSINGLEACTION:
value = [[singleActionTypeMatrix selectedCell] tag];
break;
case PERFORMMULTIPLEACTION:
value = [[multipleActionTypeMatrix selectedCell] tag];
break;
case PERFORMALLACTION:
value = [[allActionTypeMatrix selectedCell] tag];
break;
default:
break;
}
return [NSNumber numberWithInt:value];
}
#pragma mark Single Drive Actions
- (NSString *)valueOfDrivenamePopupButton:(int)selectedTabIdentifier
{
NSString *value;
int index = [drivenamesPopupButton indexOfSelectedItem];
//check that an item is selected, -1 indicates none selected
if (index != -1) {
value = [[drivenamesPopupButton itemAtIndex:index] title];
} else {
value = [NSString stringWithString:@""];
}
return value;
}
#pragma mark Multiple Drive Actions
- (NSString *)valueOfDrivecontainsTextField:(int)selectedTabIdentifier
{
return [drivecontainsTextField stringValue];
}
- (NSString *)valueOfDrivepropertyPopupButton:(int)selectedTabIdentifier
{
NSString *value;
int index = [drivepropertyPopupButton indexOfSelectedItem];
//check that an item is selected, -1 indicates none selected
if (index != -1) {
value = [[drivepropertyPopupButton selectedItem] title];
} else {
value = [NSString stringWithString:@""];
}
return value;
}
@end