source: releases/Pester/1.0/Source/NJRIntegerFilter.m

Last change on this file was 21, checked in by Nicholas Riley, 22 years ago

Pester 1.0d1

File size: 1.5 KB
Line 
1//
2// NJRIntegerFilter.m
3// HostLauncher
4//
5// Created by Nicholas Riley on Tue Dec 18 2001.
6// Copyright (c) 2001 Nicholas Riley. All rights reserved.
7//
8
9// based on MyIntegerFilter
10// Copyright © 2001 Bill Cheeseman. All rights reserved.
11
12#import "NJRIntegerFilter.h"
13
14@implementation NJRIntegerFilter
15
16// Input filter
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".
22 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
25 }
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
32 return YES; // Accept *partialStringPtr as typed
33}
34
35@end
Note: See TracBrowser for help on using the repository browser.