[102] | 1 | //
|
---|
| 2 | // PSTimeDateEditor.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 "PSTimeDateEditor.h"
|
---|
| 10 | #import "NJRDateFormatter.h"
|
---|
| 11 |
|
---|
| 12 | @implementation PSTimeDateEditor
|
---|
| 13 |
|
---|
| 14 | + (void)setUpTimeField:(NSTextField *)timeOfDay dateField:(NSTextField *)timeDate completions:(NSPopUpButton *)timeDateCompletions;
|
---|
| 15 | {
|
---|
[360] | 16 | [[NJRDateFormatter alloc] init]; // XXX testing
|
---|
| 17 | [NSDateFormatter setDefaultFormatterBehavior: NSDateFormatterBehavior10_4];
|
---|
| 18 | static NSDateFormatter *timeFormatter = nil, *dateFormatter = nil;
|
---|
[102] | 19 | if (timeFormatter == nil) {
|
---|
[360] | 20 | timeFormatter = [[NJRDateFormatter timeFormatter] retain];
|
---|
| 21 | [timeFormatter setLenient: YES];
|
---|
| 22 | [timeFormatter setDateStyle: NSDateFormatterNoStyle];
|
---|
| 23 | [timeFormatter setTimeStyle: NSDateFormatterShortStyle];
|
---|
| 24 | dateFormatter = [[NJRDateFormatter dateFormatter] retain];
|
---|
| 25 | [dateFormatter setLenient: YES];
|
---|
| 26 | [dateFormatter setDateStyle: NSDateFormatterLongStyle];
|
---|
| 27 | [dateFormatter setTimeStyle: NSDateFormatterNoStyle];
|
---|
[102] | 28 | }
|
---|
| 29 | [timeOfDay setFormatter: timeFormatter];
|
---|
| 30 | [timeDate setFormatter: dateFormatter];
|
---|
| 31 | [timeDate setObjectValue: [NSDate date]];
|
---|
| 32 |
|
---|
| 33 | // add completions
|
---|
[360] | 34 | NSArray *dayNames = [dateFormatter weekdaySymbols];
|
---|
[102] | 35 | NSArray *completions = [timeDateCompletions itemTitles];
|
---|
| 36 | NSEnumerator *e = [completions objectEnumerator];
|
---|
| 37 | NSString *title;
|
---|
| 38 | int itemIndex = 0;
|
---|
| 39 | NSRange matchingRange;
|
---|
| 40 | while ( (title = [e nextObject]) != nil) {
|
---|
[355] | 41 | matchingRange = [title rangeOfString: @"«day»"];
|
---|
[102] | 42 | if (matchingRange.location != NSNotFound) {
|
---|
| 43 | NSMutableString *format = [title mutableCopy];
|
---|
| 44 | NSEnumerator *we = [dayNames objectEnumerator];
|
---|
| 45 | NSString *dayName;
|
---|
| 46 | [format deleteCharactersInRange: matchingRange];
|
---|
| 47 | [format insertString: @"%@" atIndex: matchingRange.location];
|
---|
| 48 | [timeDateCompletions removeItemAtIndex: itemIndex];
|
---|
| 49 | while ( (dayName = [we nextObject]) != nil) {
|
---|
| 50 | [timeDateCompletions insertItemWithTitle: [NSString stringWithFormat: format, dayName] atIndex: itemIndex];
|
---|
| 51 | itemIndex++;
|
---|
| 52 | }
|
---|
[355] | 53 | [format release];
|
---|
[102] | 54 | } else itemIndex++;
|
---|
| 55 | }
|
---|
| 56 | }
|
---|
| 57 |
|
---|
| 58 | @end
|
---|