-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBCAuthorDialogController.m
More file actions
281 lines (171 loc) · 6.69 KB
/
Copy pathBCAuthorDialogController.m
File metadata and controls
281 lines (171 loc) · 6.69 KB
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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
//
// BCAuthorDialogController.m
// Caravan
//
// Created by Tom Houpt on 15/3/16.
// Copyright (c) 2015 Tom Houpt. All rights reserved.
//
#import "BCAuthorDialogController.h"
#import "BCAuthor.h"
@interface BCAuthorDialogController (Private)
-(void)populateDialog;
-(void)retrieveFromDialog;
-(IBAction)okPressed:(id)sender;
-(IBAction)cancelPressed:(id)sender;
-(IBAction)optionFieldsPressed:(id)sender;
-(void)collapseOptions;
-(void)expandOptions;
@end
@implementation BCAuthorDialogController
-(id)initWithAuthor:(BCAuthor *)a; {
self = [super init];
if (self) {
_theAuthor = a;
if (!_dialog) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
[NSBundle loadNibNamed:@"VerticalAuthorDialog" owner:self];
#pragma clang diagnostic pop
_firstRun = YES;
}
}
return self;
}
-(void)populateDialog; {
[_indexName setStringValue:_theAuthor.indexName];
[_initials setStringValue:_theAuthor.initials];
[_orcid setStringValue:_theAuthor.orcid];
[_contribution setStringValue:_theAuthor.contribution];
[_position setStringValue:_theAuthor.position];
[_prefix setStringValue:_theAuthor.prefix];
[_fullName setStringValue:_theAuthor.fullName];
[_degrees setStringValue:_theAuthor.degrees];
[_informal setStringValue:_theAuthor.informal];
[_affiliation setStringValue:_theAuthor.affiliation];
[_address setStringValue:_theAuthor.address];
[_phone setStringValue:_theAuthor.phone];
[_fax setStringValue:_theAuthor.fax];
[_email setStringValue:_theAuthor.email];
[_website setStringValue:_theAuthor.website];
[self setupRecentAffiliations];
}
-(void)retrieveFromDialog; {
_theAuthor.indexName = [_indexName stringValue];
_theAuthor.initials = [_initials stringValue];
_theAuthor.orcid = [_orcid stringValue];
_theAuthor.contribution = [_contribution stringValue];
_theAuthor.position = [_position stringValue];
_theAuthor.prefix = [_prefix stringValue];
_theAuthor.fullName = [_fullName stringValue];
_theAuthor.degrees = [_degrees stringValue];
_theAuthor.informal = [_informal stringValue];
_theAuthor.affiliation = [_affiliation stringValue];
_theAuthor.address = [_address stringValue];
_theAuthor.phone = [_phone stringValue];
_theAuthor.fax = [_fax stringValue];
_theAuthor.email = [_email stringValue];
_theAuthor.website = [_website stringValue];
[self addAffiliationToRecentAffiliations];
}
-(BOOL)dialogForWindow:(NSWindow *)ownerWindow; {
[self populateDialog];
if ( _firstRun && [[ NSUserDefaults standardUserDefaults] boolForKey:kAuthorOptionFieldsAreExpandedKey]) {
[self expandOptions];
_firstRun = NO;
}
[NSApp beginSheet: _dialog
modalForWindow: ownerWindow
modalDelegate: nil
didEndSelector: nil
contextInfo: nil];
[NSApp runModalForWindow: _dialog];
// See NSApplication Class Reference/runModalSession
[NSApp endSheet: _dialog];
[_dialog orderOut: self];
return _returnFlag;
}
-(IBAction)cancelPressed:(id)sender; {
[NSApp stopModal];
// return canceled
self.returnFlag = NO;
}
-(IBAction)okPressed:(id)sender; {
[NSApp stopModal];
// return OK
[self retrieveFromDialog];
self.returnFlag = YES;
}
// User Defaults
#define USERDEFAULT(x) ([[NSUserDefaults standardUserDefaults] objectForKey:(x)])
#define SETUSERDEFAULT(obj,key) ([[NSUserDefaults standardUserDefaults] setObject:(obj) forKey:(key)])
-(void)setupRecentAffiliations; {
_affilArray = [NSMutableArray arrayWithArray:USERDEFAULT(kAuthorRecentAffiliationsKey)];
for (NSString *a in _affilArray) {
NSString *spaced_affliation = [a stringByReplacingOccurrencesOfString:@"," withString:@", "];
[_recentAffiliations addItemWithTitle:spaced_affliation];
}
}
-(void)addAffiliationToRecentAffiliations; {
if ([ _theAuthor.affiliation length] == 0) {
return;
}
BOOL alreadyInArray = NO;
for (NSString *a in _affilArray) {
if ( [a isEqualToString:_theAuthor.affiliation]) {
alreadyInArray = YES;
}
}
if (!alreadyInArray) {
if ([_affilArray count] >= kMaxNumberOfRecentAffiliations) {
[_affilArray removeObjectAtIndex:0];
}
[_affilArray addObject:_theAuthor.affiliation];
SETUSERDEFAULT(_affilArray,kAuthorRecentAffiliationsKey);
}
}
-(IBAction)recentAffifiationSelected:(id)sender; {
[_affiliation setStringValue: [[_recentAffiliations selectedItem] title]];
}
-(IBAction)optionFieldsPressed:(id)sender; {
if ( [[ NSUserDefaults standardUserDefaults] boolForKey:kAuthorOptionFieldsAreExpandedKey]) {
[self collapseOptions];
}
else {
[self expandOptions];
}
}
-(void)collapseOptions; {
[_optionsView removeFromSuperview];
// resize the dialog
NSRect newFrame = _dialog.frame;
newFrame.origin.y += _optionsView.frame.size.height;
newFrame.size.height -= _optionsView.bounds.size.height;
[_dialog setFrame:newFrame display:YES animate:YES];
newFrame = _optionsView.frame;
newFrame.origin.y -= 48;
[_optionsView setFrame:newFrame];
[_dialog setMinSize:_dialog.frame.size];
[_dialog setMaxSize:_dialog.frame.size];
[_optionFieldsButton setState:NSOffState];
[_optionFieldsLabelButton setTitle:@"Show Additional Fields"];
[[ NSUserDefaults standardUserDefaults] setBool: NO forKey:kAuthorOptionFieldsAreExpandedKey];
}
-(void)expandOptions; {
// enlarge the dialog
// make sure the top left of window doesn't move
NSRect newFrame = _dialog.frame;
newFrame.origin.y -= _optionsView.frame.size.height;
newFrame.size.height += _optionsView.frame.size.height;
[_dialog setFrame:newFrame display:YES animate:YES];
newFrame = _optionsView.frame;
newFrame.origin.y += 48;
[_optionsView setFrame:newFrame];
[_dialog setMinSize:_dialog.frame.size];
[_dialog setMaxSize:_dialog.frame.size];
// Add the details view, containing the release notes webview and the showReleaseNotes checkbox
[[_dialog contentView] addSubview:_optionsView];
[_optionFieldsButton setState:NSOnState];
[_optionFieldsLabelButton setTitle:@"Hide Additional Fields"];
[[ NSUserDefaults standardUserDefaults] setBool: YES forKey:kAuthorOptionFieldsAreExpandedKey];
}
@end