зеркало из https://github.com/mozilla/pjs.git
Bug 70048: ``Text of modifiers on accelerators can't be localized''. Attempt #2 :-)
Patch by lordpixel@mac.com, jag. r=jag, lordpixel, pinkerton, sr=ben, blake.
This commit is contained in:
Родитель
a084ef91a9
Коммит
cb07a908dd
|
@ -80,6 +80,13 @@ nsMenuDismissalListener* nsMenuFrame::mDismissalListener = nsnull;
|
|||
|
||||
static NS_DEFINE_IID(kLookAndFeelCID, NS_LOOKANDFEEL_CID);
|
||||
|
||||
nsrefcnt nsMenuFrame::gRefCnt = 0;
|
||||
nsString *nsMenuFrame::gShiftText = nsnull;
|
||||
nsString *nsMenuFrame::gControlText = nsnull;
|
||||
nsString *nsMenuFrame::gMetaText = nsnull;
|
||||
nsString *nsMenuFrame::gAltText = nsnull;
|
||||
nsString *nsMenuFrame::gModifierSeparator = nsnull;
|
||||
|
||||
//
|
||||
// NS_NewMenuFrame
|
||||
//
|
||||
|
@ -179,11 +186,63 @@ nsMenuFrame::Init(nsIPresContext* aPresContext,
|
|||
UpdateMenuType(aPresContext);
|
||||
|
||||
nsAutoString accelString;
|
||||
|
||||
//load the display strings for the keyboard accelerators, but only once
|
||||
if (gRefCnt++ == 0) {
|
||||
|
||||
nsCOMPtr<nsIStringBundleService> bundleService(do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv));
|
||||
nsCOMPtr<nsIStringBundle> bundle;
|
||||
if (NS_SUCCEEDED(rv) && bundleService) {
|
||||
rv = bundleService->CreateBundle( "chrome://global-platform/locale/platformKeys.properties",
|
||||
getter_AddRefs(bundle));
|
||||
}
|
||||
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv) && bundle, "chrome://global/locale/platformKeys.properties could not be loaded");
|
||||
nsXPIDLString shiftModifier;
|
||||
nsXPIDLString metaModifier;
|
||||
nsXPIDLString altModifier;
|
||||
nsXPIDLString controlModifier;
|
||||
nsXPIDLString modifierSeparator;
|
||||
if (NS_SUCCEEDED(rv) && bundle) {
|
||||
//macs use symbols for each modifier key, so fetch each from the bundle, which also covers i18n
|
||||
rv = bundle->GetStringFromName(NS_LITERAL_STRING("VK_SHIFT").get(), getter_Copies(shiftModifier));
|
||||
rv = bundle->GetStringFromName(NS_LITERAL_STRING("VK_META").get(), getter_Copies(metaModifier));
|
||||
rv = bundle->GetStringFromName(NS_LITERAL_STRING("VK_ALT").get(), getter_Copies(altModifier));
|
||||
rv = bundle->GetStringFromName(NS_LITERAL_STRING("VK_CONTROL").get(), getter_Copies(controlModifier));
|
||||
rv = bundle->GetStringFromName(NS_LITERAL_STRING("MODIFIER_SEPARATOR").get(), getter_Copies(modifierSeparator));
|
||||
} else {
|
||||
rv = NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
//if any of these don't exist, we get an empty string
|
||||
gShiftText = new nsString(shiftModifier);
|
||||
gMetaText = new nsString(metaModifier);
|
||||
gAltText = new nsString(altModifier);
|
||||
gControlText = new nsString(controlModifier);
|
||||
gModifierSeparator = new nsString(modifierSeparator);
|
||||
}
|
||||
|
||||
BuildAcceleratorText(accelString);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsMenuFrame::~nsMenuFrame()
|
||||
{
|
||||
// Clean up shared statics
|
||||
if (--gRefCnt == 0) {
|
||||
delete gShiftText;
|
||||
gShiftText = nsnull;
|
||||
delete gControlText;
|
||||
gControlText = nsnull;
|
||||
delete gMetaText;
|
||||
gMetaText = nsnull;
|
||||
delete gAltText;
|
||||
gAltText = nsnull;
|
||||
delete gModifierSeparator;
|
||||
gModifierSeparator = nsnull;
|
||||
}
|
||||
}
|
||||
|
||||
// The following methods are all overridden to ensure that the menupopup frame
|
||||
// is placed in the appropriate list.
|
||||
NS_IMETHODIMP
|
||||
|
@ -1330,32 +1389,32 @@ nsMenuFrame::BuildAcceleratorText(nsString& aAccelString)
|
|||
while (token) {
|
||||
|
||||
if (PL_strcmp(token, "shift") == 0)
|
||||
aAccelString += NS_LITERAL_STRING("Shift");
|
||||
aAccelString += *gShiftText;
|
||||
else if (PL_strcmp(token, "alt") == 0)
|
||||
aAccelString += NS_LITERAL_STRING("Alt");
|
||||
aAccelString += *gAltText;
|
||||
else if (PL_strcmp(token, "meta") == 0)
|
||||
aAccelString += NS_LITERAL_STRING("Meta");
|
||||
aAccelString += *gMetaText;
|
||||
else if (PL_strcmp(token, "control") == 0)
|
||||
aAccelString += NS_LITERAL_STRING("Ctrl");
|
||||
aAccelString += *gControlText;
|
||||
else if (PL_strcmp(token, "accel") == 0) {
|
||||
switch (accelKey)
|
||||
{
|
||||
case nsIDOMKeyEvent::DOM_VK_META:
|
||||
aAccelString += NS_LITERAL_STRING("Meta");
|
||||
aAccelString += *gMetaText;
|
||||
break;
|
||||
|
||||
case nsIDOMKeyEvent::DOM_VK_ALT:
|
||||
aAccelString += NS_LITERAL_STRING("Alt");
|
||||
aAccelString += *gAltText;
|
||||
break;
|
||||
|
||||
case nsIDOMKeyEvent::DOM_VK_CONTROL:
|
||||
default:
|
||||
aAccelString += NS_LITERAL_STRING("Ctrl");
|
||||
aAccelString += *gControlText;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
aAccelString += NS_LITERAL_STRING("+");
|
||||
aAccelString += *gModifierSeparator;
|
||||
|
||||
token = nsCRT::strtok(newStr, ", ", &newStr);
|
||||
}
|
||||
|
|
|
@ -200,6 +200,7 @@ protected:
|
|||
PRInt32 aNameSpaceID,
|
||||
nsIAtom* aAttribute,
|
||||
PRInt32 aHint);
|
||||
virtual ~nsMenuFrame();
|
||||
|
||||
protected:
|
||||
nsresult SetDebug(nsBoxLayoutState& aState, nsIFrame* aList, PRBool aDebug);
|
||||
|
@ -218,6 +219,15 @@ protected:
|
|||
nsIPresContext* mPresContext; // Our pres context.
|
||||
nsString mGroupName;
|
||||
nsSize mLastPref;
|
||||
|
||||
//we load some display strings from platformKeys.properties only once
|
||||
static nsrefcnt gRefCnt;
|
||||
static nsString *gShiftText;
|
||||
static nsString *gControlText;
|
||||
static nsString *gMetaText;
|
||||
static nsString *gAltText;
|
||||
static nsString *gModifierSeparator;
|
||||
|
||||
public:
|
||||
static nsMenuDismissalListener* mDismissalListener; // The listener that dismisses menus.
|
||||
private:
|
||||
|
|
|
@ -83,7 +83,6 @@ en-US.jar:
|
|||
locale/en-US/global/regionNames.properties (resources/locale/en-US/regionNames.properties)
|
||||
locale/en-US/global/about.html (resources/locale/en-US/about.html)
|
||||
locale/en-US/global/commonDialogs.properties (resources/locale/en-US/commonDialogs.properties)
|
||||
locale/en-US/global/platformKeys.properties (resources/locale/en-US/platformKeys.properties)
|
||||
US.jar:
|
||||
locale/US/global-region/contents.rdf (resources/locale/en-US/contents-region.rdf)
|
||||
locale/US/global-region/region.dtd (resources/locale/en-US/region.dtd)
|
||||
|
|
|
@ -2,8 +2,5 @@ en-mac.jar:
|
|||
locale/en-US/global-platform/contents.rdf (contents-platform.rdf)
|
||||
locale/en-US/global-platform/platformGlobalOverlay.dtd
|
||||
locale/en-US/global-platform/platformDialogOverlay.dtd
|
||||
#this should not go into global-platform as its an override of the XP version used for
|
||||
#windows/os2/unix. See platformKeys.properties in the parent directory
|
||||
en-US.jar:
|
||||
+ locale/en-US/global/platformKeys.properties
|
||||
locale/en-US/global-platform/platformKeys.properties
|
||||
locale/en-US/global-platform/wizard.properties
|
||||
|
|
|
@ -2,4 +2,5 @@ en-os2.jar:
|
|||
locale/en-US/global-platform/contents.rdf (contents-platform.rdf)
|
||||
locale/en-US/global-platform/platformGlobalOverlay.dtd
|
||||
locale/en-US/global-platform/platformDialogOverlay.dtd
|
||||
locale/en-US/global-platform/platformKeys.properties
|
||||
locale/en-US/global-platform/wizard.properties
|
|
@ -2,5 +2,6 @@ en-unix.jar:
|
|||
locale/en-US/global-platform/contents.rdf (contents-platform.rdf)
|
||||
locale/en-US/global-platform/platformGlobalOverlay.dtd
|
||||
locale/en-US/global-platform/platformDialogOverlay.dtd
|
||||
locale/en-US/global-platform/platformKeys.properties
|
||||
locale/en-US/global-platform/printdialog.dtd
|
||||
locale/en-US/global-platform/wizard.properties
|
|
@ -0,0 +1,18 @@
|
|||
#default
|
||||
#this file defines the on screen display names for the various modifier keys
|
||||
#these are used in XP menus to show keyboard shortcuts
|
||||
|
||||
#the shift key
|
||||
VK_SHIFT=Shift
|
||||
|
||||
#the command key
|
||||
VK_META=Meta
|
||||
|
||||
#the alt key
|
||||
VK_ALT=Alt
|
||||
|
||||
#the control key
|
||||
VK_CONTROL=Ctrl
|
||||
|
||||
#the seperator character used between modifiers
|
||||
MODIFIER_SEPARATOR=+
|
|
@ -2,4 +2,5 @@ en-win.jar:
|
|||
locale/en-US/global-platform/contents.rdf (contents-platform.rdf)
|
||||
locale/en-US/global-platform/platformGlobalOverlay.dtd
|
||||
locale/en-US/global-platform/platformDialogOverlay.dtd
|
||||
locale/en-US/global-platform/platformKeys.properties
|
||||
locale/en-US/global-platform/wizard.properties
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
#default
|
||||
#this file defines the on screen display names for the various modifier keys
|
||||
#these are used in XP menus to show keyboard shortcuts
|
||||
|
||||
#the shift key
|
||||
VK_SHIFT=Shift
|
||||
|
||||
#the command key
|
||||
VK_META=Meta
|
||||
|
||||
#the alt key
|
||||
VK_ALT=Alt
|
||||
|
||||
#the control key
|
||||
VK_CONTROL=Ctrl
|
||||
|
||||
#the seperator character used between modifiers
|
||||
MODIFIER_SEPARATOR=+
|
Загрузка…
Ссылка в новой задаче