[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 | [NSDateFormatter setDefaultFormatterBehavior: NSDateFormatterBehavior10_4];
|
---|
| 17 | static NSDateFormatter *timeFormatter = nil, *dateFormatter = nil;
|
---|
[102] | 18 | if (timeFormatter == nil) {
|
---|
[360] | 19 | timeFormatter = [[NJRDateFormatter timeFormatter] retain];
|
---|
| 20 | [timeFormatter setLenient: YES];
|
---|
| 21 | [timeFormatter setDateStyle: NSDateFormatterNoStyle];
|
---|
| 22 | [timeFormatter setTimeStyle: NSDateFormatterShortStyle];
|
---|
| 23 | dateFormatter = [[NJRDateFormatter dateFormatter] retain];
|
---|
| 24 | [dateFormatter setLenient: YES];
|
---|
| 25 | [dateFormatter setDateStyle: NSDateFormatterLongStyle];
|
---|
| 26 | [dateFormatter setTimeStyle: NSDateFormatterNoStyle];
|
---|
[102] | 27 | }
|
---|
| 28 | [timeOfDay setFormatter: timeFormatter];
|
---|
| 29 | [timeDate setFormatter: dateFormatter];
|
---|
| 30 | [timeDate setObjectValue: [NSDate date]];
|
---|
| 31 |
|
---|
| 32 | // add completions
|
---|
[360] | 33 | NSArray *dayNames = [dateFormatter weekdaySymbols];
|
---|
[102] | 34 | NSArray *completions = [timeDateCompletions itemTitles];
|
---|
| 35 | NSEnumerator *e = [completions objectEnumerator];
|
---|
| 36 | NSString *title;
|
---|
| 37 | int itemIndex = 0;
|
---|
| 38 | NSRange matchingRange;
|
---|
| 39 | while ( (title = [e nextObject]) != nil) {
|
---|
[355] | 40 | matchingRange = [title rangeOfString: @"«day»"];
|
---|
[102] | 41 | if (matchingRange.location != NSNotFound) {
|
---|
| 42 | NSMutableString *format = [title mutableCopy];
|
---|
| 43 | NSEnumerator *we = [dayNames objectEnumerator];
|
---|
| 44 | NSString *dayName;
|
---|
| 45 | [format deleteCharactersInRange: matchingRange];
|
---|
| 46 | [format insertString: @"%@" atIndex: matchingRange.location];
|
---|
| 47 | [timeDateCompletions removeItemAtIndex: itemIndex];
|
---|
| 48 | while ( (dayName = [we nextObject]) != nil) {
|
---|
| 49 | [timeDateCompletions insertItemWithTitle: [NSString stringWithFormat: format, dayName] atIndex: itemIndex];
|
---|
| 50 | itemIndex++;
|
---|
| 51 | }
|
---|
[355] | 52 | [format release];
|
---|
[102] | 53 | } else itemIndex++;
|
---|
| 54 | }
|
---|
[521] | 55 | if ([timeDateCompletions pullsDown]) // add a dummy first item, which gets consumed for the (obscured) title
|
---|
| 56 | [timeDateCompletions insertItemWithTitle: @"" atIndex: 0];
|
---|
[102] | 57 | }
|
---|
| 58 |
|
---|
| 59 | @end
|
---|