source: trunk/Cocoa/Pester/Source/PSTimeDateEditor.m@ 620

Last change on this file since 620 was 556, checked in by Nicholas Riley, 15 years ago

Remove now-unnecessary testing code in PSTimeDateEditor.

File size: 2.3 KB
Line 
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{
16 [NSDateFormatter setDefaultFormatterBehavior: NSDateFormatterBehavior10_4];
17 static NSDateFormatter *timeFormatter = nil, *dateFormatter = nil;
18 if (timeFormatter == nil) {
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];
27 }
28 [timeOfDay setFormatter: timeFormatter];
29 [timeDate setFormatter: dateFormatter];
30 [timeDate setObjectValue: [NSDate date]];
31
32 // add completions
33 NSArray *dayNames = [dateFormatter weekdaySymbols];
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) {
40 matchingRange = [title rangeOfString: @"«day»"];
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 }
52 [format release];
53 } else itemIndex++;
54 }
55 if ([timeDateCompletions pullsDown]) // add a dummy first item, which gets consumed for the (obscured) title
56 [timeDateCompletions insertItemWithTitle: @"" atIndex: 0];
57}
58
59@end
Note: See TracBrowser for help on using the repository browser.