Changeset 53 for trunk/Cocoa/Pester/Source/PSAlarmNotifierController.m
- Timestamp:
- 01/02/03 05:30:03 (21 years ago)
- Location:
- trunk/Cocoa/Pester/Source
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Cocoa/Pester/Source
- Property svn:ignore
-
old new 1 1 build 2 .gdb_history
-
- Property svn:ignore
-
trunk/Cocoa/Pester/Source/PSAlarmNotifierController.m
r43 r53 10 10 #import "PSAlarmAlertController.h" 11 11 #import "PSAlarm.h" 12 #import "PSNotifierAlert.h" 13 #import "NJRIntervalField.h" 14 15 static NSString * const PSAlarmSnoozeInterval = @"Pester alarm snooze interval"; // NSUserDefaults key 16 17 @interface PSAlarmNotifierController (Private) 18 19 - (void)update:(id)sender; 20 - (void)updateNextDateDisplay:(id)sender; 21 22 @end 12 23 13 24 @implementation PSAlarmNotifierController … … 15 26 // XXX should use NSNonactivatingPanelMask on 10.2 16 27 17 - (id)initWithAlarm:(PSAlarm *)a larm;28 - (id)initWithAlarm:(PSAlarm *)anAlarm; 18 29 { 19 30 if ([self initWithWindowNibName: @"Notifier"]) { 20 [[self window] center]; 31 NSWindow *window = [self window]; 32 NSRect frameRect = [window frame]; 33 alarm = [anAlarm retain]; 21 34 [messageField setStringValue: [alarm message]]; 22 [dateField setStringValue: 23 [NSString stringWithFormat: @"%@ at %@", [alarm dateString], [alarm timeString]]]; 24 [[self window] makeKeyAndOrderFront: nil]; 25 [[self window] orderFrontRegardless]; 35 [dateField setStringValue: [alarm dateTimeString]]; 36 if (![snoozeIntervalField setInterval: [alarm snoozeInterval]] && 37 ![snoozeIntervalField setInterval: [[[NSUserDefaults standardUserDefaults] objectForKey: PSAlarmSnoozeInterval] doubleValue]]) 38 [snoozeIntervalField setInterval: 15 * 60]; // 15 minutes 39 if ([alarm isRepeating]) { 40 [intervalField setStringValue: 41 [NSString stringWithFormat: @"every %@", [[alarm intervalString] lowercaseString]]]; 42 [self updateNextDateDisplay: nil]; 43 updateTimer = [NSTimer scheduledTimerWithTimeInterval: 1 target: self selector: @selector(updateNextDateDisplay:) userInfo: nil repeats: YES]; 44 frameRect.size = [window maxSize]; 45 } else { 46 frameRect.size = [window minSize]; 47 } 48 [window setFrame: frameRect display: NO]; 49 [window center]; 50 [window makeKeyAndOrderFront: nil]; 51 [window orderFrontRegardless]; 26 52 } 27 53 return self; 54 } 55 56 - (void)dealloc; 57 { 58 [alarm release]; 59 [updateTimer invalidate]; updateTimer = nil; 60 [super dealloc]; 61 } 62 63 - (void)updateNextDateDisplay:(id)sender; 64 { 65 if (!canSnooze) { 66 NSString *nextDateTimeString = [alarm nextDateTimeString]; 67 if (nextDateTimeString == nil) { // no longer repeating 68 [updateTimer invalidate]; updateTimer = nil; 69 } else { 70 [nextDateField setStringValue: nextDateTimeString]; 71 } 72 } 73 } 74 75 - (void)update:(id)sender; 76 { 77 canSnooze = [snoozeIntervalField interval] != 0; 78 if (canSnooze) [nextDateField setStringValue: @"after snooze"]; 79 [snoozeButton setEnabled: canSnooze]; 80 [canSnooze ? snoozeButton : okButton setKeyEquivalent: @"\r"]; 81 [canSnooze ? okButton : snoozeButton setKeyEquivalent: @""]; 28 82 } 29 83 … … 32 86 [PSAlarmAlertController stopAlerts: sender]; 33 87 [self close]; 88 [[PSNotifierAlert alert] completedForAlarm: alarm]; 89 } 90 91 - (IBAction)snooze:(NSButton *)sender; 92 { 93 NSTimeInterval snoozeInterval = [snoozeIntervalField interval]; 94 [alarm setSnoozeInterval: snoozeInterval]; 95 [[NSUserDefaults standardUserDefaults] setObject: [NSNumber numberWithDouble: snoozeInterval] forKey: PSAlarmSnoozeInterval]; 96 [self close: sender]; 97 } 98 99 - (IBAction)stopRepeating:(NSButton *)sender; 100 { 101 NSWindow *window = [self window]; 102 NSRect frameRect = [window frame]; 103 NSSize newSize = [window minSize]; 104 105 [alarm setRepeating: NO]; 106 [sender setEnabled: NO]; 107 frameRect.origin.y += frameRect.size.height - newSize.height; 108 frameRect.size = newSize; 109 [window setFrame: frameRect display: YES animate: YES]; 34 110 } 35 111 36 112 @end 113 114 @implementation PSAlarmNotifierController (NSControlSubclassDelegate) 115 116 - (BOOL)control:(NSControl *)control didFailToFormatString:(NSString *)string errorDescription:(NSString *)error; 117 { 118 if (control == snoozeIntervalField) 119 [snoozeIntervalField handleDidFailToFormatString: string errorDescription: error label: @"snooze interval"]; 120 return NO; 121 } 122 123 - (void)control:(NSControl *)control didFailToValidatePartialString:(NSString *)string errorDescription:(NSString *)error; 124 { 125 // NSLog(@"UPDATING FROM validation"); 126 [self update: control]; // switch to snooze if someone types something weird... 127 } 128 129 - (BOOL)control:(NSControl *)control textView:(NSTextView *)textView doCommandBySelector:(SEL)commandSelector; 130 { 131 // NSLog(@"UPDATING from textView: %@", NSStringFromSelector(commandSelector)); 132 if (commandSelector == @selector(cancel:)) { 133 // if someone just wants the stupid thing to go away and presses escape, donÕt hinder them 134 [self close: control]; 135 return YES; 136 } 137 // if someone invokes the default button or switches fields, donÕt override it 138 if (commandSelector == @selector(insertNewline:) || 139 commandSelector == @selector(insertTab:) || 140 commandSelector == @selector(insertBacktab:)) return NO; 141 [self update: control]; // ...or if they type a navigation key... 142 return NO; // we donÕt handle it 143 } 144 145 @end 146 147 @implementation PSAlarmNotifierController (NSControlSubclassNotifications) 148 149 - (void)controlTextDidChange:(NSNotification *)notification; 150 { 151 // NSLog(@"UPDATING FROM controlTextDidChange: %@", [notification object]); 152 [self update: [notification object]]; // ...or if they modify the snooze interval 153 } 154 155 @end 156 157 @implementation PSAlarmNotifierController (NSWindowNotifications) 158 159 - (void)windowWillClose:(NSNotification *)notification; 160 { 161 // canÕt rely on dealloc to invalidate the timer, because it retains this object 162 [updateTimer invalidate]; updateTimer = nil; 163 [self release]; // in non-document-based apps, this is needed; see docs 164 } 165 166 @end
Note:
See TracChangeset
for help on using the changeset viewer.