source: trunk/Cocoa/Pester/Source/NJRValidatingField.m@ 429

Last change on this file since 429 was 364, checked in by Nicholas Riley, 17 years ago

English.lproj/Alarms.nib: Specify alternating row coloring in the nib,
now we're 10.4+.

English.lproj/InfoPlist.strings: Updated for 1.1b6.

English.lproj/Localizable.strings: Quote alarm message in pretty
description (used in tooltip). Change voice error now it no longer
incorporates OSStatus.

English.lproj/MainMenu.nib: Add speech prefs again; turn repetitions
field into a NJRValidatingField and hook up its delegate.

Info-Pester.plist: Updated for 1.1b6.

NJRHotKey.m: Switch to new Objective-C exception style.

NJRIntervalField.[hm]: Now a subclass of NJRValidatingField.

NJRTableDelegate.m: Get rid of our own tooltip support as NSTableView
now supports them (though with a minor visual glitch on the first
tooltip).

NJRTableView.[hm]: Remove tooltip support. Remove alternating row
coloring support.

NJRValidatingField.[hm]: Contains validation sheet stuff from
NJRIntervalField.

NJRVoicePopUpButton.[hm]: Switch to NSSpeechSynthesizer.

PSAlarm.m: Quote alarm message in pretty description (used in
tooltip). Fix repeating alarms not restoring as repeating if they
didn't expire while Pester was not running. No longer set timer on
Pester 1.0 alarm import, to help make importing atomic.

PSAlarmSetController.[hm]: Use NJRValidatingField for repetitions
field. Switch to new Objective-C exception style. Fix validation
issues on in/at changing. Temporary changes to restore speech support
and allow the sound popup to be removed entirely from the nib (rather
than being dragged out of the visible area, as it was in 1.1b5).
Changes for NSSpeechSynthesizer, which uses different voice names.

PSAlarms.m: Switch to new Objective-C exception style. Fix
duplication and error handling in Pester 1.0 alarm import, making
atomic.

PSAlarmsController.m: Use new tooltip support (since it's implemented
in the delegate rather than the data source, we have to proxy it).

PSAlerts.m: Wrap initialization in exception block so we don't leak.

PSApplication.m: Switch to new Objective-C exception style.

PSMediaAlert.m: Clamp repetitions at 1..99 so the user can't type an
invalid value, then quit and have it saved.

PSSpeechAlert.[hm]: Switch to NSSpeechSynthesizer. Throw an
intelligible exception if the voice is unavailable.

PSTimer.m: Switch to new Objective-C exception style.

Pester.xcodeproj: Remove VERSION generation; rename targets to be more
understandable.

Read Me.rtfd: Updated for 1.1b6.

SUSpeaker.[hm]: Gone in switch to NSSpeechSynthesizer.

VERSION: Gone - we use agvtool for everything now.

Updates/release-notes.html: Updated for 1.1b6.

Updates/updates.xml: Updated for 1.1b6.

package-Pester.sh: Use agvtool to get version. Atomically update
file on Web server to avoid partial downloads.

