-
Notifications
You must be signed in to change notification settings - Fork 5
/
ISNewIssueWindowController.j
96 lines (76 loc) · 2.44 KB
/
ISNewIssueWindowController.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
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
@implementation ISNewIssueWindowController : CPWindowController
{
CPArray repoTitles;
}
- (void)showWindow:(id)sender
{
[super showWindow:sender];
if (![sender isKindOfClass:[CPButton class]])
return;
var pt = [sender bounds],
pt = [sender convertRect:pt toView:nil],
origin = CGPointMake(CGRectGetMidX(pt), CGRectGetMidY(pt) + 3),
win = [self window];
// offset for the spiky thing
origin.x -= 52;
[win setFrameOrigin:origin];
[win setAnimationLocation:"15% 0%"];
[win setAnimationLength:"170"];
[win orderFontWithAnimation:sender];
[win makeKeyWindow];
// this has to be done here because the window posts the didMove
// notification when we change the origin point.
[win setDelegate:win];
[sender bind:"enabled" toObject:win withKeyPath:"isDetached" options:nil];
}
- (void)setRepos:(CPArray)theRepos
{
repoTitles = theRepos;
}
- (void)selectRepo:(ISRepository)aRepo
{
[[[self window] repoField] selectItemWithTitle:[aRepo identifier]];
}
- (void)loadWindow
{
[super loadWindow];
[[self window] setRepos:repoTitles];
}
- (void)controlTextDidChange:(CPNotification)aNote
{
var win = [self window],
enable = NO;
// FIX ME: Char count this < 50 should return NO.
if ([[win titleField] stringValue] && [[win bodyField] stringValue])
enable = YES;
[[win saveButton] setEnabled:enable];
}
- (@action)cancel:(id)sender
{
[[self window] cancel:sender];
}
- (@action)addIssue:(id)sender
{
// create a temparary issue object.
var win = [self window],
issue = [CPDictionary dictionaryWithObjects:[[[win titleField] stringValue], [[win bodyField] stringValue], [[win repoField] titleOfSelectedItem]] forKeys:["title", "body", "repo"]];
[[ISGithubAPIController sharedController] createIssue:issue withCallback:function(newIssue, aRequest){
if (!aRequest.success() && JSON.parse(aRequest.responseText()).message)
{
alert("make this a CPAlert I guess");
}
}];
}
- (@action)preview:(id)sender
{
}
- (@action)openInNewPlatformWindow:(id)sender
{
if (![CPPlatform isBrowser] || ![CPPlatformWindow supportsMultipleInstances])
return;
var platformWindow = [[CPPlatformWindow alloc] initWithContentRect:CGRectMake(100, 100, 545, 350)];
[platformWindow orderFront:self];
[[self window] setPlatformWindow:platformWindow];
[[self window] setFullBridge:YES];
}
@end