-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathloadCrontabController.m
executable file
·149 lines (115 loc) · 3.12 KB
/
loadCrontabController.m
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#import "loadCrontabController.h"
NSString *locUserSelectedNotification = @"UserSelected";
@implementation loadCrontabController
static loadCrontabController *sharedInstance = nil;
// class methods
+ (loadCrontabController *)sharedInstance {
return sharedInstance ? sharedInstance : [[self alloc] init];
}
//
- (id)init {
if (sharedInstance) {
[self dealloc];
} else {
//NSLog( @"init" );
[super init];
sharedInstance = self;
}
return sharedInstance;
}
- (void)dealloc {
[ [ self window ] close ];
if ( username ) [ username release ];
[ super dealloc ];
}
- (NSPanel *)window {
return window;
}
- (NSString *)username {
return username;
}
- (int)returnCode {
return returnCode;
}
-(void)hideWindow {
// "window" is an NSPanel, so closing does not dispose
//NSLog( @"hide" );
[ NSApp stopModal ];
[ window close ];
}
- (void)showModalDialog {
//NSLog( @"show" );
if ( ! window ) {
if (![NSBundle loadNibNamed:@"LoadCrontabWindow" owner:self]) {
NSLog(@"Failed to load LoadCrontabWindow.nib");
NSBeep();
return;
}
[ window setMenu:nil];
}
[ NSApp runModalForWindow: [ self window ] ];
}
- (void)beginSheetForWindow: (NSWindow *)parent {
if ( ! window ) {
if (![NSBundle loadNibNamed:@"LoadCrontabWindow" owner:self]) {
NSLog(@"Failed to load LoadCrontabWindow.nib");
NSBeep();
return;
}
[ window setMenu:nil];
}
[ NSApp beginSheet: window modalForWindow: parent modalDelegate: self
didEndSelector: @selector(sheetDidEnd:returnCode:contextInfo:) contextInfo: nil ];
}
- (void)sheetDidEnd:(NSWindow *)sheet returnCode:(int)code contextInfo:(void *)contextInfo {
//NSLog( @"in here, code: %i", code );
[ username release ];
returnCode = code;
switch ( code ) {
case 0: // cancel
username = nil;
break;
case 1: // load
username = [ [ NSString alloc ] initWithString: [ edUser stringValue ] ];
break;
case 2: // default
username = nil;
break;
}
[sheet orderOut:nil];
[ [ NSNotificationCenter defaultCenter ] postNotificationName: locUserSelectedNotification object: self ];
}
// control actions
- (IBAction)cancelPressed:(id)sender {
/*
username = nil;
[ self hideWindow ];
returnCode = 0;
*/
username = nil;
[ NSApp endSheet: [ self window ] returnCode: 0 ];
}
- (IBAction)loadPressed:(id)sender {
/*
if ( username ) [ username release ];
username = [ [ NSString alloc ] initWithString: [ edUser stringValue ] ];
[ self hideWindow ];
returnCode = 1;
*/
[ NSApp endSheet: [ self window ] returnCode: 1 ];
}
- (IBAction)defaultPressed:(id)sender {
/*
username = nil;
[ self hideWindow ];
returnCode = 2;
*/
username = nil;
[ NSApp endSheet: [ self window ] returnCode: 2 ];
}
// delegates
// text field
- (void)controlTextDidChange:(NSNotification *)aNotification {
[ btLoad setEnabled: ! [ [ edUser stringValue ] isEqualToString: @"" ] ];
}
@end