File size: 4.8 KB
Line 
1//
2// NJRValidatingField.m
3// Pester
4//
5// Created by Nicholas Riley on 11/27/07.
6// Copyright 2007 Nicholas Riley. All rights reserved.
7//
8
9#import "NJRValidatingField.h"
10
11
12@implementation NJRValidatingField
13
14- (void)_propagateValidationChange;
15{
16 NSText *fieldEditor = [self currentEditor];
17 NSDictionary *userInfo = nil;
18 if (fieldEditor != nil) userInfo = [NSDictionary dictionaryWithObject: fieldEditor forKey: @"NSFieldEditor"];
19 [[NSNotificationCenter defaultCenter] postNotificationName: NSControlTextDidChangeNotification object: self userInfo: userInfo];
20 [self selectText: self];
21}
22
23- (void)validationFailedSheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo {
24 // modal delegate callback method for NSBeginAlertSheet() function; called in the above method
25 if (returnCode == NSAlertOtherReturn) { // cancel
26 [self abortEditing]; // abort edit session and reinstate original value
27 [self _propagateValidationChange];
28 } else if (returnCode == NSAlertAlternateReturn) { // set to min/max/default value
29 [self setObjectValue: [(NSDictionary *)contextInfo objectForKey: @"proposedValue"]];
30 [self validateEditing];
31 [self _propagateValidationChange];
32 }
33 [(NSDictionary *)contextInfo release];
34}
35
36- (void)handleDidFailToFormatString:(NSString *)string errorDescription:(NSString *)error label:(NSString *)label;
37{
38 NSString *alertMessage = nil;
39 NSString *alternateButtonString = nil;
40 NSNumber *proposedValue = nil;
41 NSDictionary *contextInfo;
42
43 NSString *alertInformation = [NSString localizedStringWithFormat:
44 NSLocalizedString(@"The %@ field must be set to a value between %@ and %@.",
45 @"Informative text for alert posed by text field when invalid value entered"),
46 label, [[self formatter] minimum], [[self formatter] maximum]];
47 NSString *defaultButtonString = NSLocalizedString(@"Edit", @"Name of Edit button");
48 NSString *otherButtonString = NSLocalizedString(@"Cancel", @"Name of Cancel button");
49
50 if ([error isEqualToString:
51 NSLocalizedStringFromTableInBundle(@"Fell short of minimum", @"Formatter",
52 [NSBundle bundleForClass:[NSFormatter class]],
53 @"Presented when user value smaller than minimum")]) {
54 proposedValue = [[self formatter] minimum];
55 alertMessage = [NSString stringWithFormat:
56 NSLocalizedString(@"%@ is too small for the %@ field.",
57 @"Message text for alert posed by numeric field when too-small value entered"),
58 string, label];
59 alternateButtonString = [NSString localizedStringWithFormat:
60 NSLocalizedString(@"Set to %@",
61 @"Name of alternate button for alert posed by numeric field when too-small value entered"),
62 proposedValue];
63 } else if ([error isEqualToString:
64 NSLocalizedStringFromTableInBundle(@"Maximum exceeded", @"Formatter",
65 [NSBundle bundleForClass:[NSFormatter class]],
66 @"Presented when user value larger than maximum")]) {
67 proposedValue = [[self formatter] maximum];
68 alertMessage = [NSString stringWithFormat:
69 NSLocalizedString(@"%@ is too large for the %@ field.",
70 @"Message text for alert posed by numeric field when too-large value entered"),
71 string, label];
72 alternateButtonString = [NSString localizedStringWithFormat:
73 NSLocalizedString(@"Set to %@",
74 @"Name of alternate button for alert posed by numeric field when too-large value entered"),
75 proposedValue];
76 } else if ([error isEqualToString:
77 NSLocalizedStringFromTableInBundle(@"Invalid number", @"Formatter",
78 [NSBundle bundleForClass:[NSFormatter class]],
79 @"Presented when user typed illegal characters: no valid object")]) {
80 alertMessage = [NSString stringWithFormat:
81 NSLocalizedString(@"%@ is not a valid entry for the %@ field.",
82 @"Message text for alert posed by text field when invalid value entered"),
83 string, label];
84 alternateButtonString = nil;
85 }
86
87 contextInfo = [NSDictionary dictionaryWithObject: proposedValue forKey: @"proposedValue"];
88 [contextInfo retain];
89 NSBeep();
90 NSBeginAlertSheet(alertMessage, defaultButtonString, alternateButtonString, otherButtonString, [self window],
91 self, @selector(validationFailedSheetDidEnd:returnCode:contextInfo:), NULL, contextInfo,
92 alertInformation);
93}
94@end
Note: See TracBrowser for help on using the repository browser.