зеркало из https://github.com/mozilla/pjs.git
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:
Родитель
09593adb0a
Коммит
8659ec4f40
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче