Changeset 53 for trunk/Cocoa/Pester/Source/NJRIntegerFilter.m
- Timestamp:
- 01/02/03 05:30:03 (21 years ago)
- Location:
- trunk/Cocoa/Pester/Source
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Cocoa/Pester/Source
- Property svn:ignore
-
old new 1 1 build 2 .gdb_history
-
- Property svn:ignore
-
trunk/Cocoa/Pester/Source/NJRIntegerFilter.m
r21 r53 7 7 // 8 8 9 // based on MyIntegerFilter 10 // Copyright © 2001 Bill Cheeseman. All rights reserved.9 // based on MyIntegerFilter, later VRIntegerNumberFilter 10 // Copyright © 2001-2002 Bill Cheeseman. All rights reserved. 11 11 12 12 #import "NJRIntegerFilter.h" … … 14 14 @implementation NJRIntegerFilter 15 15 16 // Input filter16 // Input validation 17 17 18 - (BOOL)isPartialStringValid:(NSString **)partialStringPtr proposedSelectedRange:(NSRangePointer)proposedSelRangePtr originalString:(NSString *)origString originalSelectedRange:(NSRange)origSelRange errorDescription:(NSString **)error { 19 20 // Override method to enable NSControl delegate method control:didFailToValidatePartialString:errorDescription: to 21 // reject invalid keypresses. Filters out keyboard input characters other than "1" .. "9". 18 - (BOOL)isPartialStringValid:(NSString **)partialStringPtr proposedSelectedRange:(NSRangePointer)proposedSelRangePtr originalString:(NSString *)origString originalSelectedRange:(NSRange)origSelRange errorDescription:(NSString **)error; 19 { 20 // Override method to enable NSControl delegate method control:didFailToValidatePartialString:errorDescription: to reject invalid keypresses. Filters out keyboard input characters other than 0..9. 22 21 if ([[*partialStringPtr substringWithRange:NSMakeRange(origSelRange.location, (*proposedSelRangePtr).location - origSelRange.location)] rangeOfCharacterFromSet:[[NSCharacterSet decimalDigitCharacterSet] invertedSet] options:NSLiteralSearch].location != NSNotFound) { 23 *error = NSLocalizedString(@"Input is not an integer ", @"Presented when user value not a numeric digit");24 return NO; // Reject *partialStringPtr as typed, invoke delegate method 22 *error = NSLocalizedString(@"Input is not an integer.", @"Presented when user value not a numeric digit"); 23 return NO; // Reject *partialStringPtr as typed, invoke delegate method for error handling 25 24 } 26 27 if ([*partialStringPtr length] == 0) { 28 // Work around NSFormatter issue in Mac OS X 10.0. 29 [[[NSApp keyWindow] fieldEditor:NO forObject:nil] setSelectedRange:*proposedSelRangePtr]; 30 } 31 25 *error = nil; 32 26 return YES; // Accept *partialStringPtr as typed 33 27 }
Note:
See TracChangeset
for help on using the changeset viewer.