1
0
mirror of https://github.com/aseprite/aseprite.git synced 2025-04-02 13:20:12 +00:00

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

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

@ -108,7 +108,7 @@ void AppMenus::reload()
.FirstChild("key").ToElement(); .FirstChild("key").ToElement();
while (xmlKey) { while (xmlKey) {
const char* command_name = xmlKey->Attribute("command"); 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) { if (command_name && command_key) {
Command* command = CommandsModule::instance()->getCommandByName(command_name); Command* command = CommandsModule::instance()->getCommandByName(command_name);
@ -157,7 +157,7 @@ void AppMenus::reload()
.FirstChild("key").ToElement(); .FirstChild("key").ToElement();
while (xmlKey) { while (xmlKey) {
const char* tool_id = xmlKey->Attribute("tool"); 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) { if (tool_id && tool_key) {
tools::Tool* tool = App::instance()->getToolBox()->getToolById(tool_id); tools::Tool* tool = App::instance()->getToolBox()->getToolById(tool_id);
@ -178,8 +178,7 @@ void AppMenus::reload()
.FirstChild("key").ToElement(); .FirstChild("key").ToElement();
while (xmlKey) { while (xmlKey) {
const char* tool_id = xmlKey->Attribute("tool"); 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) { if (tool_id && tool_key) {
tools::Tool* tool = App::instance()->getToolBox()->getToolById(tool_id); tools::Tool* tool = App::instance()->getToolBox()->getToolById(tool_id);
if (tool) { if (tool) {
@ -199,7 +198,7 @@ void AppMenus::reload()
.FirstChild("key").ToElement(); .FirstChild("key").ToElement();
while (xmlKey) { while (xmlKey) {
const char* tool_action = xmlKey->Attribute("action"); 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) { if (tool_action && tool_key) {
PRINTF(" - Shortcut for sprite editor `%s': <%s>\n", 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 } // namespace app

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

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

@ -266,7 +266,12 @@ bool Entry::onProcessMessage(Message* msg)
} }
else { else {
// Map common Windows shortcuts for Cut/Copy/Paste // 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) { switch (scancode) {
case kKeyX: cmd = EntryCmd::Cut; break; case kKeyX: cmd = EntryCmd::Cut; break;
case kKeyC: cmd = EntryCmd::Copy; break; case kKeyC: cmd = EntryCmd::Copy; break;

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

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

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