Addresses some of the issues brought up in ticket #8148

The key labels have been changed to Win/Option and Alt/Command
to better associate them with the key names on a PC keyboard. This is
not perfect, but, better.

Added a checkbox entitled "Switch right Alt/Command and Win/Option keys"
This checkbox does what it says, switches the keys on the right side
of your keyboard leaving the left side according to how you set them.
This is needed for some international keymaps.

Whether or not you have switched already is not remembered, you have to
check the box each time you open the dialog. I don't know how to figure
out whether or not the keys have been switched already reliably. Hopefully
this isn't a big deal.

Set the menu option and window title to sentence case, thanks Humdinger.
This commit is contained in:
John Scipione 2012-03-25 16:45:00 -04:00
parent 3109e9c7b5
commit 1a6b60e613
4 changed files with 38 additions and 16 deletions

View File

@ -44,7 +44,7 @@ KeymapApplication::MessageReceived(BMessage* message)
void
KeymapApplication::_ShowModifierKeysWindow()
{
if (fModifierKeysWindow)
if (fModifierKeysWindow != NULL)
fModifierKeysWindow->Activate();
else {
fModifierKeysWindow = new ModifierKeysWindow();

View File

@ -418,7 +418,7 @@ KeymapWindow::_CreateMenu()
new BMessage(kMsgMenuFileSaveAs)));
menu->AddSeparatorItem();
menu->AddItem(new BMenuItem(
B_TRANSLATE("Set Modifier Keys" B_UTF8_ELLIPSIS),
B_TRANSLATE("Set modifier keys" B_UTF8_ELLIPSIS),
new BMessage(kMsgShowModifierKeysWindow)));
menu->AddSeparatorItem();
menu->AddItem(new BMenuItem(B_TRANSLATE("Quit"),

View File

@ -40,14 +40,16 @@ static const uint32 kMsgUpdateModifier = 'upmd';
static const uint32 kMsgApplyModifiers = 'apmd';
static const uint32 kMsgRevertModifiers = 'rvmd';
static int32 kInitialSwitchRight;
#undef B_TRANSLATE_CONTEXT
#define B_TRANSLATE_CONTEXT "Modifier Keys window"
#define B_TRANSLATE_CONTEXT "Modifier keys window"
ModifierKeysWindow::ModifierKeysWindow()
:
BWindow(BRect(80, 50, 400, 260), B_TRANSLATE("Modifier Keys"),
BWindow(BRect(80, 50, 400, 260), B_TRANSLATE("Modifier keys"),
B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE
| B_AUTO_UPDATE_SIZE_LIMITS)
{
@ -65,23 +67,27 @@ ModifierKeysWindow::ModifierKeysWindow()
BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET));
BStringView* optionStringView
= new BStringView("option", B_TRANSLATE("Option:"));
= new BStringView("option", B_TRANSLATE("Win/Option:"));
optionStringView->SetExplicitMaxSize(
BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET));
BStringView* commandStringView
= new BStringView("command", B_TRANSLATE("Command:"));
= new BStringView("command", B_TRANSLATE("Alt/Command:"));
commandStringView->SetExplicitMaxSize(
BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET));
fCancelButton = new BButton("CancelButton", B_TRANSLATE("Cancel"),
fSwitchRight = new BCheckBox("switchRight",
B_TRANSLATE("Switch right Alt/Command and Win/Option keys"),
new BMessage(kMsgUpdateModifier));
fCancelButton = new BButton("cancelButton", B_TRANSLATE("Cancel"),
new BMessage(B_QUIT_REQUESTED));
fRevertButton = new BButton("revertButton", B_TRANSLATE("Revert"),
new BMessage(kMsgRevertModifiers));
fRevertButton->SetEnabled(false);
fOkButton = new BButton("OkButton", B_TRANSLATE("OK"),
fOkButton = new BButton("okButton", B_TRANSLATE("OK"),
new BMessage(kMsgApplyModifiers));
fOkButton->MakeDefault(true);
@ -103,6 +109,7 @@ ModifierKeysWindow::ModifierKeysWindow()
.Add(_CreateCommandMenuField(), 1, 3)
)
.AddGlue()
.Add(fSwitchRight)
.AddGroup(B_HORIZONTAL, 10)
.Add(fCancelButton)
.AddGlue()
@ -112,6 +119,10 @@ ModifierKeysWindow::ModifierKeysWindow()
.SetInsets(10, 10, 10, 10)
);
// TODO: Figure out a way to set this based on current modifiers
kInitialSwitchRight = B_CONTROL_OFF;
fSwitchRight->SetValue(kInitialSwitchRight);
CenterOnScreen();
}
@ -184,16 +195,24 @@ ModifierKeysWindow::MessageReceived(BMessage* message)
break;
}
fRevertButton->SetEnabled(memcmp(fCurrentMap, fSavedMap,
sizeof(key_map)));
fRevertButton->SetEnabled(
kInitialSwitchRight != fSwitchRight->Value()
|| memcmp(fCurrentMap, fSavedMap, sizeof(key_map)));
break;
}
// Ok button
// OK button
case kMsgApplyModifiers:
{
BMessage* updateModifiers = new BMessage(kMsgUpdateModifiers);
if (fSwitchRight->Value() != kInitialSwitchRight) {
int32 rightOptionKey = fCurrentMap->right_option_key;
int32 rightCommandKey = fCurrentMap->right_command_key;
fCurrentMap->right_option_key = rightCommandKey;
fCurrentMap->right_command_key = rightOptionKey;
}
if (fCurrentMap->caps_key != fSavedMap->caps_key)
updateModifiers->AddUInt32("caps_key", fCurrentMap->caps_key);
@ -239,6 +258,8 @@ ModifierKeysWindow::MessageReceived(BMessage* message)
// Revert button
case kMsgRevertModifiers:
fSwitchRight->SetValue(kInitialSwitchRight);
memcpy(fCurrentMap, fSavedMap, sizeof(key_map));
_MarkMenuItems();
@ -316,8 +337,7 @@ ModifierKeysWindow::_CreateOptionMenuField()
BMenuItem* item = new BMenuItem(B_TRANSLATE(_KeyToString(key)),
message);
if (fCurrentMap->left_option_key == _KeyToKeyCode(key)
&& fCurrentMap->right_option_key == _KeyToKeyCode(key, true))
if (fCurrentMap->left_option_key == _KeyToKeyCode(key))
item->SetMarked(true);
fOptionMenu->AddItem(item, key);
@ -340,8 +360,7 @@ ModifierKeysWindow::_CreateCommandMenuField()
BMenuItem* item = new BMenuItem(B_TRANSLATE(_KeyToString(key)),
message);
if (fCurrentMap->left_command_key == _KeyToKeyCode(key)
&& fCurrentMap->right_command_key == _KeyToKeyCode(key, true))
if (fCurrentMap->left_command_key == _KeyToKeyCode(key))
item->SetMarked(true);
fCommandMenu->AddItem(item, key);

View File

@ -10,6 +10,7 @@
#include <Button.h>
#include <CheckBox.h>
#include <InterfaceDefs.h>
#include <MenuField.h>
#include <PopUpMenu.h>
@ -38,7 +39,9 @@ private:
BPopUpMenu* fControlMenu;
BPopUpMenu* fOptionMenu;
BPopUpMenu* fCommandMenu;
BCheckBox* fSwitchRight;
BButton* fRevertButton;
BButton* fCancelButton;
BButton* fOkButton;