Add support for command key in Mac OS X platform

Other change:
- Fixed ui::Message::onlyCtrl/Shift/AltPressed() member functions
This commit is contained in:
David Capello 2014-08-06 00:42:50 -03:00
parent c104b4812d
commit a856cdf8bd
8 changed files with 86 additions and 54 deletions

View File

@ -7,14 +7,14 @@
<!-- Keyboard shortcuts for commands (menu options) -->
<commands>
<!-- File -->
<key command="NewFile" shortcut="Ctrl+N" />
<key command="OpenFile" shortcut="Ctrl+O" />
<key command="SaveFile" shortcut="Ctrl+S" />
<key command="SaveFileAs" shortcut="Ctrl+Shift+S" />
<key command="SaveFileCopyAs" shortcut="Ctrl+Shift+C" />
<key command="CloseFile" shortcut="Ctrl+W" />
<key command="CloseAllFiles" shortcut="Ctrl+Shift+W" />
<key command="RepeatLastExport" shortcut="Ctrl+Shift+X" />
<key command="NewFile" shortcut="Ctrl+N" mac="Cmd+N" />
<key command="OpenFile" shortcut="Ctrl+O" mac="Cmd+O" />
<key command="SaveFile" shortcut="Ctrl+S" mac="Cmd+S" />
<key command="SaveFileAs" shortcut="Ctrl+Shift+S" mac="Cmd+Shift+S" />
<key command="SaveFileCopyAs" shortcut="Ctrl+Shift+C" mac="Cmd+Shift+C" />
<key command="CloseFile" shortcut="Ctrl+W" mac="Cmd+W" />
<key command="CloseAllFiles" shortcut="Ctrl+Shift+W" mac="Cmd+Shift+W" />
<key command="RepeatLastExport" shortcut="Ctrl+Shift+X" mac="Cmd+Shift+X" />
<key command="AdvancedMode" shortcut="F11" />
<key command="DeveloperConsole" shortcut="F12" />
<key command="Exit" shortcut="Alt+F4" />
@ -22,14 +22,19 @@
<param name="type" value="all" />
</key>
<!-- Edit -->
<key command="Undo" shortcut="Ctrl+Z" /> <key command="Undo" shortcut="Ctrl+U" />
<key command="Redo" shortcut="Ctrl+Y" />
<key command="Redo" shortcut="Ctrl+R" />
<key command="Redo" shortcut="Ctrl+Shift+Z" />
<key command="Cut" shortcut="Ctrl+X" /> <key command="Cut" shortcut="Shift+Del" />
<key command="Copy" shortcut="Ctrl+C" /> <key command="Copy" shortcut="Ctrl+Ins" />
<key command="Paste" shortcut="Ctrl+V" /> <key command="Paste" shortcut="Shift+Ins" />
<key command="Clear" shortcut="Del" /> <key command="Clear" shortcut="Backspace" />
<key command="Undo" shortcut="Ctrl+Z" mac="Cmd+Z" />
<key command="Undo" shortcut="Ctrl+U" mac="Cmd+U" />
<key command="Redo" shortcut="Ctrl+Y" mac="Cmd+Y" />
<key command="Redo" shortcut="Ctrl+R" mac="Cmd+R" />
<key command="Redo" shortcut="Ctrl+Shift+Z" mac="Cmd+Shift+Z" />
<key command="Cut" shortcut="Ctrl+X" mac="Cmd+X" />
<key command="Cut" shortcut="Shift+Del" />
<key command="Copy" shortcut="Ctrl+C" mac="Cmd+C" />
<key command="Copy" shortcut="Ctrl+Ins" mac="Cmd+Ins" />
<key command="Paste" shortcut="Ctrl+V" mac="Cmd+V" />
<key command="Paste" shortcut="Shift+Ins" />
<key command="Clear" shortcut="Del" />
<key command="Clear" shortcut="Backspace" />
<key command="Flip" shortcut="Shift+H">
<param name="target" value="mask" />
<param name="orientation" value="horizontal" />
@ -39,14 +44,14 @@
<param name="orientation" value="vertical" />
</key>
<key command="ReplaceColor" shortcut="Shift+R" />
<key command="InvertColor" shortcut="Ctrl+I" />
<key command="InvertColor" shortcut="Ctrl+I" mac="Cmd+I" />
<key command="ConvolutionMatrix" shortcut="F9" />
<key command="ColorCurve" shortcut="Ctrl+M" />
<key command="ColorCurve" shortcut="Ctrl+M" mac="Cmd+M" />
<key command="ColorCurve" shortcut="F10" />
<key command="ConfigureTools" shortcut="C" />
<key command="Options" shortcut="Ctrl+Shift+O" />
<key command="Options" shortcut="Ctrl+Shift+O" mac="Cmd+Shift+O" />
<!-- Sprite -->
<key command="SpriteProperties" shortcut="Ctrl+P" />
<key command="SpriteProperties" shortcut="Ctrl+P" mac="Cmd+P" />
<!-- Layer -->
<key command="LayerProperties" shortcut="Shift+P" />
<key command="NewLayer" shortcut="Shift+N" />
@ -64,15 +69,15 @@
<key command="GotoFrame" shortcut="Alt+G" />
<key command="PlayAnimation" shortcut="Enter" />
<!-- Select -->
<key command="MaskAll" shortcut="Ctrl+A" />
<key command="DeselectMask" shortcut="Ctrl+D" />
<key command="ReselectMask" shortcut="Ctrl+Shift+D" />
<key command="InvertMask" shortcut="Ctrl+Shift+I" />
<key command="MaskAll" shortcut="Ctrl+A" mac="Cmd+A" />
<key command="DeselectMask" shortcut="Ctrl+D" mac="Cmd+D" />
<key command="ReselectMask" shortcut="Ctrl+Shift+D" mac="Cmd+Shift+D" />
<key command="InvertMask" shortcut="Ctrl+Shift+I" mac="Cmd+Shift+I" />
<!-- View -->
<key command="Refresh" shortcut="F5" />
<key command="MakeUniqueEditor" shortcut="Ctrl+1" />
<key command="SplitEditorVertically" shortcut="Ctrl+2" />
<key command="SplitEditorHorizontally" shortcut="Ctrl+3" />
<key command="MakeUniqueEditor" shortcut="Ctrl+1" mac="Cmd+1" />
<key command="SplitEditorVertically" shortcut="Ctrl+2" mac="Cmd+2" />
<key command="SplitEditorHorizontally" shortcut="Ctrl+3" mac="Cmd+3" />
<key command="Preview" shortcut="F8" />
<key command="ShowGrid" shortcut="Shift+G" />
<key command="SnapToGrid" shortcut="Shift+S" />
@ -84,8 +89,8 @@
<param name="switch" value="true" />
</key>
<!-- Tabs -->
<key command="GotoNextTab" shortcut="Ctrl+Tab" />
<key command="GotoPreviousTab" shortcut="Ctrl+Shift+Tab" />
<key command="GotoNextTab" shortcut="Ctrl+Tab" mac="Cmd+Tab" />
<key command="GotoPreviousTab" shortcut="Ctrl+Shift+Tab" mac="Cmd+Shift+Tab" />
<!-- Others -->
<key command="SwitchColors" shortcut="X" />
<key command="ChangeColor" shortcut="9">
@ -105,11 +110,11 @@
<param name="change" value="increment-index" />
</key>
<key command="ChangeColor" shortcut="Ctrl+9">
<param name="target" value="background" />
<param name="target" value="background" mac="Cmd+9" />
<param name="change" value="decrement-index" />
</key>
<key command="ChangeColor" shortcut="Ctrl+0">
<param name="target" value="background" />
<param name="target" value="background" mac="Cmd+0" />
<param name="change" value="increment-index" />
</key>
@ -128,22 +133,22 @@
</key>
<!-- Scroll with cursor -->
<key command="Scroll" shortcut="Ctrl+Left">
<key command="Scroll" shortcut="Ctrl+Left" mac="Cmd+Left">
<param name="direction" value="left" />
<param name="units" value="zoomed-tile-width" />
<param name="quantity" value="1" />
</key>
<key command="Scroll" shortcut="Ctrl+Right">
<key command="Scroll" shortcut="Ctrl+Right" mac="Cmd+Right">
<param name="direction" value="right" />
<param name="units" value="zoomed-tile-width" />
<param name="quantity" value="1" />
</key>
<key command="Scroll" shortcut="Ctrl+Up">
<key command="Scroll" shortcut="Ctrl+Up" mac="Cmd+Up">
<param name="direction" value="up" />
<param name="units" value="zoomed-tile-height" />
<param name="quantity" value="1" />
</key>
<key command="Scroll" shortcut="Ctrl+Down">
<key command="Scroll" shortcut="Ctrl+Down" mac="Cmd+Down">
<param name="direction" value="down" />
<param name="units" value="zoomed-tile-height" />
<param name="quantity" value="1" />

