Keymap: Add ability to remove a key mapping

... of a normal (non-modifier) key via a right click menu.
This commit is contained in:
John Scipione
2015-01-07 21:11:39 -05:00
parent 6aa4d138bf
commit b433c2ad87
4 changed files with 133 additions and 107 deletions
+15 -5
View File
@@ -215,11 +215,20 @@ KeyboardLayoutView::MouseDown(BPoint point)
&& (modifiers() & B_CONTROL_KEY) != 0)) { && (modifiers() & B_CONTROL_KEY) != 0)) {
// secondary mouse button, pop up a swap context menu // secondary mouse button, pop up a swap context menu
if (!is_mappable_to_modifier(key->code)) { if (!is_mappable_to_modifier(key->code)) {
// ToDo: pop up a list of alternative characters // ToDo: Pop up a list of alternative characters to map
fButtons = buttons; // the key to. Currently we only add an option to remove the
return; // current key mapping.
} BPopUpMenu* alternativesPopUp = new BPopUpMenu(
"Alternatives pop up", true, true, B_ITEMS_IN_COLUMN);
BMessage* message = new BMessage(kMsgUpdateNormalKeys);
message->AddUInt32("keyCode", key->code);
message->AddBool("unset", true);
alternativesPopUp->AddItem(new BMenuItem(B_TRANSLATE("Remove"),
message));
alternativesPopUp->SetAsyncAutoDestruct(true);
if (alternativesPopUp->SetTargetForItems(Window()) == B_OK)
alternativesPopUp->Go(ConvertToScreen(point), true);
} else {
// pop up the modifier keys menu // pop up the modifier keys menu
BPopUpMenu* modifiersPopUp = new BPopUpMenu("Modifiers pop up", BPopUpMenu* modifiersPopUp = new BPopUpMenu("Modifiers pop up",
true, true, B_ITEMS_IN_COLUMN); true, true, B_ITEMS_IN_COLUMN);
@@ -321,6 +330,7 @@ KeyboardLayoutView::MouseDown(BPoint point)
modifiersPopUp->SetAsyncAutoDestruct(true); modifiersPopUp->SetAsyncAutoDestruct(true);
if (modifiersPopUp->SetTargetForItems(Window()) == B_OK) if (modifiersPopUp->SetTargetForItems(Window()) == B_OK)
modifiersPopUp->Go(ConvertToScreen(point), true); modifiersPopUp->Go(ConvertToScreen(point), true);
}
} else if ((buttons & B_TERTIARY_MOUSE_BUTTON) != 0 } else if ((buttons & B_TERTIARY_MOUSE_BUTTON) != 0
&& (fButtons & B_TERTIARY_MOUSE_BUTTON) == 0) { && (fButtons & B_TERTIARY_MOUSE_BUTTON) == 0) {
// tertiary mouse button, toggle the "deadness" of dead keys // tertiary mouse button, toggle the "deadness" of dead keys
+1 -1
View File
@@ -374,7 +374,7 @@ Keymap::SetKey(uint32 keyCode, uint32 modifiers, int8 deadKey,
if (offset < 0) if (offset < 0)
return; return;
if (numBytes == -1) if (numBytes < 0)
numBytes = strlen(bytes); numBytes = strlen(bytes);
if (numBytes > 6) if (numBytes > 6)
return; return;
+2 -1
View File
@@ -23,7 +23,8 @@
static const uint32 kMsgShowModifierKeysWindow = 'smkw'; static const uint32 kMsgShowModifierKeysWindow = 'smkw';
static const uint32 kMsgCloseModifierKeysWindow = 'hmkw'; static const uint32 kMsgCloseModifierKeysWindow = 'hmkw';
static const uint32 kMsgUpdateModifierKeys = 'umks'; static const uint32 kMsgUpdateModifierKeys = 'umod';
static const uint32 kMsgUpdateNormalKeys = 'ukey';
class KeymapApplication : public BApplication { class KeymapApplication : public BApplication {
+15
View File
@@ -320,6 +320,21 @@ KeymapWindow::MessageReceived(BMessage* message)
_UpdateButtons(); _UpdateButtons();
break; break;
case kMsgUpdateNormalKeys:
{
uint32 keyCode;
if (message->FindUInt32("keyCode", &keyCode) != B_OK)
break;
bool unset;
if (message->FindBool("unset", &unset) == B_OK && unset) {
fCurrentMap.SetKey(keyCode, modifiers(), 0, "", 0);
_UpdateButtons();
fKeyboardLayoutView->SetKeymap(&fCurrentMap);
}
break;
}
case kMsgUpdateModifierKeys: case kMsgUpdateModifierKeys:
{ {
uint32 keyCode; uint32 keyCode;