-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGoToLinePanelController.j
49 lines (41 loc) · 1.2 KB
/
GoToLinePanelController.j
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
// (c) 2010-2011 by Anton Korenyushkin
@import "PanelController.j"
@implementation GoToLinePanelController : PanelController
{
@outlet CPTextField lineField;
@outlet CPButton goButton;
id target;
SEL action;
}
- (id)initWithTarget:(id)aTarget action:(SEL)anAction // public
{
if (self = [super initWithWindowCibName:"GoToLinePanel"]) {
target = aTarget;
action = anAction;
[DATA addObserver:self forKeyPath:"app.buffer"];
}
return self;
}
- (void)awakeFromCib // private
{
[goButton setEnabled:NO];
[goButton setKeyEquivalent:CPCarriageReturnCharacter];
}
- (void)observeValueForKeyPath:(CPString)keyPath ofObject:(id)object change:(CPDictionary)change context:(id)context // protected
{
if (keyPath == "app.buffer")
[self close];
else
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
}
- (void)controlTextDidChange:(id)sender // private
{
var lineNumber = +[lineField stringValue];
[goButton setEnabled:!isNaN(lineNumber) && lineNumber >= 0 && lineNumber % 1 == 0];
}
- (@action)submit:(id)sender // private
{
objj_msgSend(target, action, +[lineField stringValue]);
[self close];
}
@end