diff --git a/src/commands/cmd_preview.cpp b/src/commands/cmd_preview.cpp index c22642113..9952c9845 100644 --- a/src/commands/cmd_preview.cpp +++ b/src/commands/cmd_preview.cpp @@ -181,7 +181,8 @@ void PreviewCommand::onExecute(Context* context) if (keypressed()) { int readkey_value = readkey(); Message* msg = jmessage_new_key_related(JM_KEYPRESSED, readkey_value); - Command* command = get_command_from_key_message(msg); + Command* command = NULL; + get_command_from_key_message(msg, &command, NULL); jmessage_free(msg); // Change frame diff --git a/src/dialogs/aniedit.cpp b/src/dialogs/aniedit.cpp index 7717c568c..cb7c080fb 100644 --- a/src/dialogs/aniedit.cpp +++ b/src/dialogs/aniedit.cpp @@ -698,7 +698,9 @@ bool AnimationEditor::onProcessMessage(Message* msg) break; case JM_KEYPRESSED: { - Command *command = get_command_from_key_message(msg); + Command* command = NULL; + Params* params = NULL; + get_command_from_key_message(msg, &command, ¶ms); // Close animation editor. if ((command && (strcmp(command->short_name(), CommandId::FilmEditor) == 0)) || @@ -757,7 +759,7 @@ bool AnimationEditor::onProcessMessage(Message* msg) strcmp(command->short_name(), CommandId::GotoNextLayer) == 0 || strcmp(command->short_name(), CommandId::GotoLastFrame) == 0) { // execute the command - UIContext::instance()->executeCommand(command); + UIContext::instance()->executeCommand(command, params); showCurrentCel(); invalidate(); diff --git a/src/modules/gui.cpp b/src/modules/gui.cpp index 3383472b8..1ec87d253 100644 --- a/src/modules/gui.cpp +++ b/src/modules/gui.cpp @@ -905,20 +905,19 @@ JAccel add_keyboard_shortcut_to_spriteeditor(const char* shortcut_string, const return shortcut->accel; } -Command* get_command_from_key_message(Message* msg) +bool get_command_from_key_message(Message* msg, Command** command, Params** params) { for (std::vector::iterator it = shortcuts->begin(); it != shortcuts->end(); ++it) { Shortcut* shortcut = *it; - if (shortcut->type == Shortcut_ExecuteCommand && - // TODO why? - // shortcut->argument.empty() && - shortcut->is_pressed(msg)) { - return shortcut->command; + if (shortcut->type == Shortcut_ExecuteCommand && shortcut->is_pressed(msg)) { + if (command) *command = shortcut->command; + if (params) *params = shortcut->params; + return true; } } - return NULL; + return false; } JAccel get_accel_to_execute_command(const char* command_name, Params* params) diff --git a/src/modules/gui.h b/src/modules/gui.h index 622055786..abd425ac1 100644 --- a/src/modules/gui.h +++ b/src/modules/gui.h @@ -113,7 +113,7 @@ JAccel add_keyboard_shortcut_to_change_tool(const char* shortcut, tools::Tool* t JAccel add_keyboard_shortcut_to_quicktool(const char* shortcut, tools::Tool* tool); JAccel add_keyboard_shortcut_to_spriteeditor(const char* shortcut, const char* action_name); -Command* get_command_from_key_message(Message* msg); +bool get_command_from_key_message(Message* msg, Command** command, Params** params); JAccel get_accel_to_execute_command(const char* command, Params* params = NULL); JAccel get_accel_to_change_tool(tools::Tool* tool); JAccel get_accel_to_copy_selection(); diff --git a/src/widgets/editor/moving_pixels_state.cpp b/src/widgets/editor/moving_pixels_state.cpp index c83711552..cd2b1b49f 100644 --- a/src/widgets/editor/moving_pixels_state.cpp +++ b/src/widgets/editor/moving_pixels_state.cpp @@ -314,12 +314,13 @@ bool MovingPixelsState::onKeyDown(Editor* editor, Message* msg) return true; } else { - Command* cmd = get_command_from_key_message(msg); - if (cmd) { + Command* command = NULL; + Params* params = NULL; + if (get_command_from_key_message(msg, &command, ¶ms)) { // Intercept the "Cut" or "Copy" command to handle them locally // with the current m_pixelsMovement data. - if (strcmp(cmd->short_name(), CommandId::Cut) == 0 || - strcmp(cmd->short_name(), CommandId::Copy) == 0) { + if (strcmp(command->short_name(), CommandId::Cut) == 0 || + strcmp(command->short_name(), CommandId::Copy) == 0) { // Copy the floating image to the clipboard. { Document* document = editor->getDocument(); @@ -331,7 +332,7 @@ bool MovingPixelsState::onKeyDown(Editor* editor, Message* msg) } // In case of "Cut" command. - if (strcmp(cmd->short_name(), CommandId::Cut) == 0) { + if (strcmp(command->short_name(), CommandId::Cut) == 0) { // Discard the dragged image. m_pixelsMovement->discardImage(); m_discarded = true; @@ -345,8 +346,9 @@ bool MovingPixelsState::onKeyDown(Editor* editor, Message* msg) } // Flip Horizontally/Vertically commands are handled manually to // avoid dropping the floating region of pixels. - else if (strcmp(cmd->short_name(), CommandId::Flip) == 0) { - if (FlipCommand* flipCommand = dynamic_cast(cmd)) { + else if (strcmp(command->short_name(), CommandId::Flip) == 0) { + if (FlipCommand* flipCommand = dynamic_cast(command)) { + flipCommand->loadParams(params); m_pixelsMovement->flipImage(flipCommand->getFlipType()); return true; }