Changeset 364 for trunk/Cocoa/Pester/Source/NJRIntervalField.m
- Timestamp:
- 11/28/07 01:29:26 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Cocoa/Pester/Source/NJRIntervalField.m
r355 r364 80 80 } 81 81 82 - (void)handleDidFailToFormatString:(NSString *)string errorDescription:(NSString *)error label:(NSString *)label;83 {84 NSString *alertMessage = nil;85 NSString *alternateButtonString = nil;86 NSNumber *proposedValue = nil;87 NSDictionary *contextInfo;88 89 NSString *alertInformation = [NSString localizedStringWithFormat:90 NSLocalizedString(@"The %@ field must be set to a value between %@ and %@.",91 @"Informative text for alert posed by text field when invalid value entered"),92 label, [[self formatter] minimum], [[self formatter] maximum]];93 NSString *defaultButtonString = NSLocalizedString(@"Edit", @"Name of Edit button");94 NSString *otherButtonString = NSLocalizedString(@"Cancel", @"Name of Cancel button");95 96 if ([error isEqualToString:97 NSLocalizedStringFromTableInBundle(@"Fell short of minimum", @"Formatter",98 [NSBundle bundleForClass:[NSFormatter class]],99 @"Presented when user value smaller than minimum")]) {100 proposedValue = [[self formatter] minimum];101 alertMessage = [NSString stringWithFormat:102 NSLocalizedString(@"%@ is too small for the %@ field.",103 @"Message text for alert posed by numeric field when too-small value entered"),104 string, label];105 alternateButtonString = [NSString localizedStringWithFormat:106 NSLocalizedString(@"Set to %@",107 @"Name of alternate button for alert posed by numeric field when too-small value entered"),108 proposedValue];109 } else if ([error isEqualToString:110 NSLocalizedStringFromTableInBundle(@"Maximum exceeded", @"Formatter",111 [NSBundle bundleForClass:[NSFormatter class]],112 @"Presented when user value larger than maximum")]) {113 proposedValue = [[self formatter] maximum];114 alertMessage = [NSString stringWithFormat:115 NSLocalizedString(@"%@ is too large for the %@ field.",116 @"Message text for alert posed by numeric field when too-large value entered"),117 string, label];118 alternateButtonString = [NSString localizedStringWithFormat:119 NSLocalizedString(@"Set to %@",120 @"Name of alternate button for alert posed by numeric field when too-large value entered"),121 proposedValue];122 } else if ([error isEqualToString:123 NSLocalizedStringFromTableInBundle(@"Invalid number", @"Formatter",124 [NSBundle bundleForClass:[NSFormatter class]],125 @"Presented when user typed illegal characters: no valid object")]) {126 alertMessage = [NSString stringWithFormat:127 NSLocalizedString(@"%@ is not a valid entry for the %@ field.",128 @"Message text for alert posed by text field when invalid value entered"),129 string, label];130 alternateButtonString = nil;131 }132 133 contextInfo = [NSDictionary dictionaryWithObject: proposedValue forKey: @"proposedValue"];134 [contextInfo retain];135 NSBeep();136 NSBeginAlertSheet(alertMessage, defaultButtonString, alternateButtonString, otherButtonString, [self window],137 self, @selector(validationFailedSheetDidEnd:returnCode:contextInfo:), NULL, contextInfo,138 alertInformation);139 }140 141 - (void)_propagateValidationChange;142 {143 NSText *fieldEditor = [self currentEditor];144 NSDictionary *userInfo = nil;145 if (fieldEditor != nil) userInfo = [NSDictionary dictionaryWithObject: fieldEditor forKey: @"NSFieldEditor"];146 [[NSNotificationCenter defaultCenter] postNotificationName: NSControlTextDidChangeNotification object: self userInfo: userInfo];147 [self selectText: self];148 }149 150 - (void)validationFailedSheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo {151 // modal delegate callback method for NSBeginAlertSheet() function; called in the above method152 if (returnCode == NSAlertOtherReturn) { // cancel153 [self abortEditing]; // abort edit session and reinstate original value154 [self _propagateValidationChange];155 } else if (returnCode == NSAlertAlternateReturn) { // set to min/max/default value156 [self setObjectValue: [(NSDictionary *)contextInfo objectForKey: @"proposedValue"]];157 [self validateEditing];158 [self _propagateValidationChange];159 }160 [(NSDictionary *)contextInfo release];161 }162 163 82 @end
Note:
See TracChangeset
for help on using the changeset viewer.