Ignore:
Timestamp:
11/18/02 08:57:41 (20 years ago)
Author:
Nicholas Riley
Message:

Alarms.nib: Removed horizontal scroll bar. Turned on grid. Set delegate to NJRTableDelegate instead of PSAlarmSetController.

NJRTableDelegate: In general, made functional (was previously unused). Fixed MyCompanyName. Changed ORDER_BY_CONTEXT to use key-value coding instead of assuming data consists of a dictionary of dictionaries. Added sorting support (reorderedData, replaces oData) with autosave support for sort context. Added _positionTypeSelectDisplay, which adjusts position and justification of type select display control based on the current sort column. Added support for reverse sorting in type select string. Use table data source instead of sorted data so text matches as displayed (this will break with non-text cells...).

NJRTableView: Adapted from iTableView (Jaguar table alternate table background color), TableTester? (most everything else) and NJROutlineView (keyDown, moveToBeginning/EndOfDocument). Support for type selection, delete shortcut for row deletion, and iTunes-alike background colors and frame.

NSCharacterSet-NJRExtensions: Moved _typeSelectSet from NJROutlineView as it's now shared with NJRTableView. Still need to factor NJROutlineView as embedded in HostLauncher? some day.

PSAlarm: Reorganized, renamed and categorized methods. Added time accessor for the benefit of sorting. Renamed compare: to compareDate: for clarity. Added compareMessage:, though it's currently unused. Renamed cancel to cancelTimer for clarity.

PSAlarmSetController: More fun with initial first responder on window show/hide; still need to work around bug properly (subclass NSComboBox?) and fix it for real. As is, works for OS X 10.1.

PSAlarms: Added alarms accessor, returning alarm array. Fixed memory leak on successful alarm removal (oops). Added removeAlarms:, needed with sorted alarm list.

PSAlarmsController: Set window resize increment. Changes to table delegate methods to use reordered alarm list. Register for NSTableViewSelectionDidChangeNotification now we're no longer the table view delegate. Fixed autoselection in alarmsChanged by using data reordering support in NJRTableView. Implement NJRTableViewDataSource to permit deletion from table view.

Pester.pbproj: Added new files.

