-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUseLibPanelController.j
More file actions
84 lines (74 loc) · 2.63 KB
/
UseLibPanelController.j
File metadata and controls
84 lines (74 loc) · 2.63 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
// (c) 2010-2011 by Anton Korenyushkin
@import "PanelController.j"
@import "Data.j"
@implementation UseLibPanelController : PanelController
{
id target;
SEL action;
@outlet CPTextField authorLabel;
@outlet CPTextField authorField;
@outlet CPTextField nameLabel;
@outlet CPTextField nameField;
@outlet CPTextField versionLabel;
@outlet CPTextField versionField;
@outlet CPTextField aliasLabel;
@outlet CPTextField aliasField;
@outlet CPButton useButton;
}
- (id)initWithTarget:(id)aTarget action:(SEL)anAction // public
{
if (self = [super initWithWindowCibName:"UseLibPanel"]) {
target = aTarget;
action = anAction;
[DATA addObserver:self forKeyPath:"app"];
}
return self;
}
- (void)awakeFromCib // private
{
[authorLabel, nameLabel, versionLabel, aliasLabel].forEach(
function (label) { [label setAlignment:CPRightTextAlignment]; });
[authorField selectAll:nil];
[useButton setEnabled:NO];
[useButton setKeyEquivalent:CPCarriageReturnCharacter];
}
- (void)observeValueForKeyPath:(CPString)keyPath ofObject:(id)object change:(CPDictionary)change context:(id)context // private
{
if (keyPath == "app")
[self close];
}
- (void)controlTextDidChange:(id)sender // private
{
[useButton setEnabled:([authorField stringValue] &&
[nameField stringValue] &&
[versionField stringValue] &&
[aliasField stringValue])];
}
- (void)controlTextDidFocus:(CPNotification)notification // private
{
if ([notification object] === aliasField && ![aliasField stringValue]) {
[aliasField setStringValue:[nameField stringValue]];
[aliasField selectAll:nil];
[self controlTextDidChange:nil];
}
}
- (@action)submit:(id)sender // private
{
objj_msgSend(target, action, [[Lib alloc] initWithName:[aliasField stringValue]
authorName:[authorField stringValue]
appName:[nameField stringValue]
version:[versionField stringValue]]);
}
- (void)didEndErrorSheet:(Alert)sender // public
{
var message = [sender message];
if (message.indexOf("version") != -1)
[[self window] makeFirstResponder:versionField];
else if (message.indexOf("library") != -1)
[[self window] makeFirstResponder:nameField];
else if (message.indexOf("author") != -1)
[[self window] makeFirstResponder:authorField];
else if (message.indexOf("alias") != -1)
[[self window] makeFirstResponder:aliasField];
}
@end