source: trunk/Cocoa/Pester/Source/PSSnoozeUntilController.m@ 612

Last change on this file since 612 was 600, checked in by Nicholas Riley, 15 years ago

Prototypes to pacify GCC.

File size: 5.5 KB
Line 
1//
2// PSSnoozeUntilController.m
3// Pester
4//
5// Created by Nicholas Riley on Sun Feb 16 2003.
6// Copyright (c) 2003 Nicholas Riley. All rights reserved.
7//
8
9#import "PSAlarmNotifierController.h"
10#import "PSCalendarController.h"
11#import "PSSnoozeUntilController.h"
12#import "PSTimeDateEditor.h"
13#import "NSCalendarDate-NJRExtensions.h"
14
15@interface PSSnoozeUntilController (PSSnoozeUntilControllerRuntime)
16- (void)sheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(PSAlarmNotifierController *)aController;
17@end
18
19@implementation PSSnoozeUntilController
20
21+ (PSSnoozeUntilController *)snoozeUntilControllerWithNotifierController:(PSAlarmNotifierController *)aController;
22{
23 return [[self alloc] initWithNotifierController: aController];
24}
25
26- (id)initWithNotifierController:(PSAlarmNotifierController *)aController;
27{
28 if ([self initWithWindowNibName: @"Snooze until"]) {
29 NSWindow *window = [self window];
30 alarm = [[PSAlarm alloc] init];
31 snoozeInterval = [aController snoozeInterval];
32 [alarm setInterval: snoozeInterval];
33 [PSTimeDateEditor setUpTimeField: timeOfDay dateField: timeDate completions: timeDateCompletions];
34 if ([alarm isValid]) {
35 // [alarm time] works fine for display, but we can't use it overall until we've moved off NSCalendarDate
36 [timeOfDay setObjectValue: [alarm date]];
37 [timeDate setObjectValue: [alarm date]];
38 }
39 [self update: self];
40
41 [NSApp beginSheet: window modalForWindow: [aController window] modalDelegate: self didEndSelector: @selector(sheetDidEnd:returnCode:contextInfo:) contextInfo: aController];
42
43 // work around Cocoa confusion with our bizarre key loop
44 [timeOfDay setNextKeyView: timeDate];
45 }
46 return self;
47}
48
49- (void)dealloc;
50{
51 [alarm release];
52 [super dealloc];
53}
54
55- (void)sheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(PSAlarmNotifierController *)aController;
56{
57 if (returnCode == NSRunAbortedResponse) {
58 [aController setSnoozeInterval: snoozeInterval];
59 [sheet close];
60 } else {
61 [aController snoozeUntilDate: [alarm date]];
62 }
63 // XXX according to Cocoa documentation, the sheet should hide after the didEnd method returns, but it doesn't.
64}
65
66// XXX yuck, should not be duplicating this method between PSAlarmSetController and PSSnoozeUntilController
67// XXX with -[NSControl currentEditor] don't need to compare? Also check -[NSControl validateEditing]
68- (id)objectValueForTextField:(NSTextField *)field whileEditing:(id)sender;
69{
70 if (sender == field) {
71 NSString *stringValue = [[[self window] fieldEditor: NO forObject: field] string];
72 id obj = nil;
73 [[field formatter] getObjectValue: &obj forString: stringValue errorDescription: NULL];
74 // NSLog(@"from field editor: %@", obj);
75 return obj;
76 } else {
77 // NSLog(@"from field: %@", [field objectValue]);
78 return [field objectValue];
79 }
80}
81
82#pragma mark date setting
83
84- (void)setAlarmDateAndInterval:(id)sender;
85{
86 [alarm setForDate: [self objectValueForTextField: timeDate whileEditing: sender]
87 atTime: [self objectValueForTextField: timeOfDay whileEditing: sender]];
88}
89
90// Be careful not to hook up any of the text fields' actions to update: because we handle them in controlTextDidChange: instead. If we could get the active text field somehow via public API (guess we could use controlTextDidBegin/controlTextDidEndEditing) then we'd not need to overload the update sender for this purpose. Or, I guess, we could use another method other than update. It should not be this hard to implement what is essentially standard behavior. Sigh.
91// Note: finding out whether a given control is editing is easier. See: <http://cocoa.mamasam.com/COCOADEV/2002/03/2/28501.php>.
92
93- (IBAction)update:(id)sender;
94{
95 BOOL isValid;
96 [self setAlarmDateAndInterval: sender];
97 isValid = [alarm isValid];
98 [snoozeButton setEnabled: isValid];
99 if (!isValid) {
100 [messageField setStringValue: [alarm invalidMessage]];
101 } else {
102 [messageField setStringValue: @""];
103 }
104}
105
106- (IBAction)dateCompleted:(NSPopUpButton *)sender;
107{
108 [timeDate setStringValue: [sender titleOfSelectedItem]];
109 [self update: sender];
110}
111
112#pragma mark calendar
113
114- (IBAction)showCalendar:(NSButton *)sender;
115{
116 [PSCalendarController controllerWithDate: [NSCalendarDate dateForDay: [timeDate objectValue]] delegate: self];
117}
118
119- (void)calendarController:(PSCalendarController *)calendar didSetDate:(NSCalendarDate *)date;
120{
121 [timeDate setObjectValue: date];
122 [self update: self];
123}
124
125- (NSView *)calendarControllerLaunchingView:(PSCalendarController *)controller;
126{
127 return timeCalendarButton;
128}
129
130#pragma mark actions
131
132- (IBAction)close:(id)sender;
133{
134 [NSApp endSheet: [self window] returnCode: NSRunAbortedResponse];
135}
136
137- (IBAction)snooze:(NSButton *)sender;
138{
139 if ([alarm isValid]) {
140 [NSApp endSheet: [self window] returnCode: NSRunStoppedResponse];
141 } else {
142 [messageField setStringValue: [@"Unable to snooze. " stringByAppendingString: [alarm invalidMessage]]];
143 [sender setEnabled: NO];
144 }
145}
146
147@end
148
149@implementation PSSnoozeUntilController (NSControlSubclassNotifications)
150
151// called because we're the delegate
152
153- (void)controlTextDidChange:(NSNotification *)notification;
154{
155 [self update: [notification object]];
156}
157
158@end
159
160@implementation PSSnoozeUntilController (NSWindowNotifications)
161
162- (void)windowWillClose:(NSNotification *)notification;
163{
164 [self autorelease];
165}
166
167@end
Note: See TracBrowser for help on using the repository browser.