Read Me.rtfd: Added TableTester?/iTableView acknowledgements. Updated release notes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Cocoa/Pester/Source/PSAlarm.m

    r43 r51  
    2020
    2121@implementation PSAlarm
     22
     23#pragma mark initialize-release
    2224
    2325+ (void)initialize; // XXX change on locale modification, subscribe to NSNotifications
     
    4143}
    4244
     45#pragma mark private
     46
    4347- (void)_setAlarmDate:(NSCalendarDate *)aDate;
    4448{
     
    5054}
    5155
    52 - (void)_invalidate:(NSString *)aMessage;
     56- (void)_beInvalid:(NSString *)aMessage;
    5357{
    5458    alarmType = PSAlarmInvalid;
     
    6266}
    6367
    64 - (void)_validateForType:(PSAlarmType)type;
     68- (void)_beValidWithType:(PSAlarmType)type;
    6569{
    6670    if (alarmType == PSAlarmSet) return; // already valid
     
    7579    alarmDate = [NSCalendarDate dateWithTimeIntervalSinceNow: alarmInterval];
    7680    [alarmDate retain];
    77     [self _validateForType: PSAlarmInterval];
    78 }
     81    [self _beValidWithType: PSAlarmInterval];
     82}
     83
     84- (void)_setIntervalFromDate;
     85{
     86    alarmInterval = [alarmDate timeIntervalSinceNow] + 1;
     87    if (alarmInterval <= 0) {
     88        [self _beInvalid: @"Please specify an alarm time in the future."];
     89        return;
     90    }
     91    [self _beValidWithType: PSAlarmDate];
     92}
     93
     94- (NSString *)_alarmTypeString;
     95{
     96    switch (alarmType) {
     97        case PSAlarmDate: return @"PSAlarmDate";
     98        case PSAlarmInterval: return @"PSAlarmInterval";
     99        case PSAlarmSet: return @"PSAlarmSet";
     100        case PSAlarmInvalid: return @"PSAlarmInvalid";
     101        default: return [NSString stringWithFormat: @"<unknown: %u>", alarmType];
     102    }
     103}
     104
     105- (void)_timerExpired:(NSTimer *)aTimer;
     106{
     107    [[NSNotificationCenter defaultCenter] postNotificationName: PSAlarmTimerExpiredNotification object: self];
     108    [timer release]; timer = nil;
     109}
     110
     111#pragma mark alarm setting
    79112
    80113- (void)setInterval:(NSTimeInterval)anInterval;
     
    82115    alarmInterval = anInterval;
    83116    if (alarmInterval <= 0) {
    84         [self _invalidate: @"Please specify an alarm interval."]; return;
     117        [self _beInvalid: @"Please specify an alarm interval."]; return;
    85118    }
    86119    [self _setDateFromInterval];
    87 }
    88 
    89 - (void)_setIntervalFromDate;
    90 {
    91     alarmInterval = [alarmDate timeIntervalSinceNow] + 1;
    92     if (alarmInterval <= 0) {
    93         [self _invalidate: @"Please specify an alarm time in the future."];
    94         return;
    95     }
    96     [self _validateForType: PSAlarmDate];
    97120}
    98121
     
    107130    NSCalendarDate *calTime, *calDate;
    108131    if (time == nil && date == nil) {
    109         [self _invalidate: @"Please specify an alarm date and time."]; return;
     132        [self _beInvalid: @"Please specify an alarm date and time."]; return;
    110133    }
    111134    if (time == nil) {
    112         [self _invalidate: @"Please specify an alarm time."]; return;
     135        [self _beInvalid: @"Please specify an alarm time."]; return;
    113136    }
    114137    if (date == nil) {
    115         [self _invalidate: @"Please specify an alarm date."]; return;
     138        [self _beInvalid: @"Please specify an alarm date."]; return;
    116139    }
    117140    // XXX if calTime's date is different from the default date, complain
     
    119142    calDate = [NSCalendarDate dateWithTimeIntervalSinceReferenceDate: [date timeIntervalSinceReferenceDate]];
    120143    if (calTime == nil || calDate == nil) {
    121         [self _invalidate: @"Please specify a reasonable date and time."];
     144        [self _beInvalid: @"Please specify a reasonable date and time."];
    122145    }
    123146    [self setForDateAtTime:
     
    131154}
    132155
    133 - (BOOL)isValid;
    134 {
    135     if (alarmType == PSAlarmDate) [self _setIntervalFromDate];
    136     return (alarmType != PSAlarmInvalid);
     156#pragma mark accessing
     157
     158- (NSString *)message;
     159{
     160    if (alarmMessage == nil || [alarmMessage isEqualToString: @""])
     161        return @"Alarm!";
     162    return alarmMessage;
    137163}
    138164
     
    146172}
    147173
    148 - (NSString *)message;
    149 {
    150     if (alarmMessage == nil || [alarmMessage isEqualToString: @""])
    151         return @"Alarm!";
    152     return alarmMessage;   
     174- (BOOL)isValid;
     175{
     176    if (alarmType == PSAlarmDate) [self _setIntervalFromDate];
     177    return (alarmType != PSAlarmInvalid);
    153178}
    154179
     
    163188    if (alarmType == PSAlarmInterval) [self _setDateFromInterval];
    164189    return alarmDate;
     190}
     191
     192- (NSCalendarDate *)time;
     193{
     194    if (alarmType == PSAlarmInterval) [self _setDateFromInterval];
     195    return [[NSCalendarDate alloc] initWithYear: 0
     196                                          month: 1
     197                                            day: 1
     198                                           hour: [alarmDate hourOfDay]
     199                                         minute: [alarmDate minuteOfHour]
     200                                         second: [alarmDate secondOfMinute]
     201                                       timeZone: nil];
     202}
     203
     204- (NSTimeInterval)interval;
     205{
     206    if (alarmType == PSAlarmSet || alarmType == PSAlarmDate) [self _setIntervalFromDate];
     207    return alarmInterval;
     208}
     209
     210- (void)addAlert:(PSAlert *)alert;
     211{
     212    if (alerts == nil) alerts = [[NSMutableArray alloc] initWithCapacity: 4];
     213    [alerts addObject: alert];
     214}
     215
     216- (void)removeAlerts;
     217{
     218    [alerts removeAllObjects];
     219}
     220
     221- (NSArray *)alerts;
     222{
     223    return [[alerts copy] autorelease];
    165224}
    166225
     
    193252}
    194253
    195 - (NSTimeInterval)interval;
    196 {
    197     if (alarmType == PSAlarmSet || alarmType == PSAlarmDate) [self _setIntervalFromDate];
    198     return alarmInterval;
    199 }
     254#pragma mark actions
    200255
    201256- (BOOL)setTimer;
     
    204259        case PSAlarmDate: if (![self isValid]) return NO;
    205260        case PSAlarmInterval:
    206             timer = [NSTimer scheduledTimerWithTimeInterval: alarmInterval
    207                                                      target: self
    208                                                    selector: @selector(_timerExpired:)
    209                                                    userInfo: nil
    210                                                     repeats: NO];
     261            timer = [NSTimer scheduledTimerWithTimeInterval: alarmInterval target: self selector: @selector(_timerExpired:) userInfo: nil repeats: NO];
    211262            if (timer != nil) {
    212263                [timer retain];
     
    220271}
    221272
    222 - (void)cancel;
     273- (void)cancelTimer;
    223274{
    224275    [timer invalidate]; [timer release]; timer = nil;
    225276}
    226277
    227 - (void)_timerExpired:(NSTimer *)aTimer;
    228 {
    229     [[NSNotificationCenter defaultCenter] postNotificationName: PSAlarmTimerExpiredNotification object: self];
    230     [timer release]; timer = nil;
    231 }
    232 
    233 - (NSString *)_alarmTypeString;
    234 {
    235     switch (alarmType) {
    236         case PSAlarmDate: return @"PSAlarmDate";
    237         case PSAlarmInterval: return @"PSAlarmInterval";
    238         case PSAlarmSet: return @"PSAlarmSet";
    239         case PSAlarmInvalid: return @"PSAlarmInvalid";
    240         default: return [NSString stringWithFormat: @"<unknown: %u>", alarmType];
    241     }
    242 }
    243 
    244 - (NSComparisonResult)compare:(PSAlarm *)otherAlarm;
     278#pragma mark comparing
     279
     280- (NSComparisonResult)compareDate:(PSAlarm *)otherAlarm;
    245281{
    246282    return [[self date] compare: [otherAlarm date]];
    247283}
    248284
    249 - (void)addAlert:(PSAlert *)alert;
    250 {
    251     if (alerts == nil) alerts = [[NSMutableArray alloc] initWithCapacity: 4];
    252     [alerts addObject: alert];
    253 }
    254 
    255 - (void)removeAlerts;
    256 {
    257     [alerts removeAllObjects];
    258 }
    259 
    260 - (NSArray *)alerts;
    261 {
    262     return [[alerts copy] autorelease];
    263 }
     285- (NSComparisonResult)compareMessage:(PSAlarm *)otherAlarm;
     286{
     287    return [[self message] caseInsensitiveCompare: [otherAlarm message]];
     288}
     289
     290#pragma mark printing
    264291
    265292- (NSString *)description;
     
    272299           [NSString stringWithFormat: @"\ntimer: %@", timer] : @""))];
    273300}
     301
     302#pragma mark archiving
    274303
    275304- (void)encodeWithCoder:(NSCoder *)coder;
Note: See TracChangeset for help on using the changeset viewer.