Update semantic shortcuts

Update BKeymap::GetModifiedCharacters() to translate a given character
and set of modifiers filling out a list of all characters that match for another
set of modifiers.

This allows us to, for example, get all characters in the normal map that
have the '+' character in the corresponding shift map.

It is fully generic allowing one to get a list of characters in any map given
a character and modifiers of another map.

Also I converted from using a BList to using a BObjectList.

With this, along with BWindow::HasShortcut(), the semantic shortcuts now
work not only with Command+'=', but any key in the normal map that has
'+' in it's shift map as long as it isn't already taken by another shortcut.
This commit is contained in:
John Scipione
2013-10-19 19:30:47 -04:00
parent 26a23118e7
commit bd336e3abc
4 changed files with 89 additions and 68 deletions
+19 -20
View File
@@ -53,6 +53,7 @@ All rights reserved.
#include <Path.h>
#include <PopUpMenu.h>
#include <Screen.h>
#include <UnicodeChar.h>
#include <Volume.h>
#include <VolumeRoster.h>
#include <Roster.h>
@@ -937,26 +938,6 @@ BContainerWindow::Init(const BMessage* message)
AddShortcuts();
}
BKeymap keymap;
keymap.SetToCurrent();
BList shiftChars;
if (keymap.GetModifiedCharacters("=", B_SHIFT_KEY, &shiftChars)
== B_OK) {
int32 count = shiftChars.CountItems();
for (int32 i = 0; i < count; i++) {
if (strcmp((const char*)shiftChars.ItemAt(i), "+") == 0) {
// Add semantic zoom in shortcut, bug #6692
BMessage* increaseSize = new BMessage(kIconMode);
increaseSize->AddInt32("scale", 1);
AddShortcut('=', B_COMMAND_KEY, increaseSize, PoseView());
break;
}
}
}
while (!shiftChars.IsEmpty())
delete (const char*)shiftChars.RemoveItem((int32)0);
shiftChars.MakeEmpty();
AddContextMenus();
AddShortcut('T', B_COMMAND_KEY | B_SHIFT_KEY, new BMessage(kDelete),
PoseView());
@@ -982,6 +963,24 @@ BContainerWindow::Init(const BMessage* message)
new BMessage('dpfL'), PoseView());
#endif
BKeymap keymap;
keymap.SetToCurrent();
BObjectList<const char> unmodified(3, true);
if (keymap.GetModifiedCharacters("+", B_SHIFT_KEY, 0, &unmodified)
== B_OK) {
int32 count = unmodified.CountItems();
for (int32 i = 0; i < count; i++) {
uint32 key = BUnicodeChar::FromUTF8(unmodified.ItemAt(i));
if (!HasShortcut(key, 0)) {
// Add semantic zoom in shortcut, bug #6692
BMessage* increaseSize = new BMessage(kIconMode);
increaseSize->AddInt32("scale", 1);
AddShortcut(key, B_COMMAND_KEY, increaseSize, PoseView());
}
}
}
unmodified.MakeEmpty();
if (message)
RestoreState(*message);
else