View File

@ -108,7 +108,7 @@ void AppMenus::reload()
.FirstChild("key").ToElement();
while (xmlKey) {
const char* command_name = xmlKey->Attribute("command");
const char* command_key = xmlKey->Attribute("shortcut");
const char* command_key = getShortcut(xmlKey);
if (command_name && command_key) {
Command* command = CommandsModule::instance()->getCommandByName(command_name);
@ -157,7 +157,7 @@ void AppMenus::reload()
.FirstChild("key").ToElement();
while (xmlKey) {
const char* tool_id = xmlKey->Attribute("tool");
const char* tool_key = xmlKey->Attribute("shortcut");
const char* tool_key = getShortcut(xmlKey);
if (tool_id && tool_key) {
tools::Tool* tool = App::instance()->getToolBox()->getToolById(tool_id);
@ -178,8 +178,7 @@ void AppMenus::reload()
.FirstChild("key").ToElement();
while (xmlKey) {
const char* tool_id = xmlKey->Attribute("tool");
const char* tool_key = xmlKey->Attribute("shortcut");
const char* tool_key = getShortcut(xmlKey);
if (tool_id && tool_key) {
tools::Tool* tool = App::instance()->getToolBox()->getToolById(tool_id);
if (tool) {
@ -199,7 +198,7 @@ void AppMenus::reload()
.FirstChild("key").ToElement();
while (xmlKey) {
const char* tool_action = xmlKey->Attribute("action");
const char* tool_key = xmlKey->Attribute("shortcut");
const char* tool_key = getShortcut(xmlKey);
if (tool_action && tool_key) {
PRINTF(" - Shortcut for sprite editor `%s': <%s>\n", tool_action, tool_key);
@ -394,4 +393,22 @@ void AppMenus::applyShortcutToMenuitemsWithCommand(Menu* menu, Command *command,
}
}
const char* AppMenus::getShortcut(TiXmlElement* elem)
{
const char* shortcut = NULL;
#if defined ALLEGRO_WINDOWS
if (!shortcut) shortcut = elem->Attribute("win");
#elif defined ALLEGRO_MACOSX
if (!shortcut) shortcut = elem->Attribute("mac");
#elif defined ALLEGRO_UNIX
if (!shortcut) shortcut = elem->Attribute("linux");
#endif
if (!shortcut)
shortcut = elem->Attribute("shortcut");
return shortcut;
}
} // namespace app

View File

@ -65,6 +65,7 @@ namespace app {
Widget* convertXmlelemToMenuitem(TiXmlElement* elem);
Widget* createInvalidVersionMenuitem();
void applyShortcutToMenuitemsWithCommand(Menu* menu, Command* command, Params* params, Accelerator* accel);
const char* getShortcut(TiXmlElement* elem);
base::UniquePtr<Menu> m_rootMenu;
MenuItem* m_recentListMenuitem;

View File

@ -58,6 +58,9 @@ static void process_one_word(Accelerator* accel, char* word)
else if (ustricmp (tok, "Ctrl") == 0) {
modifiers = (KeyModifiers)((int)modifiers | (int)kKeyCtrlModifier);
}
else if (ustricmp (tok, "Cmd") == 0) {
modifiers = (KeyModifiers)((int)modifiers | (int)kKeyCmdModifier);
}
// Scancode
@ -313,14 +316,10 @@ std::string Accelerator::KeyCombo::toString()
ustrcpy(buf, "");
// Shifts
if (this->modifiers & kKeyCtrlModifier)
ustrcat(buf, "Ctrl+");
if (this->modifiers & kKeyAltModifier)
ustrcat(buf, "Alt+");
if (this->modifiers & kKeyShiftModifier)
ustrcat(buf, "Shift+");
if (this->modifiers & kKeyCtrlModifier) ustrcat(buf, "Ctrl+");
if (this->modifiers & kKeyCmdModifier) ustrcat(buf, "Cmd+");
if (this->modifiers & kKeyAltModifier) ustrcat(buf, "Alt+");
if (this->modifiers & kKeyShiftModifier) ustrcat(buf, "Shift+");
// Key
if (this->unicodeChar)
@ -440,6 +439,7 @@ bool Accelerator::checkFromAllegroKeyArray()
if (key[KEY_LCONTROL]) modifiers = (KeyModifiers)((int)modifiers | (int)kKeyCtrlModifier);
if (key[KEY_RCONTROL]) modifiers = (KeyModifiers)((int)modifiers | (int)kKeyCtrlModifier);
if (key[KEY_ALT] ) modifiers = (KeyModifiers)((int)modifiers | (int)kKeyAltModifier);
if (key[KEY_COMMAND ]) modifiers = (KeyModifiers)((int)modifiers | (int)kKeyCmdModifier);
for (KeyCombos::iterator it = m_combos.begin(), end = m_combos.end();
it != end; ++it) {

View File

@ -266,7 +266,12 @@ bool Entry::onProcessMessage(Message* msg)
}
else {
// Map common Windows shortcuts for Cut/Copy/Paste
if (msg->onlyCtrlPressed()) {
#if defined ALLEGRO_MACOSX
if (msg->onlyCmdPressed())
#else
if (msg->onlyCtrlPressed())
#endif
{
switch (scancode) {
case kKeyX: cmd = EntryCmd::Cut; break;
case kKeyC: cmd = EntryCmd::Copy; break;

View File

@ -14,7 +14,8 @@ namespace ui {
kKeyNoneModifier = 0,
kKeyShiftModifier = 1,
kKeyCtrlModifier = 2,
kKeyAltModifier = 4
kKeyAltModifier = 4,
kKeyCmdModifier = 8
};
enum KeyScancode {

View File

@ -24,7 +24,8 @@ Message::Message(MessageType type)
, m_used(false)
, m_modifiers((KeyModifiers)((key[KEY_LSHIFT] || key[KEY_RSHIFT] ? kKeyShiftModifier: 0) |
(key[KEY_LCONTROL] || key[KEY_RCONTROL] ? kKeyCtrlModifier: 0) |
(key[KEY_ALT] ? kKeyAltModifier: 0)))
(key[KEY_ALT] ? kKeyAltModifier: 0) |
(key[KEY_COMMAND] ? kKeyCmdModifier: 0)))
{
}

View File

@ -42,9 +42,11 @@ namespace ui {
bool shiftPressed() const { return (m_modifiers & kKeyShiftModifier) == kKeyShiftModifier; }
bool ctrlPressed() const { return (m_modifiers & kKeyCtrlModifier) == kKeyCtrlModifier; }
bool altPressed() const { return (m_modifiers & kKeyAltModifier) == kKeyAltModifier; }
bool onlyShiftPressed() const { return (m_modifiers & kKeyShiftModifier) == kKeyShiftModifier; }
bool onlyCtrlPressed() const { return (m_modifiers & kKeyCtrlModifier) == kKeyCtrlModifier; }
bool onlyAltPressed() const { return (m_modifiers & kKeyAltModifier) == kKeyAltModifier; }
bool cmdPressed() const { return (m_modifiers & kKeyCmdModifier) == kKeyCmdModifier; }
bool onlyShiftPressed() const { return m_modifiers == kKeyShiftModifier; }
bool onlyCtrlPressed() const { return m_modifiers == kKeyCtrlModifier; }
bool onlyAltPressed() const { return m_modifiers == kKeyAltModifier; }
bool onlyCmdPressed() const { return m_modifiers == kKeyCmdModifier; }
void addRecipient(Widget* widget);
void prependRecipient(Widget* widget);