Ignore:
Timestamp:
01/02/03 05:30:03 (20 years ago)
Author:
Nicholas Riley
Message:

Updated for Pester 1.1a5 (very limited release).

Pester 1.1a4 was never released.

Location:
trunk/Cocoa/Pester/Source
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Cocoa/Pester/Source

    • Property svn:ignore
      •  

        old new  
        11build
         2.gdb_history
  • trunk/Cocoa/Pester/Source/PSAlarmNotifierController.m

    r43 r53  
    1010#import "PSAlarmAlertController.h"
    1111#import "PSAlarm.h"
     12#import "PSNotifierAlert.h"
     13#import "NJRIntervalField.h"
     14
     15static 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
    1223
    1324@implementation PSAlarmNotifierController
     
    1526// XXX should use NSNonactivatingPanelMask on 10.2
    1627
    17 - (id)initWithAlarm:(PSAlarm *)alarm;
     28- (id)initWithAlarm:(PSAlarm *)anAlarm;
    1829{
    1930    if ([self initWithWindowNibName: @"Notifier"]) {
    20         [[self window] center];
     31        NSWindow *window = [self window];
     32        NSRect frameRect = [window frame];
     33        alarm = [anAlarm retain];
    2134        [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];
    2652    }
    2753    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: @""];
    2882}
    2983
     
    3286    [PSAlarmAlertController stopAlerts: sender];
    3387    [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];
    34110}
    35111
    36112@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.