Fix bug 324369: make sure we save a changed history value when closing the prefs pane (if the user hasn't tabbed to another control), while validating that it's a number.

This commit is contained in:
smfr%smfr.org 2006-02-01 05:18:47 +00:00
Родитель 68d4747601
Коммит f7226db89a
2 изменённых файлов: 47 добавлений и 13 удалений

Просмотреть файл

@ -51,6 +51,7 @@ const int kDefaultExpireDays = 9;
- (void)doClearDiskCache;
- (void)doClearGlobalHistory;
- (BOOL)historyDaysValid;
@end
@ -80,25 +81,47 @@ const int kDefaultExpireDays = 9;
[textFieldHistoryDays setIntValue:expireDays];
}
- (NSPreferencePaneUnselectReply)shouldUnselect
{
// make sure the history days value is numbers only (should use a formatter for this?)
if (![self historyDaysValid])
{
[[textFieldHistoryDays window] makeFirstResponder:textFieldHistoryDays];
[textFieldHistoryDays selectText:nil];
NSBeep();
return NSUnselectCancel;
}
return NSUnselectNow;
}
- (void)didUnselect
{
if (!mPrefService)
return;
if ([self historyDaysValid])
[self setPref:"browser.history_expire_days" toInt:[textFieldHistoryDays intValue]];
}
- (IBAction)historyDaysModified:(id)sender
{
if (!mPrefService)
return;
if (sender == textFieldHistoryDays) {
// If any non-numeric characters were entered make some noise and spit it out.
if (([[textFieldHistoryDays stringValue] rangeOfCharacterFromSet:[[NSCharacterSet decimalDigitCharacterSet] invertedSet]]).length) {
BOOL gotPref;
int prefValue = [self getIntPref:"browser.history_expire_days" withSuccess:&gotPref];
if (!gotPref)
prefValue = kDefaultExpireDays;
[textFieldHistoryDays setIntValue:prefValue];
NSBeep ();
return;
}
if ([self historyDaysValid])
{
[self setPref:"browser.history_expire_days" toInt:[sender intValue]];
}
else
{
// If any non-numeric characters were entered make some noise and spit it out.
BOOL gotPref;
int prefValue = [self getIntPref:"browser.history_expire_days" withSuccess:&gotPref];
if (!gotPref)
prefValue = kDefaultExpireDays;
[textFieldHistoryDays setIntValue:prefValue];
NSBeep();
}
[self setPref:"browser.history_expire_days" toInt:[sender intValue]];
}
// Clear the user's disk cache
@ -163,4 +186,11 @@ const int kDefaultExpireDays = 9;
hist->RemoveAllPages();
}
- (BOOL)historyDaysValid
{
NSCharacterSet* nonDigitsSet = [[NSCharacterSet decimalDigitCharacterSet] invertedSet];
NSRange nonDigitsRange = [[textFieldHistoryDays stringValue] rangeOfCharacterFromSet:nonDigitsSet];
return (nonDigitsRange.length == 0);
}
@end

Просмотреть файл

@ -223,6 +223,10 @@ static NSString* const CacheInfoPaneSeenKey = @"MVPreferencePaneSeen"; // N
mCloseWhenPaneIsReady = NO;
[mPendingPaneIdentifier autorelease];
mPendingPaneIdentifier = [identifier retain];
// set the selected toolbar item back
if ([NSToolbar instancesRespondToSelector:@selector(setSelectedItemIdentifier:)])
[[mWindow toolbar] setSelectedItemIdentifier:mCurrentPaneIdentifier];
return;
}