зеркало из https://github.com/mozilla/pjs.git
a bunch of fixes that didn't land when i wanted them to.
This commit is contained in:
Родитель
a88dfa28c8
Коммит
62050bae9a
|
@ -453,22 +453,47 @@ static const char* ioServiceContractID = "@mozilla.org/network/io-service;1";
|
|||
-(BOOL)validateMenuItem: (NSMenuItem*)aMenuItem
|
||||
{
|
||||
// disable items that aren't relevant if there's no main browser window open
|
||||
if ([aMenuItem action] == @selector(newTab:) ||
|
||||
SEL action = [aMenuItem action];
|
||||
if (action == @selector(newTab:) ||
|
||||
/* ... many more items go here ... */
|
||||
[aMenuItem action] == @selector(savePage:)) {
|
||||
action == @selector(printPage:) ||
|
||||
action == @selector(findInPage:) ||
|
||||
action == @selector(findAgain:) ||
|
||||
action == @selector(toggleBookmarksToolbar:) ||
|
||||
action == @selector(doStop:) ||
|
||||
action == @selector(doReload:) ||
|
||||
action == @selector(biggerTextSize:) ||
|
||||
action == @selector(smallerTextSize:) ||
|
||||
action == @selector(viewSource:) ||
|
||||
action == @selector(goHome:) ||
|
||||
action == @selector(addBookmark:) || // doesn't work, not sure why
|
||||
action == @selector(savePage:)) {
|
||||
if ([[[mApplication mainWindow] windowController] isMemberOfClass:[BrowserWindowController class]])
|
||||
return YES;
|
||||
return NO;
|
||||
}
|
||||
|
||||
// only activate if we've got multiple tabs open.
|
||||
if (([aMenuItem action] == @selector(closeTab:) ||
|
||||
[aMenuItem action] == @selector (nextTab:) ||
|
||||
[aMenuItem action] == @selector (previousTab:))) {
|
||||
if ((action == @selector(closeTab:) ||
|
||||
action == @selector (nextTab:) ||
|
||||
action == @selector (previousTab:))) {
|
||||
if ([[[[mApplication mainWindow] windowController] getTabBrowser] numberOfTabViewItems] > 1)
|
||||
return YES;
|
||||
return NO;
|
||||
}
|
||||
|
||||
if ( action == @selector(goBack:) || action == @selector(goForward:) ) {
|
||||
NSWindow* mainWindow = [mApplication mainWindow];
|
||||
if (mainWindow) {
|
||||
if (action == @selector(goBack:))
|
||||
return [[[[mainWindow windowController] getBrowserWrapper] getBrowserView] canGoBack];
|
||||
if (action == @selector(goForward:))
|
||||
return [[[[mainWindow windowController] getBrowserWrapper] getBrowserView] canGoForward];
|
||||
}
|
||||
else
|
||||
return NO;
|
||||
}
|
||||
|
||||
// default return
|
||||
return YES;
|
||||
}
|
||||
|
|
|
@ -37,11 +37,11 @@
|
|||
// Hookup cookie prefs. Relies on the tags of the radio buttons in the matrix being
|
||||
// set such that "enable all" is 0 and "disable all" is 2.
|
||||
PRInt32 acceptCookies = 0;
|
||||
mPrefService->GetIntPref("network.accept_cookies", &acceptCookies);
|
||||
mPrefService->GetIntPref("network.cookie.cookieBehavior", &acceptCookies);
|
||||
if ( acceptCookies == 1 ) // be safe in case of importing a mozilla profile
|
||||
acceptCookies = 2;
|
||||
if ( [mCookies selectCellWithTag:acceptCookies] != YES )
|
||||
NS_WARNING("Bad value for network.accept_cookies");
|
||||
NS_WARNING("Bad value for network.cookie.cookieBehavior");
|
||||
|
||||
PRBool warnAboutCookies = PR_TRUE;
|
||||
mPrefService->GetBoolPref("network.cookie.warnAboutCookies", &warnAboutCookies);
|
||||
|
@ -103,7 +103,7 @@
|
|||
{
|
||||
if ( !mPrefService )
|
||||
return;
|
||||
mPrefService->SetIntPref("network.accept_cookies", [[mCookies selectedCell] tag]);
|
||||
mPrefService->SetIntPref("network.cookie.cookieBehavior", [[mCookies selectedCell] tag]);
|
||||
}
|
||||
|
||||
//
|
||||
|
|
|
@ -118,16 +118,40 @@
|
|||
- (int)confirmEx:(NSWindow*)parent title:(NSString*)title text:(NSString*)text
|
||||
button1:(NSString*)btn1 button2:(NSString*)btn2 button3:(NSString*)btn3
|
||||
{
|
||||
printf("ConfirmEx invoked, and this is not yet implemented!\n");
|
||||
return 0;
|
||||
[confirmPanelText setStringValue:text];
|
||||
[confirmPanel setTitle:title];
|
||||
|
||||
[confirmPanelButton1 setTitle:btn1];
|
||||
[confirmPanelButton2 setTitle:btn2];
|
||||
[confirmPanelButton3 setTitle:btn3];
|
||||
|
||||
int result = [NSApp runModalForWindow:confirmPanel relativeToWindow:parent];
|
||||
|
||||
[confirmPanel close];
|
||||
|
||||
return (result == 1);
|
||||
}
|
||||
|
||||
- (int)confirmCheckEx:(NSWindow*)parent title:(NSString*)title text:(NSString*)text
|
||||
button1:(NSString*)btn1 button2:(NSString*)btn2 button3:(NSString*)btn3
|
||||
checkMsg:(NSString*)checkMsg checkValue:(BOOL*)checkValue
|
||||
{
|
||||
printf("ConfirmCheckEx invoked, and this is not yet implemented!\n");
|
||||
return 0;
|
||||
[confirmCheckPanelText setStringValue:text];
|
||||
[confirmCheckPanel setTitle:title];
|
||||
int state = (*checkValue ? NSOnState : NSOffState);
|
||||
[confirmCheckPanelCheck setState:state];
|
||||
[confirmCheckPanelCheck setTitle:checkMsg];
|
||||
|
||||
[confirmCheckPanelButton1 setTitle:btn1];
|
||||
[confirmCheckPanelButton2 setTitle:btn2];
|
||||
[confirmCheckPanelButton3 setTitle:btn3];
|
||||
|
||||
int result = [NSApp runModalForWindow:confirmCheckPanel relativeToWindow:parent];
|
||||
|
||||
*checkValue = ([confirmCheckPanelCheck state] == NSOnState);
|
||||
[confirmCheckPanel close];
|
||||
|
||||
return (result == 1);
|
||||
}
|
||||
|
||||
- (BOOL)prompt:(NSWindow*)parent title:(NSString*)title text:(NSString*)text promptText:(NSMutableString*)promptText checkMsg:(NSString*)checkMsg checkValue:(BOOL*)checkValue doCheck:(BOOL)doCheck
|
||||
|
|
|
@ -81,6 +81,11 @@ private:
|
|||
const PRUnichar *messageName,
|
||||
const PRUnichar *showAgainName);
|
||||
|
||||
NSString *GetCommonDialogLocaleString(const char *s);
|
||||
NSString *GetButtonStringFromFlags(PRUint32 btnFlags, PRUint32 btnIDAndShift,
|
||||
const PRUnichar *btnTitle);
|
||||
|
||||
nsCOMPtr<nsIStringBundle> mCommonDialogStringBundle;
|
||||
nsCOMPtr<nsIStringBundle> mSecurityStringBundle;
|
||||
|
||||
static nsCocoaBrowserService* sSingleton;
|
||||
|
|
|
@ -315,6 +315,72 @@ nsCocoaBrowserService::ConfirmCheck(nsIDOMWindow *parent,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NSString *
|
||||
nsCocoaBrowserService::GetCommonDialogLocaleString(const char *key)
|
||||
{
|
||||
NSString *returnValue = @"";
|
||||
|
||||
nsresult rv;
|
||||
if (!mCommonDialogStringBundle) {
|
||||
#define kCommonDialogsStrings "chrome://global/locale/commonDialogs.properties"
|
||||
nsCOMPtr<nsIStringBundleService> service = do_GetService(NS_STRINGBUNDLE_CONTRACTID);
|
||||
if ( service )
|
||||
rv = service->CreateBundle(kCommonDialogsStrings, getter_AddRefs(mCommonDialogStringBundle));
|
||||
else
|
||||
rv = NS_ERROR_FAILURE;
|
||||
if (NS_FAILED(rv)) return returnValue;
|
||||
}
|
||||
|
||||
nsXPIDLString string;
|
||||
rv = mCommonDialogStringBundle->GetStringFromName(NS_ConvertASCIItoUCS2(key).get(), getter_Copies(string));
|
||||
if (NS_FAILED(rv)) return returnValue;
|
||||
|
||||
returnValue = [NSString stringWithCharacters:string length:(string ? nsCRT::strlen(string) : 0)];
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
NSString *
|
||||
nsCocoaBrowserService::GetButtonStringFromFlags(PRUint32 btnFlags,
|
||||
PRUint32 btnIDAndShift,
|
||||
const PRUnichar *btnTitle)
|
||||
{
|
||||
NSString *btnStr = nsnull;
|
||||
switch ((btnFlags >> btnIDAndShift) & 0xff) {
|
||||
case BUTTON_TITLE_OK:
|
||||
btnStr = GetCommonDialogLocaleString("OK");
|
||||
break;
|
||||
case BUTTON_TITLE_CANCEL:
|
||||
btnStr = GetCommonDialogLocaleString("Cancel");
|
||||
break;
|
||||
case BUTTON_TITLE_YES:
|
||||
btnStr = GetCommonDialogLocaleString("Yes");
|
||||
break;
|
||||
case BUTTON_TITLE_NO:
|
||||
btnStr = GetCommonDialogLocaleString("No");
|
||||
break;
|
||||
case BUTTON_TITLE_SAVE:
|
||||
btnStr = GetCommonDialogLocaleString("Save");
|
||||
break;
|
||||
case BUTTON_TITLE_DONT_SAVE:
|
||||
btnStr = GetCommonDialogLocaleString("DontSave");
|
||||
break;
|
||||
case BUTTON_TITLE_REVERT:
|
||||
btnStr = GetCommonDialogLocaleString("Revert");
|
||||
break;
|
||||
case BUTTON_TITLE_IS_STRING:
|
||||
btnStr = [NSString stringWithCharacters:btnTitle length:(btnTitle ? nsCRT::strlen(btnTitle) : 0)];
|
||||
}
|
||||
|
||||
return btnStr;
|
||||
}
|
||||
|
||||
// these constants are used for identifying the buttons and are intentionally overloaded to
|
||||
// correspond to the number of bits needed for shifting to obtain the flags for a particular
|
||||
// button (should be defined in nsIPrompt*.idl instead of here)
|
||||
const PRUint32 kButton0 = 0;
|
||||
const PRUint32 kButton1 = 8;
|
||||
const PRUint32 kButton2 = 16;
|
||||
|
||||
/* void confirmEx (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text, in unsigned long buttonFlags, in wstring button0Title, in wstring button1Title, in wstring button2Title, in wstring checkMsg, inout boolean checkValue, out PRInt32 buttonPressed); */
|
||||
NS_IMETHODIMP
|
||||
nsCocoaBrowserService::ConfirmEx(nsIDOMWindow *parent,
|
||||
|
@ -337,9 +403,9 @@ nsCocoaBrowserService::ConfirmEx(nsIDOMWindow *parent,
|
|||
NSString* msgStr = [NSString stringWithCharacters:checkMsg length:(checkMsg ? nsCRT::strlen(checkMsg) : 0)];
|
||||
NSWindow* window = GetNSWindowForDOMWindow(parent);
|
||||
|
||||
NSString* btn1Str = [NSString stringWithCharacters:button0Title length:(button0Title ? nsCRT::strlen(button0Title) : 0)];
|
||||
NSString* btn2Str = [NSString stringWithCharacters:button1Title length:(button1Title ? nsCRT::strlen(button1Title) : 0)];
|
||||
NSString* btn3Str = [NSString stringWithCharacters:button2Title length:(button2Title ? nsCRT::strlen(button2Title) : 0)];
|
||||
NSString* btn1Str = GetButtonStringFromFlags(buttonFlags, kButton0, button0Title);
|
||||
NSString* btn2Str = GetButtonStringFromFlags(buttonFlags, kButton1, button1Title);
|
||||
NSString* btn3Str = GetButtonStringFromFlags(buttonFlags, kButton2, button2Title);
|
||||
|
||||
if (checkValue) {
|
||||
BOOL valueBool = *checkValue ? YES : NO;
|
||||
|
@ -354,9 +420,7 @@ nsCocoaBrowserService::ConfirmEx(nsIDOMWindow *parent,
|
|||
*buttonPressed = (PRInt32)[controller confirmEx:window title:titleStr text:textStr
|
||||
button1: btn1Str button2: btn2Str button3: btn3Str];
|
||||
}
|
||||
|
||||
printf("Uh-oh! Not posing the confirm yet, but just assuming OK was pressed.\n");
|
||||
|
||||
|
||||
return NS_OK;
|
||||
|
||||
}
|
||||
|
|
|
@ -453,22 +453,47 @@ static const char* ioServiceContractID = "@mozilla.org/network/io-service;1";
|
|||
-(BOOL)validateMenuItem: (NSMenuItem*)aMenuItem
|
||||
{
|
||||
// disable items that aren't relevant if there's no main browser window open
|
||||
if ([aMenuItem action] == @selector(newTab:) ||
|
||||
SEL action = [aMenuItem action];
|
||||
if (action == @selector(newTab:) ||
|
||||
/* ... many more items go here ... */
|
||||
[aMenuItem action] == @selector(savePage:)) {
|
||||
action == @selector(printPage:) ||
|
||||
action == @selector(findInPage:) ||
|
||||
action == @selector(findAgain:) ||
|
||||
action == @selector(toggleBookmarksToolbar:) ||
|
||||
action == @selector(doStop:) ||
|
||||
action == @selector(doReload:) ||
|
||||
action == @selector(biggerTextSize:) ||
|
||||
action == @selector(smallerTextSize:) ||
|
||||
action == @selector(viewSource:) ||
|
||||
action == @selector(goHome:) ||
|
||||
action == @selector(addBookmark:) || // doesn't work, not sure why
|
||||
action == @selector(savePage:)) {
|
||||
if ([[[mApplication mainWindow] windowController] isMemberOfClass:[BrowserWindowController class]])
|
||||
return YES;
|
||||
return NO;
|
||||
}
|
||||
|
||||
// only activate if we've got multiple tabs open.
|
||||
if (([aMenuItem action] == @selector(closeTab:) ||
|
||||
[aMenuItem action] == @selector (nextTab:) ||
|
||||
[aMenuItem action] == @selector (previousTab:))) {
|
||||
if ((action == @selector(closeTab:) ||
|
||||
action == @selector (nextTab:) ||
|
||||
action == @selector (previousTab:))) {
|
||||
if ([[[[mApplication mainWindow] windowController] getTabBrowser] numberOfTabViewItems] > 1)
|
||||
return YES;
|
||||
return NO;
|
||||
}
|
||||
|
||||
if ( action == @selector(goBack:) || action == @selector(goForward:) ) {
|
||||
NSWindow* mainWindow = [mApplication mainWindow];
|
||||
if (mainWindow) {
|
||||
if (action == @selector(goBack:))
|
||||
return [[[[mainWindow windowController] getBrowserWrapper] getBrowserView] canGoBack];
|
||||
if (action == @selector(goForward:))
|
||||
return [[[[mainWindow windowController] getBrowserWrapper] getBrowserView] canGoForward];
|
||||
}
|
||||
else
|
||||
return NO;
|
||||
}
|
||||
|
||||
// default return
|
||||
return YES;
|
||||
}
|
||||
|
|
|
@ -118,16 +118,40 @@
|
|||
- (int)confirmEx:(NSWindow*)parent title:(NSString*)title text:(NSString*)text
|
||||
button1:(NSString*)btn1 button2:(NSString*)btn2 button3:(NSString*)btn3
|
||||
{
|
||||
printf("ConfirmEx invoked, and this is not yet implemented!\n");
|
||||
return 0;
|
||||
[confirmPanelText setStringValue:text];
|
||||
[confirmPanel setTitle:title];
|
||||
|
||||
[confirmPanelButton1 setTitle:btn1];
|
||||
[confirmPanelButton2 setTitle:btn2];
|
||||
[confirmPanelButton3 setTitle:btn3];
|
||||
|
||||
int result = [NSApp runModalForWindow:confirmPanel relativeToWindow:parent];
|
||||
|
||||
[confirmPanel close];
|
||||
|
||||
return (result == 1);
|
||||
}
|
||||
|
||||
- (int)confirmCheckEx:(NSWindow*)parent title:(NSString*)title text:(NSString*)text
|
||||
button1:(NSString*)btn1 button2:(NSString*)btn2 button3:(NSString*)btn3
|
||||
checkMsg:(NSString*)checkMsg checkValue:(BOOL*)checkValue
|
||||
{
|
||||
printf("ConfirmCheckEx invoked, and this is not yet implemented!\n");
|
||||
return 0;
|
||||
[confirmCheckPanelText setStringValue:text];
|
||||
[confirmCheckPanel setTitle:title];
|
||||
int state = (*checkValue ? NSOnState : NSOffState);
|
||||
[confirmCheckPanelCheck setState:state];
|
||||
[confirmCheckPanelCheck setTitle:checkMsg];
|
||||
|
||||
[confirmCheckPanelButton1 setTitle:btn1];
|
||||
[confirmCheckPanelButton2 setTitle:btn2];
|
||||
[confirmCheckPanelButton3 setTitle:btn3];
|
||||
|
||||
int result = [NSApp runModalForWindow:confirmCheckPanel relativeToWindow:parent];
|
||||
|
||||
*checkValue = ([confirmCheckPanelCheck state] == NSOnState);
|
||||
[confirmCheckPanel close];
|
||||
|
||||
return (result == 1);
|
||||
}
|
||||
|
||||
- (BOOL)prompt:(NSWindow*)parent title:(NSString*)title text:(NSString*)text promptText:(NSMutableString*)promptText checkMsg:(NSString*)checkMsg checkValue:(BOOL*)checkValue doCheck:(BOOL)doCheck
|
||||
|
|
|
@ -81,6 +81,11 @@ private:
|
|||
const PRUnichar *messageName,
|
||||
const PRUnichar *showAgainName);
|
||||
|
||||
NSString *GetCommonDialogLocaleString(const char *s);
|
||||
NSString *GetButtonStringFromFlags(PRUint32 btnFlags, PRUint32 btnIDAndShift,
|
||||
const PRUnichar *btnTitle);
|
||||
|
||||
nsCOMPtr<nsIStringBundle> mCommonDialogStringBundle;
|
||||
nsCOMPtr<nsIStringBundle> mSecurityStringBundle;
|
||||
|
||||
static nsCocoaBrowserService* sSingleton;
|
||||
|
|
|
@ -315,6 +315,72 @@ nsCocoaBrowserService::ConfirmCheck(nsIDOMWindow *parent,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NSString *
|
||||
nsCocoaBrowserService::GetCommonDialogLocaleString(const char *key)
|
||||
{
|
||||
NSString *returnValue = @"";
|
||||
|
||||
nsresult rv;
|
||||
if (!mCommonDialogStringBundle) {
|
||||
#define kCommonDialogsStrings "chrome://global/locale/commonDialogs.properties"
|
||||
nsCOMPtr<nsIStringBundleService> service = do_GetService(NS_STRINGBUNDLE_CONTRACTID);
|
||||
if ( service )
|
||||
rv = service->CreateBundle(kCommonDialogsStrings, getter_AddRefs(mCommonDialogStringBundle));
|
||||
else
|
||||
rv = NS_ERROR_FAILURE;
|
||||
if (NS_FAILED(rv)) return returnValue;
|
||||
}
|
||||
|
||||
nsXPIDLString string;
|
||||
rv = mCommonDialogStringBundle->GetStringFromName(NS_ConvertASCIItoUCS2(key).get(), getter_Copies(string));
|
||||
if (NS_FAILED(rv)) return returnValue;
|
||||
|
||||
returnValue = [NSString stringWithCharacters:string length:(string ? nsCRT::strlen(string) : 0)];
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
NSString *
|
||||
nsCocoaBrowserService::GetButtonStringFromFlags(PRUint32 btnFlags,
|
||||
PRUint32 btnIDAndShift,
|
||||
const PRUnichar *btnTitle)
|
||||
{
|
||||
NSString *btnStr = nsnull;
|
||||
switch ((btnFlags >> btnIDAndShift) & 0xff) {
|
||||
case BUTTON_TITLE_OK:
|
||||
btnStr = GetCommonDialogLocaleString("OK");
|
||||
break;
|
||||
case BUTTON_TITLE_CANCEL:
|
||||
btnStr = GetCommonDialogLocaleString("Cancel");
|
||||
break;
|
||||
case BUTTON_TITLE_YES:
|
||||
btnStr = GetCommonDialogLocaleString("Yes");
|
||||
break;
|
||||
case BUTTON_TITLE_NO:
|
||||
btnStr = GetCommonDialogLocaleString("No");
|
||||
break;
|
||||
case BUTTON_TITLE_SAVE:
|
||||
btnStr = GetCommonDialogLocaleString("Save");
|
||||
break;
|
||||
case BUTTON_TITLE_DONT_SAVE:
|
||||
btnStr = GetCommonDialogLocaleString("DontSave");
|
||||
break;
|
||||
case BUTTON_TITLE_REVERT:
|
||||
btnStr = GetCommonDialogLocaleString("Revert");
|
||||
break;
|
||||
case BUTTON_TITLE_IS_STRING:
|
||||
btnStr = [NSString stringWithCharacters:btnTitle length:(btnTitle ? nsCRT::strlen(btnTitle) : 0)];
|
||||
}
|
||||
|
||||
return btnStr;
|
||||
}
|
||||
|
||||
// these constants are used for identifying the buttons and are intentionally overloaded to
|
||||
// correspond to the number of bits needed for shifting to obtain the flags for a particular
|
||||
// button (should be defined in nsIPrompt*.idl instead of here)
|
||||
const PRUint32 kButton0 = 0;
|
||||
const PRUint32 kButton1 = 8;
|
||||
const PRUint32 kButton2 = 16;
|
||||
|
||||
/* void confirmEx (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text, in unsigned long buttonFlags, in wstring button0Title, in wstring button1Title, in wstring button2Title, in wstring checkMsg, inout boolean checkValue, out PRInt32 buttonPressed); */
|
||||
NS_IMETHODIMP
|
||||
nsCocoaBrowserService::ConfirmEx(nsIDOMWindow *parent,
|
||||
|
@ -337,9 +403,9 @@ nsCocoaBrowserService::ConfirmEx(nsIDOMWindow *parent,
|
|||
NSString* msgStr = [NSString stringWithCharacters:checkMsg length:(checkMsg ? nsCRT::strlen(checkMsg) : 0)];
|
||||
NSWindow* window = GetNSWindowForDOMWindow(parent);
|
||||
|
||||
NSString* btn1Str = [NSString stringWithCharacters:button0Title length:(button0Title ? nsCRT::strlen(button0Title) : 0)];
|
||||
NSString* btn2Str = [NSString stringWithCharacters:button1Title length:(button1Title ? nsCRT::strlen(button1Title) : 0)];
|
||||
NSString* btn3Str = [NSString stringWithCharacters:button2Title length:(button2Title ? nsCRT::strlen(button2Title) : 0)];
|
||||
NSString* btn1Str = GetButtonStringFromFlags(buttonFlags, kButton0, button0Title);
|
||||
NSString* btn2Str = GetButtonStringFromFlags(buttonFlags, kButton1, button1Title);
|
||||
NSString* btn3Str = GetButtonStringFromFlags(buttonFlags, kButton2, button2Title);
|
||||
|
||||
if (checkValue) {
|
||||
BOOL valueBool = *checkValue ? YES : NO;
|
||||
|
@ -354,9 +420,7 @@ nsCocoaBrowserService::ConfirmEx(nsIDOMWindow *parent,
|
|||
*buttonPressed = (PRInt32)[controller confirmEx:window title:titleStr text:textStr
|
||||
button1: btn1Str button2: btn2Str button3: btn3Str];
|
||||
}
|
||||
|
||||
printf("Uh-oh! Not posing the confirm yet, but just assuming OK was pressed.\n");
|
||||
|
||||
|
||||
return NS_OK;
|
||||
|
||||
}
|
||||
|
|
|
@ -453,22 +453,47 @@ static const char* ioServiceContractID = "@mozilla.org/network/io-service;1";
|
|||
-(BOOL)validateMenuItem: (NSMenuItem*)aMenuItem
|
||||
{
|
||||
// disable items that aren't relevant if there's no main browser window open
|
||||
if ([aMenuItem action] == @selector(newTab:) ||
|
||||
SEL action = [aMenuItem action];
|
||||
if (action == @selector(newTab:) ||
|
||||
/* ... many more items go here ... */
|
||||
[aMenuItem action] == @selector(savePage:)) {
|
||||
action == @selector(printPage:) ||
|
||||
action == @selector(findInPage:) ||
|
||||
action == @selector(findAgain:) ||
|
||||
action == @selector(toggleBookmarksToolbar:) ||
|
||||
action == @selector(doStop:) ||
|
||||
action == @selector(doReload:) ||
|
||||
action == @selector(biggerTextSize:) ||
|
||||
action == @selector(smallerTextSize:) ||
|
||||
action == @selector(viewSource:) ||
|
||||
action == @selector(goHome:) ||
|
||||
action == @selector(addBookmark:) || // doesn't work, not sure why
|
||||
action == @selector(savePage:)) {
|
||||
if ([[[mApplication mainWindow] windowController] isMemberOfClass:[BrowserWindowController class]])
|
||||
return YES;
|
||||
return NO;
|
||||
}
|
||||
|
||||
// only activate if we've got multiple tabs open.
|
||||
if (([aMenuItem action] == @selector(closeTab:) ||
|
||||
[aMenuItem action] == @selector (nextTab:) ||
|
||||
[aMenuItem action] == @selector (previousTab:))) {
|
||||
if ((action == @selector(closeTab:) ||
|
||||
action == @selector (nextTab:) ||
|
||||
action == @selector (previousTab:))) {
|
||||
if ([[[[mApplication mainWindow] windowController] getTabBrowser] numberOfTabViewItems] > 1)
|
||||
return YES;
|
||||
return NO;
|
||||
}
|
||||
|
||||
if ( action == @selector(goBack:) || action == @selector(goForward:) ) {
|
||||
NSWindow* mainWindow = [mApplication mainWindow];
|
||||
if (mainWindow) {
|
||||
if (action == @selector(goBack:))
|
||||
return [[[[mainWindow windowController] getBrowserWrapper] getBrowserView] canGoBack];
|
||||
if (action == @selector(goForward:))
|
||||
return [[[[mainWindow windowController] getBrowserWrapper] getBrowserView] canGoForward];
|
||||
}
|
||||
else
|
||||
return NO;
|
||||
}
|
||||
|
||||
// default return
|
||||
return YES;
|
||||
}
|
||||
|
|
|
@ -37,11 +37,11 @@
|
|||
// Hookup cookie prefs. Relies on the tags of the radio buttons in the matrix being
|
||||
// set such that "enable all" is 0 and "disable all" is 2.
|
||||
PRInt32 acceptCookies = 0;
|
||||
mPrefService->GetIntPref("network.accept_cookies", &acceptCookies);
|
||||
mPrefService->GetIntPref("network.cookie.cookieBehavior", &acceptCookies);
|
||||
if ( acceptCookies == 1 ) // be safe in case of importing a mozilla profile
|
||||
acceptCookies = 2;
|
||||
if ( [mCookies selectCellWithTag:acceptCookies] != YES )
|
||||
NS_WARNING("Bad value for network.accept_cookies");
|
||||
NS_WARNING("Bad value for network.cookie.cookieBehavior");
|
||||
|
||||
PRBool warnAboutCookies = PR_TRUE;
|
||||
mPrefService->GetBoolPref("network.cookie.warnAboutCookies", &warnAboutCookies);
|
||||
|
@ -103,7 +103,7 @@
|
|||
{
|
||||
if ( !mPrefService )
|
||||
return;
|
||||
mPrefService->SetIntPref("network.accept_cookies", [[mCookies selectedCell] tag]);
|
||||
mPrefService->SetIntPref("network.cookie.cookieBehavior", [[mCookies selectedCell] tag]);
|
||||
}
|
||||
|
||||
//
|
||||
|
|
|
@ -118,16 +118,40 @@
|
|||
- (int)confirmEx:(NSWindow*)parent title:(NSString*)title text:(NSString*)text
|
||||
button1:(NSString*)btn1 button2:(NSString*)btn2 button3:(NSString*)btn3
|
||||
{
|
||||
printf("ConfirmEx invoked, and this is not yet implemented!\n");
|
||||
return 0;
|
||||
[confirmPanelText setStringValue:text];
|
||||
[confirmPanel setTitle:title];
|
||||
|
||||
[confirmPanelButton1 setTitle:btn1];
|
||||
[confirmPanelButton2 setTitle:btn2];
|
||||
[confirmPanelButton3 setTitle:btn3];
|
||||
|
||||
int result = [NSApp runModalForWindow:confirmPanel relativeToWindow:parent];
|
||||
|
||||
[confirmPanel close];
|
||||
|
||||
return (result == 1);
|
||||
}
|
||||
|
||||
- (int)confirmCheckEx:(NSWindow*)parent title:(NSString*)title text:(NSString*)text
|
||||
button1:(NSString*)btn1 button2:(NSString*)btn2 button3:(NSString*)btn3
|
||||
checkMsg:(NSString*)checkMsg checkValue:(BOOL*)checkValue
|
||||
{
|
||||
printf("ConfirmCheckEx invoked, and this is not yet implemented!\n");
|
||||
return 0;
|
||||
[confirmCheckPanelText setStringValue:text];
|
||||
[confirmCheckPanel setTitle:title];
|
||||
int state = (*checkValue ? NSOnState : NSOffState);
|
||||
[confirmCheckPanelCheck setState:state];
|
||||
[confirmCheckPanelCheck setTitle:checkMsg];
|
||||
|
||||
[confirmCheckPanelButton1 setTitle:btn1];
|
||||
[confirmCheckPanelButton2 setTitle:btn2];
|
||||
[confirmCheckPanelButton3 setTitle:btn3];
|
||||
|
||||
int result = [NSApp runModalForWindow:confirmCheckPanel relativeToWindow:parent];
|
||||
|
||||
*checkValue = ([confirmCheckPanelCheck state] == NSOnState);
|
||||
[confirmCheckPanel close];
|
||||
|
||||
return (result == 1);
|
||||
}
|
||||
|
||||
- (BOOL)prompt:(NSWindow*)parent title:(NSString*)title text:(NSString*)text promptText:(NSMutableString*)promptText checkMsg:(NSString*)checkMsg checkValue:(BOOL*)checkValue doCheck:(BOOL)doCheck
|
||||
|
|
|
@ -81,6 +81,11 @@ private:
|
|||
const PRUnichar *messageName,
|
||||
const PRUnichar *showAgainName);
|
||||
|
||||
NSString *GetCommonDialogLocaleString(const char *s);
|
||||
NSString *GetButtonStringFromFlags(PRUint32 btnFlags, PRUint32 btnIDAndShift,
|
||||
const PRUnichar *btnTitle);
|
||||
|
||||
nsCOMPtr<nsIStringBundle> mCommonDialogStringBundle;
|
||||
nsCOMPtr<nsIStringBundle> mSecurityStringBundle;
|
||||
|
||||
static nsCocoaBrowserService* sSingleton;
|
||||
|
|
|
@ -315,6 +315,72 @@ nsCocoaBrowserService::ConfirmCheck(nsIDOMWindow *parent,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NSString *
|
||||
nsCocoaBrowserService::GetCommonDialogLocaleString(const char *key)
|
||||
{
|
||||
NSString *returnValue = @"";
|
||||
|
||||
nsresult rv;
|
||||
if (!mCommonDialogStringBundle) {
|
||||
#define kCommonDialogsStrings "chrome://global/locale/commonDialogs.properties"
|
||||
nsCOMPtr<nsIStringBundleService> service = do_GetService(NS_STRINGBUNDLE_CONTRACTID);
|
||||
if ( service )
|
||||
rv = service->CreateBundle(kCommonDialogsStrings, getter_AddRefs(mCommonDialogStringBundle));
|
||||
else
|
||||
rv = NS_ERROR_FAILURE;
|
||||
if (NS_FAILED(rv)) return returnValue;
|
||||
}
|
||||
|
||||
nsXPIDLString string;
|
||||
rv = mCommonDialogStringBundle->GetStringFromName(NS_ConvertASCIItoUCS2(key).get(), getter_Copies(string));
|
||||
if (NS_FAILED(rv)) return returnValue;
|
||||
|
||||
returnValue = [NSString stringWithCharacters:string length:(string ? nsCRT::strlen(string) : 0)];
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
NSString *
|
||||
nsCocoaBrowserService::GetButtonStringFromFlags(PRUint32 btnFlags,
|
||||
PRUint32 btnIDAndShift,
|
||||
const PRUnichar *btnTitle)
|
||||
{
|
||||
NSString *btnStr = nsnull;
|
||||
switch ((btnFlags >> btnIDAndShift) & 0xff) {
|
||||
case BUTTON_TITLE_OK:
|
||||
btnStr = GetCommonDialogLocaleString("OK");
|
||||
break;
|
||||
case BUTTON_TITLE_CANCEL:
|
||||
btnStr = GetCommonDialogLocaleString("Cancel");
|
||||
break;
|
||||
case BUTTON_TITLE_YES:
|
||||
btnStr = GetCommonDialogLocaleString("Yes");
|
||||
break;
|
||||
case BUTTON_TITLE_NO:
|
||||
btnStr = GetCommonDialogLocaleString("No");
|
||||
break;
|
||||
case BUTTON_TITLE_SAVE:
|
||||
btnStr = GetCommonDialogLocaleString("Save");
|
||||
break;
|
||||
case BUTTON_TITLE_DONT_SAVE:
|
||||
btnStr = GetCommonDialogLocaleString("DontSave");
|
||||
break;
|
||||
case BUTTON_TITLE_REVERT:
|
||||
btnStr = GetCommonDialogLocaleString("Revert");
|
||||
break;
|
||||
case BUTTON_TITLE_IS_STRING:
|
||||
btnStr = [NSString stringWithCharacters:btnTitle length:(btnTitle ? nsCRT::strlen(btnTitle) : 0)];
|
||||
}
|
||||
|
||||
return btnStr;
|
||||
}
|
||||
|
||||
// these constants are used for identifying the buttons and are intentionally overloaded to
|
||||
// correspond to the number of bits needed for shifting to obtain the flags for a particular
|
||||
// button (should be defined in nsIPrompt*.idl instead of here)
|
||||
const PRUint32 kButton0 = 0;
|
||||
const PRUint32 kButton1 = 8;
|
||||
const PRUint32 kButton2 = 16;
|
||||
|
||||
/* void confirmEx (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text, in unsigned long buttonFlags, in wstring button0Title, in wstring button1Title, in wstring button2Title, in wstring checkMsg, inout boolean checkValue, out PRInt32 buttonPressed); */
|
||||
NS_IMETHODIMP
|
||||
nsCocoaBrowserService::ConfirmEx(nsIDOMWindow *parent,
|
||||
|
@ -337,9 +403,9 @@ nsCocoaBrowserService::ConfirmEx(nsIDOMWindow *parent,
|
|||
NSString* msgStr = [NSString stringWithCharacters:checkMsg length:(checkMsg ? nsCRT::strlen(checkMsg) : 0)];
|
||||
NSWindow* window = GetNSWindowForDOMWindow(parent);
|
||||
|
||||
NSString* btn1Str = [NSString stringWithCharacters:button0Title length:(button0Title ? nsCRT::strlen(button0Title) : 0)];
|
||||
NSString* btn2Str = [NSString stringWithCharacters:button1Title length:(button1Title ? nsCRT::strlen(button1Title) : 0)];
|
||||
NSString* btn3Str = [NSString stringWithCharacters:button2Title length:(button2Title ? nsCRT::strlen(button2Title) : 0)];
|
||||
NSString* btn1Str = GetButtonStringFromFlags(buttonFlags, kButton0, button0Title);
|
||||
NSString* btn2Str = GetButtonStringFromFlags(buttonFlags, kButton1, button1Title);
|
||||
NSString* btn3Str = GetButtonStringFromFlags(buttonFlags, kButton2, button2Title);
|
||||
|
||||
if (checkValue) {
|
||||
BOOL valueBool = *checkValue ? YES : NO;
|
||||
|
@ -354,9 +420,7 @@ nsCocoaBrowserService::ConfirmEx(nsIDOMWindow *parent,
|
|||
*buttonPressed = (PRInt32)[controller confirmEx:window title:titleStr text:textStr
|
||||
button1: btn1Str button2: btn2Str button3: btn3Str];
|
||||
}
|
||||
|
||||
printf("Uh-oh! Not posing the confirm yet, but just assuming OK was pressed.\n");
|
||||
|
||||
|
||||
return NS_OK;
|
||||
|
||||
}
|
||||
|
|
|
@ -453,22 +453,47 @@ static const char* ioServiceContractID = "@mozilla.org/network/io-service;1";
|
|||
-(BOOL)validateMenuItem: (NSMenuItem*)aMenuItem
|
||||
{
|
||||
// disable items that aren't relevant if there's no main browser window open
|
||||
if ([aMenuItem action] == @selector(newTab:) ||
|
||||
SEL action = [aMenuItem action];
|
||||
if (action == @selector(newTab:) ||
|
||||
/* ... many more items go here ... */
|
||||
[aMenuItem action] == @selector(savePage:)) {
|
||||
action == @selector(printPage:) ||
|
||||
action == @selector(findInPage:) ||
|
||||
action == @selector(findAgain:) ||
|
||||
action == @selector(toggleBookmarksToolbar:) ||
|
||||
action == @selector(doStop:) ||
|
||||
action == @selector(doReload:) ||
|
||||
action == @selector(biggerTextSize:) ||
|
||||
action == @selector(smallerTextSize:) ||
|
||||
action == @selector(viewSource:) ||
|
||||
action == @selector(goHome:) ||
|
||||
action == @selector(addBookmark:) || // doesn't work, not sure why
|
||||
action == @selector(savePage:)) {
|
||||
if ([[[mApplication mainWindow] windowController] isMemberOfClass:[BrowserWindowController class]])
|
||||
return YES;
|
||||
return NO;
|
||||
}
|
||||
|
||||
// only activate if we've got multiple tabs open.
|
||||
if (([aMenuItem action] == @selector(closeTab:) ||
|
||||
[aMenuItem action] == @selector (nextTab:) ||
|
||||
[aMenuItem action] == @selector (previousTab:))) {
|
||||
if ((action == @selector(closeTab:) ||
|
||||
action == @selector (nextTab:) ||
|
||||
action == @selector (previousTab:))) {
|
||||
if ([[[[mApplication mainWindow] windowController] getTabBrowser] numberOfTabViewItems] > 1)
|
||||
return YES;
|
||||
return NO;
|
||||
}
|
||||
|
||||
if ( action == @selector(goBack:) || action == @selector(goForward:) ) {
|
||||
NSWindow* mainWindow = [mApplication mainWindow];
|
||||
if (mainWindow) {
|
||||
if (action == @selector(goBack:))
|
||||
return [[[[mainWindow windowController] getBrowserWrapper] getBrowserView] canGoBack];
|
||||
if (action == @selector(goForward:))
|
||||
return [[[[mainWindow windowController] getBrowserWrapper] getBrowserView] canGoForward];
|
||||
}
|
||||
else
|
||||
return NO;
|
||||
}
|
||||
|
||||
// default return
|
||||
return YES;
|
||||
}
|
||||
|
|
|
@ -118,16 +118,40 @@
|
|||
- (int)confirmEx:(NSWindow*)parent title:(NSString*)title text:(NSString*)text
|
||||
button1:(NSString*)btn1 button2:(NSString*)btn2 button3:(NSString*)btn3
|
||||
{
|
||||
printf("ConfirmEx invoked, and this is not yet implemented!\n");
|
||||
return 0;
|
||||
[confirmPanelText setStringValue:text];
|
||||
[confirmPanel setTitle:title];
|
||||
|
||||
[confirmPanelButton1 setTitle:btn1];
|
||||
[confirmPanelButton2 setTitle:btn2];
|
||||
[confirmPanelButton3 setTitle:btn3];
|
||||
|
||||
int result = [NSApp runModalForWindow:confirmPanel relativeToWindow:parent];
|
||||
|
||||
[confirmPanel close];
|
||||
|
||||
return (result == 1);
|
||||
}
|
||||
|
||||
- (int)confirmCheckEx:(NSWindow*)parent title:(NSString*)title text:(NSString*)text
|
||||
button1:(NSString*)btn1 button2:(NSString*)btn2 button3:(NSString*)btn3
|
||||
checkMsg:(NSString*)checkMsg checkValue:(BOOL*)checkValue
|
||||
{
|
||||
printf("ConfirmCheckEx invoked, and this is not yet implemented!\n");
|
||||
return 0;
|
||||
[confirmCheckPanelText setStringValue:text];
|
||||
[confirmCheckPanel setTitle:title];
|
||||
int state = (*checkValue ? NSOnState : NSOffState);
|
||||
[confirmCheckPanelCheck setState:state];
|
||||
[confirmCheckPanelCheck setTitle:checkMsg];
|
||||
|
||||
[confirmCheckPanelButton1 setTitle:btn1];
|
||||
[confirmCheckPanelButton2 setTitle:btn2];
|
||||
[confirmCheckPanelButton3 setTitle:btn3];
|
||||
|
||||
int result = [NSApp runModalForWindow:confirmCheckPanel relativeToWindow:parent];
|
||||
|
||||
*checkValue = ([confirmCheckPanelCheck state] == NSOnState);
|
||||
[confirmCheckPanel close];
|
||||
|
||||
return (result == 1);
|
||||
}
|
||||
|
||||
- (BOOL)prompt:(NSWindow*)parent title:(NSString*)title text:(NSString*)text promptText:(NSMutableString*)promptText checkMsg:(NSString*)checkMsg checkValue:(BOOL*)checkValue doCheck:(BOOL)doCheck
|
||||
|
|
|
@ -81,6 +81,11 @@ private:
|
|||
const PRUnichar *messageName,
|
||||
const PRUnichar *showAgainName);
|
||||
|
||||
NSString *GetCommonDialogLocaleString(const char *s);
|
||||
NSString *GetButtonStringFromFlags(PRUint32 btnFlags, PRUint32 btnIDAndShift,
|
||||
const PRUnichar *btnTitle);
|
||||
|
||||
nsCOMPtr<nsIStringBundle> mCommonDialogStringBundle;
|
||||
nsCOMPtr<nsIStringBundle> mSecurityStringBundle;
|
||||
|
||||
static nsCocoaBrowserService* sSingleton;
|
||||
|
|
|
@ -315,6 +315,72 @@ nsCocoaBrowserService::ConfirmCheck(nsIDOMWindow *parent,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NSString *
|
||||
nsCocoaBrowserService::GetCommonDialogLocaleString(const char *key)
|
||||
{
|
||||
NSString *returnValue = @"";
|
||||
|
||||
nsresult rv;
|
||||
if (!mCommonDialogStringBundle) {
|
||||
#define kCommonDialogsStrings "chrome://global/locale/commonDialogs.properties"
|
||||
nsCOMPtr<nsIStringBundleService> service = do_GetService(NS_STRINGBUNDLE_CONTRACTID);
|
||||
if ( service )
|
||||
rv = service->CreateBundle(kCommonDialogsStrings, getter_AddRefs(mCommonDialogStringBundle));
|
||||
else
|
||||
rv = NS_ERROR_FAILURE;
|
||||
if (NS_FAILED(rv)) return returnValue;
|
||||
}
|
||||
|
||||
nsXPIDLString string;
|
||||
rv = mCommonDialogStringBundle->GetStringFromName(NS_ConvertASCIItoUCS2(key).get(), getter_Copies(string));
|
||||
if (NS_FAILED(rv)) return returnValue;
|
||||
|
||||
returnValue = [NSString stringWithCharacters:string length:(string ? nsCRT::strlen(string) : 0)];
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
NSString *
|
||||
nsCocoaBrowserService::GetButtonStringFromFlags(PRUint32 btnFlags,
|
||||
PRUint32 btnIDAndShift,
|
||||
const PRUnichar *btnTitle)
|
||||
{
|
||||
NSString *btnStr = nsnull;
|
||||
switch ((btnFlags >> btnIDAndShift) & 0xff) {
|
||||
case BUTTON_TITLE_OK:
|
||||
btnStr = GetCommonDialogLocaleString("OK");
|
||||
break;
|
||||
case BUTTON_TITLE_CANCEL:
|
||||
btnStr = GetCommonDialogLocaleString("Cancel");
|
||||
break;
|
||||
case BUTTON_TITLE_YES:
|
||||
btnStr = GetCommonDialogLocaleString("Yes");
|
||||
break;
|
||||
case BUTTON_TITLE_NO:
|
||||
btnStr = GetCommonDialogLocaleString("No");
|
||||
break;
|
||||
case BUTTON_TITLE_SAVE:
|
||||
btnStr = GetCommonDialogLocaleString("Save");
|
||||
break;
|
||||
case BUTTON_TITLE_DONT_SAVE:
|
||||
btnStr = GetCommonDialogLocaleString("DontSave");
|
||||
break;
|
||||
case BUTTON_TITLE_REVERT:
|
||||
btnStr = GetCommonDialogLocaleString("Revert");
|
||||
break;
|
||||
case BUTTON_TITLE_IS_STRING:
|
||||
btnStr = [NSString stringWithCharacters:btnTitle length:(btnTitle ? nsCRT::strlen(btnTitle) : 0)];
|
||||
}
|
||||
|
||||
return btnStr;
|
||||
}
|
||||
|
||||
// these constants are used for identifying the buttons and are intentionally overloaded to
|
||||
// correspond to the number of bits needed for shifting to obtain the flags for a particular
|
||||
// button (should be defined in nsIPrompt*.idl instead of here)
|
||||
const PRUint32 kButton0 = 0;
|
||||
const PRUint32 kButton1 = 8;
|
||||
const PRUint32 kButton2 = 16;
|
||||
|
||||
/* void confirmEx (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text, in unsigned long buttonFlags, in wstring button0Title, in wstring button1Title, in wstring button2Title, in wstring checkMsg, inout boolean checkValue, out PRInt32 buttonPressed); */
|
||||
NS_IMETHODIMP
|
||||
nsCocoaBrowserService::ConfirmEx(nsIDOMWindow *parent,
|
||||
|
@ -337,9 +403,9 @@ nsCocoaBrowserService::ConfirmEx(nsIDOMWindow *parent,
|
|||
NSString* msgStr = [NSString stringWithCharacters:checkMsg length:(checkMsg ? nsCRT::strlen(checkMsg) : 0)];
|
||||
NSWindow* window = GetNSWindowForDOMWindow(parent);
|
||||
|
||||
NSString* btn1Str = [NSString stringWithCharacters:button0Title length:(button0Title ? nsCRT::strlen(button0Title) : 0)];
|
||||
NSString* btn2Str = [NSString stringWithCharacters:button1Title length:(button1Title ? nsCRT::strlen(button1Title) : 0)];
|
||||
NSString* btn3Str = [NSString stringWithCharacters:button2Title length:(button2Title ? nsCRT::strlen(button2Title) : 0)];
|
||||
NSString* btn1Str = GetButtonStringFromFlags(buttonFlags, kButton0, button0Title);
|
||||
NSString* btn2Str = GetButtonStringFromFlags(buttonFlags, kButton1, button1Title);
|
||||
NSString* btn3Str = GetButtonStringFromFlags(buttonFlags, kButton2, button2Title);
|
||||
|
||||
if (checkValue) {
|
||||
BOOL valueBool = *checkValue ? YES : NO;
|
||||
|
@ -354,9 +420,7 @@ nsCocoaBrowserService::ConfirmEx(nsIDOMWindow *parent,
|
|||
*buttonPressed = (PRInt32)[controller confirmEx:window title:titleStr text:textStr
|
||||
button1: btn1Str button2: btn2Str button3: btn3Str];
|
||||
}
|
||||
|
||||
printf("Uh-oh! Not posing the confirm yet, but just assuming OK was pressed.\n");
|
||||
|
||||
|
||||
return NS_OK;
|
||||
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче