-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAlert.j
More file actions
100 lines (87 loc) · 2.95 KB
/
Alert.j
File metadata and controls
100 lines (87 loc) · 2.95 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
// (c) 2010-2011 by Anton Korenyushkin
var createLabel = function (text, y, font) {
var label = [[CPTextField alloc] initWithFrame:CGRectMake(80, y, 190, [text realSizeWithFont:font inWidth:190].height)];
[label setFont:font];
[label setLineBreakMode:CPLineBreakByWordWrapping];
[label setStringValue:text];
return label;
};
@implementation Alert : CPObject
{
CPString message @accessors;
CPString comment @accessors;
id target @accessors;
SEL action @accessors;
CPPanel panel;
}
- (void)initWithMessage:(CPString)aMessage comment:(CPString)aComment target:(id)aTarget action:(SEL)anAction // public
{
if (self = [super init]) {
message = aMessage;
comment = aComment;
target = aTarget;
action = anAction;
}
return self;
}
- (id)initWithMessage:(CPString)aMessage comment:(CPString)aComment // public
{
return [self initWithMessage:aMessage comment:aComment target:nil action:nil];
}
- (id)initWithMessage:(CPString)aMessage // public
{
return [self initWithMessage:aMessage comment:nil target:nil action:nil];
}
- (void)showPanel // public
{
[self createPanelWithStyleMask:CPTitledWindowMask];
[CPApp runModalForWindow:panel];
}
- (void)showSheetForWindow:(CPWindow)window // public
{
[self createPanelWithStyleMask:CPDocModalWindowMask];
[CPApp beginSheet:panel modalForWindow:window modalDelegate:nil didEndSelector:nil contextInfo:nil];
}
- (void)createPanelWithStyleMask:(unsigned)styleMask // protected
{
var messageLabel = createLabel(message, 16, BoldSystemFont);
var commentLabel;
if (comment)
commentLabel = createLabel(comment, CGRectGetMaxY([messageLabel frame]) + 8, SystemFont);
var okButtonY = MAX(CGRectGetMaxY([commentLabel || messageLabel frame]), 64) + 16;
var okButton = [[CPButton alloc] initWithFrame:CGRectMake(206, okButtonY, 60, 24)];
[okButton setTitle:"OK"];
[okButton setTarget:self];
[okButton setAction:@selector(confirm)];
[okButton setKeyEquivalent:CPCarriageReturnCharacter];
panel = [[CPPanel alloc] initWithContentRect:CGRectMake(0, 0, 286, okButtonY + 24 + 20) styleMask:styleMask];
var contentView = [panel contentView];
var imageView = [[CPImageView alloc] initWithFrame:CGRectMake(16, 16, 48, 48)];
[imageView setImage:[[CPImage alloc] initWithContentsOfFile:[[CPBundle mainBundle] pathForResource:[self imagePath]]]];
[contentView addSubview:imageView];
[contentView addSubview:messageLabel];
if (commentLabel)
[contentView addSubview:commentLabel];
[contentView addSubview:okButton];
[panel setDelegate:self];
}
- (CPString)imagePath // protected
{
return "Error48.png";
}
- (void)confirm // protected
{
[panel dismiss];
}
- (void)windowWillClose:(id)sender // private
{
if (![panel isSheet])
[CPApp stopModal];
if ([self shouldSendAction])
objj_msgSend(target, action, self);
}
- (BOOL)shouldSendAction // protected
{
return YES;
}
@end