| 1 | // Aseprite |
|---|---|
| 2 | // Copyright (C) 2001-2017 David Capello |
| 3 | // |
| 4 | // This program is distributed under the terms of |
| 5 | // the End-User License Agreement for Aseprite. |
| 6 | |
| 7 | #ifdef HAVE_CONFIG_H |
| 8 | #include "config.h" |
| 9 | #endif |
| 10 | |
| 11 | #include "app/commands/command.h" |
| 12 | |
| 13 | #include "app/app.h" |
| 14 | #include "app/commands/commands.h" |
| 15 | #include "app/commands/params.h" |
| 16 | #include "app/context.h" |
| 17 | #include "app/ui/input_chain.h" |
| 18 | |
| 19 | namespace app { |
| 20 | |
| 21 | class CancelCommand : public Command { |
| 22 | public: |
| 23 | enum Type { |
| 24 | NoOp, |
| 25 | All, |
| 26 | }; |
| 27 | |
| 28 | CancelCommand(); |
| 29 | |
| 30 | protected: |
| 31 | bool onNeedsParams() const override { return true; } |
| 32 | void onLoadParams(const Params& params) override; |
| 33 | void onExecute(Context* context) override; |
| 34 | |
| 35 | private: |
| 36 | Type m_type; |
| 37 | }; |
| 38 | |
| 39 | CancelCommand::CancelCommand() |
| 40 | : Command(CommandId::Cancel(), CmdUIOnlyFlag) |
| 41 | , m_type(NoOp) |
| 42 | { |
| 43 | } |
| 44 | |
| 45 | void CancelCommand::onLoadParams(const Params& params) |
| 46 | { |
| 47 | std::string type = params.get("type"); |
| 48 | if (type == "noop") m_type = NoOp; |
| 49 | else if (type == "all") m_type = All; |
| 50 | } |
| 51 | |
| 52 | void CancelCommand::onExecute(Context* context) |
| 53 | { |
| 54 | switch (m_type) { |
| 55 | |
| 56 | case NoOp: |
| 57 | // Do nothing. |
| 58 | break; |
| 59 | |
| 60 | case All: |
| 61 | // TODO should the ContextBar be a InputChainElement to intercept onCancel()? |
| 62 | // Discard brush |
| 63 | { |
| 64 | Command* discardBrush = Commands::instance()->byId( |
| 65 | CommandId::DiscardBrush()); |
| 66 | context->executeCommand(discardBrush); |
| 67 | } |
| 68 | |
| 69 | App::instance()->inputChain().cancel(context); |
| 70 | break; |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | Command* CommandFactory::createCancelCommand() |
| 75 | { |
| 76 | return new CancelCommand; |
| 77 | } |
| 78 | |
| 79 | } // namespace app |
| 80 |