-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGitController.j
47 lines (39 loc) · 1.74 KB
/
GitController.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
// (c) 2010-2011 by Anton Korenyushkin
@import "BaseConsoleController.j"
@import "HTTPRequest.j"
var CommandsChangingWorkTree = ['checkout', 'clean', 'merge', 'mv', 'pull', 'rebase', 'reset', 'revert', 'rm', 'stash'];
@implementation GitController : BaseConsoleController
- (id)initWithApp:(App)anApp buffer:(Buffer)aBuffer // public
{
return [super initWithApp:anApp
buffer:aBuffer
infoBoxWidth:240
message:"Run Git commands."
comment:"Type \"help\" to get started."
inputButtonTitle:"Run"];
}
- (void)handleInput:(CPString)input // protected
{
var request = [[HTTPRequest alloc] initWithMethod:"POST"
URL:[app URL] + "git"
target:self
action:@selector(didReceiveResponse:withContext:)];
[request setErrorAction:@selector(didReceiveError:withContext:)];
[request setContext:{
questionNumber: [outputView addQuestion:input],
shouldReloadCode: CommandsChangingWorkTree.indexOf(input.trimLeft().split(' ', 1)[0]) != -1
}];
[request send:{command: input}];
}
- (void)didReceiveResponse:(CPString)data withContext:(JSObject)context // private
{
[outputView setAnswer:data negative:NO forQuestionNumber:context.questionNumber];
if (context.shouldReloadCode)
[app.navigatorController reloadCode];
}
- (BOOL)didReceiveError:(CPString)data withContext:(JSObject)context // private
{
[outputView setAnswer:data.message + "\n\n" + data.comment negative:YES forQuestionNumber:context.questionNumber];
return YES;
}
@end