source: releases/Pester/1.1b7/Source/PSSnoozeUntilController.m@ 405

Last change on this file since 405 was 366, checked in by Nicholas Riley, 17 years ago

Info-Pester.plist: Updated for build 23.

NJRHotKey.m: Cosmetic cleanup.

PSAlarm.[hm]: Fix -[PSAlarm time] to work properly, though it no
longer has any clients.

PSSnoozeUntilController.m: Fix snooze until time being off by an hour
as displayed, or if edited, in some time zones.

PSSpeechAlert.m: Display the voice name instead of its identifier in
the description.

Pester.xcodeproj: Misc.

release-notes.html: Updated for build 23.

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