Fix the UI from getting into a locked state when Camino puts up sheet while there is already a modal dialog on screen, or the window already has a sheet. Fixes bugs 279350, 314072. r=mento

Fix bug 324901: hide the checkbox in prompt dialogs when the checkMsg param is null or an empty string, to match FF behaviour. r=mento.
Disable the open menu commands when the window has a sheet on it.
This commit is contained in:
smfr%smfr.org 2006-01-29 04:56:30 +00:00
Родитель 6750b03428
Коммит c2befd3b56
8 изменённых файлов: 328 добавлений и 281 удалений

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

@ -337,14 +337,20 @@ const int kReuseWindowOnAE = 2;
[NSApp activateIgnoringOtherApps:YES];
nsAlertController* controller = CHBrowserService::GetAlertController();
BOOL dontShowAgain = NO;
BOOL confirmed = [controller confirmCheckEx:nil
title:quitAlertMsg
text:quitAlertExpl
button1:NSLocalizedString(@"QuitButtonText", @"")
button2:NSLocalizedString(@"CancelButtonText", @"")
button3:nil
checkMsg:NSLocalizedString(@"QuitWithMultipleTabsCheckboxLabel", @"")
checkValue:&dontShowAgain];
BOOL confirmed = NO;
NS_DURING
confirmed = [controller confirmCheckEx:nil
title:quitAlertMsg
text:quitAlertExpl
button1:NSLocalizedString(@"QuitButtonText", @"")
button2:NSLocalizedString(@"CancelButtonText", @"")
button3:nil
checkMsg:NSLocalizedString(@"QuitWithMultipleTabsCheckboxLabel", @"")
checkValue:&dontShowAgain];
NS_HANDLER
NS_ENDHANDLER
if (dontShowAgain)
[prefManager setPref:"camino.warn_when_closing" toBoolean:NO];
@ -462,15 +468,20 @@ const int kReuseWindowOnAE = 2;
{
nsAlertController* controller = [[nsAlertController alloc] init];
BOOL dontAskAgain = NO;
int result = [controller confirmCheckEx:nil // parent
title:NSLocalizedString(@"DefaultBrowserTitle", nil)
text:NSLocalizedString(@"DefaultBrowserMessage", nil)
button1:NSLocalizedString(@"DefaultBrowserAcceptButton", nil)
button2:NSLocalizedString(@"DefaultBrowserDenyButton", nil)
button3:nil
checkMsg:NSLocalizedString(@"DefaultBrowserChecboxTitle", nil)
checkValue:&dontAskAgain];
int result = NSAlertErrorReturn;
NS_DURING
result = [controller confirmCheckEx:nil // parent
title:NSLocalizedString(@"DefaultBrowserTitle", nil)
text:NSLocalizedString(@"DefaultBrowserMessage", nil)
button1:NSLocalizedString(@"DefaultBrowserAcceptButton", nil)
button2:NSLocalizedString(@"DefaultBrowserDenyButton", nil)
button3:nil
checkMsg:NSLocalizedString(@"DefaultBrowserChecboxTitle", nil)
checkValue:&dontAskAgain];
NS_HANDLER
NS_ENDHANDLER
if (result == NSAlertDefaultReturn)
{
[[NSWorkspace sharedWorkspace] setDefaultBrowserWithIdentifier:myIdentifier];
@ -1403,6 +1414,12 @@ Otherwise, we return the URL we originally got. Right now this supports .url and
return (![browserController bookmarkManagerIsVisible]);
return NO;
}
// disable open menu items if a sheet is up (maybe disable others too)
if (action == @selector(openFile:) ||
action == @selector(openLocation:)) {
return (!browserController || [[browserController window] attachedSheet] == nil);
}
// check what the state of the personal toolbar should be, but only if there is a browser
// window open. Popup windows that have the personal toolbar removed should always gray

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

@ -596,16 +596,22 @@ enum BWCOpenDest {
nsAlertController* controller = CHBrowserService::GetAlertController();
BOOL dontShowAgain = NO;
// note that this is a pseudo-sheet (and causes Cocoa to complain about runModalForWindow:relativeToWindow).
// Ideally, we'd be able to get a panel from nsAlertController and run it as a sheet ourselves.
int result = [controller confirmCheckEx:[self window]
title:NSLocalizedString(@"CloseWindowWithMultipleTabsMsg", @"")
text:[NSString stringWithFormat:closeMultipleTabWarning, numberOfTabs]
button1:NSLocalizedString(@"CloseWindowWithMultipleTabsButton", @"")
button2:NSLocalizedString(@"CancelButtonText", @"")
button3:nil
checkMsg:NSLocalizedString(@"CloseWindowWithMultipleTabsCheckboxLabel", @"")
checkValue:&dontShowAgain];
int result = NSAlertErrorReturn;
NS_DURING
// note that this is a pseudo-sheet (and causes Cocoa to complain about runModalForWindow:relativeToWindow).
// Ideally, we'd be able to get a panel from nsAlertController and run it as a sheet ourselves.
result = [controller confirmCheckEx:[self window]
title:NSLocalizedString(@"CloseWindowWithMultipleTabsMsg", @"")
text:[NSString stringWithFormat:closeMultipleTabWarning, numberOfTabs]
button1:NSLocalizedString(@"CloseWindowWithMultipleTabsButton", @"")
button2:NSLocalizedString(@"CancelButtonText", @"")
button3:nil
checkMsg:NSLocalizedString(@"CloseWindowWithMultipleTabsCheckboxLabel", @"")
checkValue:&dontShowAgain];
NS_HANDLER
NS_ENDHANDLER
if (dontShowAgain)
[[PreferenceManager sharedInstance] setPref:"camino.warn_when_closing" toBoolean:NO];

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

@ -827,16 +827,22 @@ static NSString* const kOfflineNotificationName = @"offlineModeChanged";
// A popup is being opened while the page is currently loading. Offer to block the
// popup.
nsAlertController* controller = CHBrowserService::GetAlertController();
BOOL confirm = [controller confirm: [self window] title: NSLocalizedString(@"PopupBlockTitle",@"")
text: [NSString stringWithFormat: NSLocalizedString(@"PopupBlockMsg", @""), NSLocalizedStringFromTable(@"CFBundleName", @"InfoPlist", nil)]];
BOOL confirm = NO;
NS_DURING
confirm = [controller confirm:[self window]
title:NSLocalizedString(@"PopupBlockTitle",@"")
text:[NSString stringWithFormat:NSLocalizedString(@"PopupBlockMsg", @""), NSLocalizedStringFromTable(@"CFBundleName", @"InfoPlist", nil)]];
// This is a one-time dialog.
[[PreferenceManager sharedInstance] setPref:"browser.popups.showPopupBlocker" toBoolean:NO];
// This is a one-time dialog.
[[PreferenceManager sharedInstance] setPref:"browser.popups.showPopupBlocker" toBoolean:NO];
NS_HANDLER
NS_ENDHANDLER
if (confirm)
[[PreferenceManager sharedInstance] setPref:"dom.disable_open_during_load" toBoolean:YES];
[[PreferenceManager sharedInstance] savePrefsFile];
[[PreferenceManager sharedInstance] savePrefsFile]; // really necessary?
if (confirm)
return nil;

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

@ -72,10 +72,18 @@ CocoaPromptService::Alert(nsIDOMWindow *parent,
CHBrowserView* browserView = [CHBrowserView browserViewFromDOMWindow:parent];
[browserView doBeforePromptDisplay];
[controller alert:[browserView getNativeWindow] title:titleStr text:textStr];
nsresult rv = NS_OK;
NS_DURING
[controller alert:[browserView getNativeWindow] title:titleStr text:textStr];
NS_HANDLER
rv = NS_ERROR_FAILURE;
NS_ENDHANDLER
[browserView doAfterPromptDismissal];
return NS_OK;
return rv;
}
/* void alertCheck (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text, in wstring checkMsg, inout boolean checkValue); */
@ -93,23 +101,29 @@ CocoaPromptService::AlertCheck(nsIDOMWindow *parent,
NSString* titleStr = [NSString stringWithPRUnichars:dialogTitle];
NSString* textStr = [NSString stringWithPRUnichars:text];
NSString* msgStr = [NSString stringWithPRUnichars:checkMsg];
CHBrowserView* browserView = [CHBrowserView browserViewFromDOMWindow:parent];
[browserView doBeforePromptDisplay];
if (checkValue) {
BOOL valueBool = *checkValue ? YES : NO;
[controller alertCheck:[browserView getNativeWindow] title:titleStr text:textStr checkMsg:msgStr checkValue:&valueBool];
*checkValue = (valueBool == YES) ? PR_TRUE : PR_FALSE;
}
else {
[controller alert:[browserView getNativeWindow] title:titleStr text:textStr];
}
nsresult rv = NS_OK;
NS_DURING
// only show the checkbox if we have an out param and string for it
if (checkValue && checkMsg && *checkMsg) {
NSString* msgStr = [NSString stringWithPRUnichars:checkMsg];
BOOL valueBool = *checkValue ? YES : NO;
[controller alertCheck:[browserView getNativeWindow] title:titleStr text:textStr checkMsg:msgStr checkValue:&valueBool];
*checkValue = (valueBool == YES) ? PR_TRUE : PR_FALSE;
}
else {
[controller alert:[browserView getNativeWindow] title:titleStr text:textStr];
}
NS_HANDLER
rv = NS_ERROR_FAILURE;
NS_ENDHANDLER
[browserView doAfterPromptDismissal];
return NS_OK;
return rv;
}
/* boolean confirm (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text); */
@ -129,10 +143,17 @@ CocoaPromptService::Confirm(nsIDOMWindow *parent,
CHBrowserView* browserView = [CHBrowserView browserViewFromDOMWindow:parent];
[browserView doBeforePromptDisplay];
*_retval = (PRBool)[controller confirm:[browserView getNativeWindow] title:titleStr text:textStr];
nsresult rv = NS_OK;
NS_DURING
*_retval = (PRBool)[controller confirm:[browserView getNativeWindow] title:titleStr text:textStr];
NS_HANDLER
rv = NS_ERROR_FAILURE;
NS_ENDHANDLER
[browserView doAfterPromptDismissal];
return NS_OK;
return rv;
}
/* boolean confirmCheck (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text, in wstring checkMsg, inout boolean checkValue); */
@ -150,23 +171,29 @@ CocoaPromptService::ConfirmCheck(nsIDOMWindow *parent,
NSString* titleStr = [NSString stringWithPRUnichars:dialogTitle];
NSString* textStr = [NSString stringWithPRUnichars:text];
NSString* msgStr = [NSString stringWithPRUnichars:checkMsg];
CHBrowserView* browserView = [CHBrowserView browserViewFromDOMWindow:parent];
[browserView doBeforePromptDisplay];
if (checkValue) {
BOOL valueBool = *checkValue ? YES : NO;
*_retval = (PRBool)[controller confirmCheck:[browserView getNativeWindow] title:titleStr text:textStr checkMsg:msgStr checkValue:&valueBool];
*checkValue = (valueBool == YES) ? PR_TRUE : PR_FALSE;
}
else {
*_retval = (PRBool)[controller confirm:[browserView getNativeWindow] title:titleStr text:textStr];
}
nsresult rv = NS_OK;
NS_DURING
// only show the checkbox if we have an out param and string for it
if (checkValue && checkMsg && *checkMsg) {
NSString* msgStr = [NSString stringWithPRUnichars:checkMsg];
BOOL valueBool = *checkValue ? YES : NO;
*_retval = (PRBool)[controller confirmCheck:[browserView getNativeWindow] title:titleStr text:textStr checkMsg:msgStr checkValue:&valueBool];
*checkValue = (valueBool == YES) ? PR_TRUE : PR_FALSE;
}
else {
*_retval = (PRBool)[controller confirm:[browserView getNativeWindow] title:titleStr text:textStr];
}
NS_HANDLER
rv = NS_ERROR_FAILURE;
NS_ENDHANDLER
[browserView doAfterPromptDismissal];
return NS_OK;
return rv;
}
// these constants are used for identifying the buttons and are intentionally overloaded to
@ -195,7 +222,6 @@ CocoaPromptService::ConfirmEx(nsIDOMWindow *parent,
NSString* titleStr = [NSString stringWithPRUnichars:dialogTitle];
NSString* textStr = [NSString stringWithPRUnichars:text];
NSString* msgStr = [NSString stringWithPRUnichars:checkMsg];
NSString* btn1Str = GetButtonStringFromFlags(buttonFlags, kButton0, button0Title);
NSString* btn2Str = GetButtonStringFromFlags(buttonFlags, kButton1, button1Title);
@ -204,31 +230,38 @@ CocoaPromptService::ConfirmEx(nsIDOMWindow *parent,
CHBrowserView* browserView = [CHBrowserView browserViewFromDOMWindow:parent];
[browserView doBeforePromptDisplay];
int result;
if (checkValue) {
BOOL valueBool = *checkValue ? YES : NO;
nsresult rv = NS_OK;
NS_DURING
int result;
// only show the checkbox if we have an out param and string for it
if (checkValue && checkMsg && *checkMsg) {
NSString* msgStr = [NSString stringWithPRUnichars:checkMsg];
BOOL valueBool = *checkValue ? YES : NO;
result = [controller confirmCheckEx:[browserView getNativeWindow] title:titleStr text:textStr
button1: btn1Str button2: btn2Str button3: btn3Str
checkMsg:msgStr checkValue:&valueBool];
*checkValue = (valueBool == YES) ? PR_TRUE : PR_FALSE;
}
else {
result = [controller confirmEx:[browserView getNativeWindow] title:titleStr text:textStr
button1: btn1Str button2: btn2Str button3: btn3Str];
}
result = [controller confirmCheckEx:[browserView getNativeWindow] title:titleStr text:textStr
button1: btn1Str button2: btn2Str button3: btn3Str
checkMsg:msgStr checkValue:&valueBool];
*checkValue = (valueBool == YES) ? PR_TRUE : PR_FALSE;
}
else {
result = [controller confirmEx:[browserView getNativeWindow] title:titleStr text:textStr
button1: btn1Str button2: btn2Str button3: btn3Str];
}
switch (result)
{
case NSAlertDefaultReturn: *buttonPressed = 0; break;
default:
case NSAlertAlternateReturn: *buttonPressed = 1; break;
case NSAlertOtherReturn: *buttonPressed = 2; break;
}
switch (result)
{
case NSAlertDefaultReturn: *buttonPressed = 0; break;
default:
case NSAlertAlternateReturn: *buttonPressed = 1; break;
case NSAlertOtherReturn: *buttonPressed = 2; break;
}
NS_HANDLER
rv = NS_ERROR_FAILURE;
NS_ENDHANDLER
[browserView doAfterPromptDismissal];
return NS_OK;
return rv;
}
@ -261,23 +294,39 @@ CocoaPromptService::Prompt(nsIDOMWindow *parent,
CHBrowserView* browserView = [CHBrowserView browserViewFromDOMWindow:parent];
[browserView doBeforePromptDisplay];
*_retval = (PRBool)[controller prompt:[browserView getNativeWindow] title:titleStr text:textStr promptText:valueStr checkMsg:msgStr checkValue:&valueBool doCheck:(checkValue != nsnull)];
nsresult rv = NS_OK;
NS_DURING
// only show the checkbox if we have a string for it
*_retval = (PRBool)[controller prompt:[browserView getNativeWindow]
title:titleStr
text:textStr
promptText:valueStr
checkMsg:msgStr
checkValue:&valueBool
doCheck:(checkMsg && *checkMsg)];
NS_HANDLER
rv = NS_ERROR_FAILURE;
NS_ENDHANDLER
[browserView doAfterPromptDismissal];
// the caller only cares about |value| and |checkValue| if |_retval|
// is something other than cancel. If it is, we'd leak any string we allocated
// to fill in |value|.
if (*_retval) {
if (checkValue) {
*checkValue = (valueBool == YES) ? PR_TRUE : PR_FALSE;
if (NS_SUCCEEDED(rv)) {
// the caller only cares about |value| and |checkValue| if |_retval|
// is something other than cancel. If it is, we'd leak any string we allocated
// to fill in |value|.
if (*_retval) {
if (checkValue) {
*checkValue = (valueBool == YES) ? PR_TRUE : PR_FALSE;
}
*value = [valueStr createNewUnicodeBuffer];
}
*value = [valueStr createNewUnicodeBuffer];
else
*value = nsnull;
}
else
*value = nsnull;
return NS_OK;
return rv;
}
/* boolean promptUsernameAndPassword (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text, inout wstring username, inout wstring password, in wstring checkMsg, inout boolean checkValue); */
@ -302,31 +351,48 @@ CocoaPromptService::PromptUsernameAndPassword(nsIDOMWindow *parent,
NSMutableString* userNameStr = [NSMutableString stringWithPRUnichars:*username];
NSMutableString* passwordStr = [NSMutableString stringWithPRUnichars:*password];
BOOL valueBool;
BOOL valueBool = NO;
if (checkValue) {
valueBool = *checkValue ? YES : NO;
}
CHBrowserView* browserView = [CHBrowserView browserViewFromDOMWindow:parent];
[browserView doBeforePromptDisplay];
*_retval = (PRBool)[controller promptUserNameAndPassword:[browserView getNativeWindow] title:titleStr text:textStr userNameText:userNameStr passwordText:passwordStr checkMsg:msgStr checkValue:&valueBool doCheck:(checkValue != nsnull)];
nsresult rv = NS_OK;
NS_DURING
// only show the checkbox if we have a string for it
*_retval = (PRBool)[controller promptUserNameAndPassword:[browserView getNativeWindow]
title:titleStr
text:textStr
userNameText:userNameStr
passwordText:passwordStr
checkMsg:msgStr
checkValue:&valueBool
doCheck:(checkMsg && *checkMsg)];
NS_HANDLER
rv = NS_ERROR_FAILURE;
NS_ENDHANDLER
[browserView doAfterPromptDismissal];
// the caller only cares about |username|, |password|, and |checkValue| if |_retval|
// is something other than cancel. If it is, we'd leak any string we allocated
// to fill in |value|.
if (*_retval) {
if (checkValue)
*checkValue = (valueBool == YES) ? PR_TRUE : PR_FALSE;
if (NS_SUCCEEDED(rv)) {
// the caller only cares about |username|, |password|, and |checkValue| if |_retval|
// is something other than cancel. If it is, we'd leak any string we allocated
// to fill in |value|.
if (*_retval) {
if (checkValue)
*checkValue = (valueBool == YES) ? PR_TRUE : PR_FALSE;
*username = [userNameStr createNewUnicodeBuffer];
*password = [passwordStr createNewUnicodeBuffer];
} else {
*username = nsnull;
*password = nsnull;
}
*username = [userNameStr createNewUnicodeBuffer];
*password = [passwordStr createNewUnicodeBuffer];
} else {
*username = nsnull;
*password = nsnull;
}
}
return NS_OK;
return rv;
}
/* boolean promptPassword (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text, inout wstring password, in wstring checkMsg, inout boolean checkValue); */
@ -349,29 +415,44 @@ CocoaPromptService::PromptPassword(nsIDOMWindow *parent,
NSString* msgStr = [NSString stringWithPRUnichars:checkMsg];
NSMutableString* passwordStr = [NSMutableString stringWithPRUnichars:*password];
BOOL valueBool;
BOOL valueBool = NO;
if (checkValue) {
valueBool = *checkValue ? YES : NO;
}
CHBrowserView* browserView = [CHBrowserView browserViewFromDOMWindow:parent];
[browserView doBeforePromptDisplay];
*_retval = (PRBool)[controller promptPassword:[browserView getNativeWindow] title:titleStr text:textStr passwordText:passwordStr checkMsg:msgStr checkValue:&valueBool doCheck:(checkValue != nsnull)];
nsresult rv = NS_OK;
NS_DURING
// only show the checkbox if we have a string for it
*_retval = (PRBool)[controller promptPassword:[browserView getNativeWindow]
title:titleStr
text:textStr
passwordText:passwordStr
checkMsg:msgStr
checkValue:&valueBool
doCheck:(checkMsg && *checkMsg)];
NS_HANDLER
rv = NS_ERROR_FAILURE;
NS_ENDHANDLER
[browserView doAfterPromptDismissal];
// the caller only cares about |password| and |checkValue| if |_retval|
// is something other than cancel. If it is, we'd leak any string we allocated
// to fill in |value|.
if (*_retval) {
if (checkValue)
*checkValue = (valueBool == YES) ? PR_TRUE : PR_FALSE;
if (NS_SUCCEEDED(rv)) {
// the caller only cares about |password| and |checkValue| if |_retval|
// is something other than cancel. If it is, we'd leak any string we allocated
// to fill in |value|.
if (*_retval) {
if (checkValue)
*checkValue = (valueBool == YES) ? PR_TRUE : PR_FALSE;
*password = [passwordStr createNewUnicodeBuffer];
*password = [passwordStr createNewUnicodeBuffer];
}
else
*password = nsnull;
}
else
*password = nsnull;
return NS_OK;
return rv;
}
/* boolean select (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text, in PRUint32 count, [array, size_is (count)] in wstring selectList, out long outSelection); */
@ -390,6 +471,8 @@ CocoaPromptService::Select(nsIDOMWindow *parent,
return NS_ERROR_NOT_IMPLEMENTED;
}
#pragma mark -
NSString *
CocoaPromptService::GetCommonDialogLocaleString(const char *key)
{

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

@ -248,21 +248,32 @@ NS_IMETHODIMP SecurityDialogs::GetPKCS12FilePassword(nsIInterfaceRequestor *ctx,
// XXX ideally we should use a custom dialog here, following the recommendations above.
NSMutableString* thePassword = [[NSMutableString alloc] init];
BOOL confirmed = [controller promptPassword:nil /* no parent, sucky APIs */
title:NSLocalizedStringFromTable(@"PKCS12BackupRestoreTitle", @"CertificateDialogs", @"")
text:NSLocalizedStringFromTable(@"PKCS12BackupRestoreMsg", @"CertificateDialogs", @"")
passwordText:thePassword
checkMsg:nil
checkValue:NULL
doCheck:NO];
*_retval = confirmed;
BOOL confirmed = NO;
nsresult rv = NS_OK;
NS_DURING
confirmed = [controller promptPassword:nil /* no parent, sucky APIs */
title:NSLocalizedStringFromTable(@"PKCS12BackupRestoreTitle", @"CertificateDialogs", @"")
text:NSLocalizedStringFromTable(@"PKCS12BackupRestoreMsg", @"CertificateDialogs", @"")
passwordText:thePassword
checkMsg:nil
checkValue:NULL
doCheck:NO];
NS_HANDLER
rv = NS_ERROR_FAILURE;
NS_ENDHANDLER
if (confirmed)
[thePassword assignTo_nsAString:password];
if (NS_SUCCEEDED(rv))
{
*_retval = confirmed;
if (confirmed)
[thePassword assignTo_nsAString:password];
}
[thePassword release];
return NS_OK;
return rv;
}
/**
@ -690,25 +701,35 @@ SecurityDialogs::GetPassword(nsIInterfaceRequestor *ctx, const PRUnichar *tokenN
NSString* msgFormat = NSLocalizedStringFromTable(@"GetTokenPasswordTitle", @"CertificateDialogs", @"");
NSString* messageStr = [NSString stringWithFormat:msgFormat, [NSString stringWithPRUnichars:tokenName]];
BOOL confirmed = [controller promptPassword:nil /* no parent, sucky APIs */
title:messageStr
text:NSLocalizedStringFromTable(@"GetTokenPasswordMsg", @"CertificateDialogs", @"")
passwordText:thePassword
checkMsg:nil
checkValue:NULL
doCheck:NO];
if (confirmed)
{
*password = [thePassword createNewUnicodeBuffer];
*canceled = YES;
BOOL confirmed = NO;
nsresult rv = NS_OK;
NS_DURING
confirmed = [controller promptPassword:nil /* no parent, sucky APIs */
title:messageStr
text:NSLocalizedStringFromTable(@"GetTokenPasswordMsg", @"CertificateDialogs", @"")
passwordText:thePassword
checkMsg:nil
checkValue:NULL
doCheck:NO];
NS_HANDLER
rv = NS_ERROR_FAILURE;
NS_ENDHANDLER
if (NS_SUCCEEDED(rv))
{
if (confirmed)
{
*password = [thePassword createNewUnicodeBuffer];
*canceled = YES;
}
else
*canceled = YES;
}
else
*canceled = YES;
[thePassword release];
return NS_OK;
return rv;
}
/**

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

@ -46,6 +46,10 @@
- (IBAction)hitButton2:(id)sender;
- (IBAction)hitButton3:(id)sender;
//
// Nota Bene: all of these methods can throw Objective-C exceptions
// if there was an error displaying the dialog.
//
- (void)alert:(NSWindow*)parent title:(NSString*)title text:(NSString*)text;
- (void)alertCheck:(NSWindow*)parent title:(NSString*)title text:(NSString*)text checkMsg:(NSString*)checkMsg checkValue:(BOOL*)checkValue;
@ -65,8 +69,4 @@
- (BOOL)postToInsecureFromSecure:(NSWindow*)parent;
- (BOOL)badCert:(NSWindow*)parent;
- (BOOL)expiredCert:(NSWindow*)parent;
- (int)unknownCert:(NSWindow*)parent;
@end

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

@ -38,7 +38,6 @@
#import "nsAlertController.h"
#import "CHBrowserService.h"
const int kMinDialogWidth = 500;
const int kMaxDialogHeight = 400;
const int kMinDialogHeight = 130;
@ -87,6 +86,8 @@ const int kLabelCheckboxAdjustment = 2; // # pixels the label must be pushed dow
@interface nsAlertController (nsAlertControllerPrivateMethods)
- (int)runModalWindow:(NSWindow*)inDialog relativeToWindow:(NSWindow*)inParentWindow;
- (NSPanel*)getAlertPanelWithTitle:(NSString*)title
message:(NSString*)message
defaultButton:(NSString*)defaultLabel
@ -132,10 +133,7 @@ const int kLabelCheckboxAdjustment = 2; // # pixels the label must be pushed dow
- (void)alert:(NSWindow*)parent title:(NSString*)title text:(NSString*)text
{
NSPanel* panel = [self getAlertPanelWithTitle: title message: text defaultButton: NSLocalizedString(@"OKButtonText", @"") altButton: nil otherButton: nil extraView: nil lastResponder:nil];
if (parent)
[NSApp runModalForWindow:panel relativeToWindow:parent];
else
[NSApp runModalForWindow:panel];
[self runModalWindow:panel relativeToWindow:parent];
[panel close];
}
@ -152,10 +150,7 @@ const int kLabelCheckboxAdjustment = 2; // # pixels the label must be pushed dow
NSPanel* panel = [self getAlertPanelWithTitle: title message: text defaultButton: NSLocalizedString(@"OKButtonText", @"") altButton: nil otherButton: nil extraView: checkboxView lastResponder: checkBox];
[panel setInitialFirstResponder: checkBox];
if (parent)
[NSApp runModalForWindow:panel relativeToWindow:parent];
else
[NSApp runModalForWindow:panel];
[self runModalWindow:panel relativeToWindow:parent];
*checkValue = ([checkBox state] == NSOnState);
[panel close];
@ -165,12 +160,8 @@ const int kLabelCheckboxAdjustment = 2; // # pixels the label must be pushed dow
{
NSPanel* panel = [self getAlertPanelWithTitle: title message: text defaultButton: NSLocalizedString(@"OKButtonText", @"") altButton: NSLocalizedString(@"CancelButtonText", @"") otherButton: nil extraView: nil lastResponder: nil];
int result;
if (parent)
result = [NSApp runModalForWindow:panel relativeToWindow:parent];
else
result = [NSApp runModalForWindow:panel];
int result = [self runModalWindow:panel relativeToWindow:parent];
[panel close];
return (result == NSAlertDefaultReturn);
@ -193,11 +184,7 @@ const int kLabelCheckboxAdjustment = 2; // # pixels the label must be pushed dow
NSPanel* panel = [self getAlertPanelWithTitle: title message: text defaultButton: okButton altButton: cancelButton otherButton: nil extraView: checkboxView lastResponder: checkBox];
[panel setInitialFirstResponder: checkBox];
int result;
if (parent)
result = [NSApp runModalForWindow:panel relativeToWindow:parent];
else
result = [NSApp runModalForWindow:panel];
int result = [self runModalWindow:panel relativeToWindow:parent];
*checkValue = ([checkBox state] == NSOnState);
[panel close];
@ -209,11 +196,7 @@ const int kLabelCheckboxAdjustment = 2; // # pixels the label must be pushed dow
{
NSPanel* panel = [self getAlertPanelWithTitle: title message: text defaultButton: btn1 altButton: btn2 otherButton: btn3 extraView: nil lastResponder: nil];
int result;
if (parent)
result = [NSApp runModalForWindow:panel relativeToWindow:parent];
else
result = [NSApp runModalForWindow:panel];
int result = [self runModalWindow:panel relativeToWindow:parent];
[panel close];
return result;
@ -232,11 +215,7 @@ const int kLabelCheckboxAdjustment = 2; // # pixels the label must be pushed dow
NSPanel* panel = [self getAlertPanelWithTitle: title message: text defaultButton: btn1 altButton: btn2 otherButton: btn3 extraView: checkboxView lastResponder: checkBox];
[panel setInitialFirstResponder: checkBox];
int result;
if (parent)
result = [NSApp runModalForWindow:panel relativeToWindow:parent];
else
result = [NSApp runModalForWindow:panel];
int result = [self runModalWindow:panel relativeToWindow:parent];
*checkValue = ([checkBox state] == NSOnState);
[panel close];
@ -281,11 +260,7 @@ const int kLabelCheckboxAdjustment = 2; // # pixels the label must be pushed dow
NSPanel* panel = [self getAlertPanelWithTitle: title message: text defaultButton: okButton altButton: cancelButton otherButton: nil extraView: extraView lastResponder:lastResponder];
[panel setInitialFirstResponder: field];
int result;
if (parent)
result = [NSApp runModalForWindow:panel relativeToWindow:parent];
else
result = [NSApp runModalForWindow:panel];
int result = [self runModalWindow:panel relativeToWindow:parent];
[panel close];
@ -340,11 +315,7 @@ const int kLabelCheckboxAdjustment = 2; // # pixels the label must be pushed dow
NSPanel* panel = [self getAlertPanelWithTitle: title message: text defaultButton: okButton altButton: cancelButton otherButton: nil extraView: extraView lastResponder:lastResponder];
[panel setInitialFirstResponder: userField];
int result;
if (parent)
result = [NSApp runModalForWindow:panel relativeToWindow:parent];
else
result = [NSApp runModalForWindow:panel];
int result = [self runModalWindow:panel relativeToWindow:parent];
[panel close];
@ -391,11 +362,7 @@ const int kLabelCheckboxAdjustment = 2; // # pixels the label must be pushed dow
NSPanel* panel = [self getAlertPanelWithTitle: title message: text defaultButton: okButton altButton: cancelButton otherButton: nil extraView: extraView lastResponder:lastResponder];
[panel setInitialFirstResponder: passField];
int result;
if (parent)
result = [NSApp runModalForWindow:panel relativeToWindow:parent];
else
result = [NSApp runModalForWindow:panel];
int result = [self runModalWindow:panel relativeToWindow:parent];
[panel close];
@ -417,11 +384,7 @@ const int kLabelCheckboxAdjustment = 2; // # pixels the label must be pushed dow
id panel = NSGetAlertPanel(title, message, continueButton, stopButton, nil);
int result;
if (parent)
result = [NSApp runModalForWindow:panel relativeToWindow:parent];
else
result = [NSApp runModalForWindow:panel];
int result = [self runModalWindow:panel relativeToWindow:parent];
[panel close];
NSReleaseAlertPanel(panel);
@ -429,88 +392,33 @@ const int kLabelCheckboxAdjustment = 2; // # pixels the label must be pushed dow
return (result == NSAlertDefaultReturn);
}
- (BOOL)badCert:(NSWindow*)parent
{
NSString* title = NSLocalizedString(@"Security Warning", @"");
NSString* message = NSLocalizedString(@"Security Mismatch", @"");
NSString* continueButton = NSLocalizedString(@"ContinueButton", @"");
NSString* stopButton = NSLocalizedString(@"StopButton", @"");
id panel = NSGetAlertPanel(title, message, continueButton, stopButton, nil);
int result;
if (parent)
result = [NSApp runModalForWindow:panel relativeToWindow:parent];
else
result = [NSApp runModalForWindow:panel];
[panel close];
NSReleaseAlertPanel(panel);
return (result == NSAlertDefaultReturn);
}
- (BOOL)expiredCert:(NSWindow*)parent
{
NSString* title = NSLocalizedString(@"Security Warning", @"");
NSString* message = NSLocalizedString(@"Expired Certification", @"");
NSString* continueButton = NSLocalizedString(@"ContinueButton", @"");
NSString* stopButton = NSLocalizedString(@"StopButton", @"");
id panel = NSGetAlertPanel(title, message, continueButton, stopButton, nil);
int result;
if (parent)
result = [NSApp runModalForWindow:panel relativeToWindow:parent];
else
result = [NSApp runModalForWindow:panel];
[panel close];
NSReleaseAlertPanel(panel);
return (result == NSAlertDefaultReturn);
}
- (int)unknownCert:(NSWindow*)parent
{
// this dialog is a little backward, with "Stop" returning 0, and the default returning
// 1. That's just how nsIBadCertListener defines its constants. *shrug*
NSString* title = NSLocalizedString(@"Security Warning", @"");
NSString* message = NSLocalizedString(@"Unknown Certification", @"");
NSString* alwaysAcceptButton = NSLocalizedString(@"Accept Always", @"");
NSString* oneAcceptButton = NSLocalizedString(@"Accept Once", @"");
NSString* stopButton = NSLocalizedString(@"StopButton", @"");
id panel = NSGetAlertPanel(title, message, oneAcceptButton, stopButton, alwaysAcceptButton);
int result;
if (parent)
result = [NSApp runModalForWindow:panel relativeToWindow:parent];
else
result = [NSApp runModalForWindow:panel];
[panel close];
NSReleaseAlertPanel(panel);
int returnValue;
if (result == NSAlertDefaultReturn)
returnValue = 1;
else if (result == NSAlertOtherReturn)
returnValue = 2;
else
returnValue = 0;
return returnValue;
}
#pragma mark -
// implementation of private methods
- (int)runModalWindow:(NSWindow*)inDialog relativeToWindow:(NSWindow*)inParentWindow
{
// If there is already a modal window up, convert a sheet into a modal window,
// because AppKit will hang if you try to do this (possibly because we're using
// the deprecated and sucky runModalForWindow:relativeToWindow:).
// Also, if the parent window already has an attached sheet, also null out
// the parent and show this as a modal dialog.
if ([NSApp modalWindow] || (inParentWindow && [inParentWindow attachedSheet]))
inParentWindow = nil;
int result;
if (inParentWindow)
result = [NSApp runModalForWindow:inDialog relativeToWindow:inParentWindow];
else
result = [NSApp runModalForWindow:inDialog];
// Convert any error into an exception
if (result == NSAlertErrorReturn)
[NSException raise:NSInternalInconsistencyException format:@"-runModalForWindow returned error"];
return result;
}
// The content width is determined by how much space is needed to display all 3 buttons,
// since every other view in the dialog can wrap if necessary
- (float)getContentWidthWithDefaultButton:(NSString*)defStr alternateButton:(NSString*)altStr otherButton:(NSString*)otherStr

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

@ -386,15 +386,21 @@ static inline u_int ns_get16(u_char* buffer)
{
// get a username for ftp, since most local servers won't support anonymous login
nsAlertController* controller = CHBrowserService::GetAlertController();
BOOL checked = NO;
NSMutableString* userName = [NSMutableString string];
BOOL confirmed = [controller prompt:[NSApp mainWindow]
title:NSLocalizedString(@"UserNameRequestTitle", @"")
text:[NSString stringWithFormat:NSLocalizedString(@"UsernameRequestFormat", @""), [NSString stringWithCString:escapedTarget]]
promptText:userName
checkMsg:@"" checkValue:&checked doCheck:NO];
BOOL confirmed = NO;
NS_DURING
confirmed = [controller prompt:[NSApp mainWindow]
title:NSLocalizedString(@"UserNameRequestTitle", @"")
text:[NSString stringWithFormat:NSLocalizedString(@"UsernameRequestFormat", @""), [NSString stringWithCString:escapedTarget]]
promptText:userName
checkMsg:@""
checkValue:nsnull
doCheck:NO];
NS_HANDLER
NS_ENDHANDLER
if (!confirmed)
return; // fix