| 1 | // Aseprite |
|---|---|
| 2 | // Copyright (C) 2019 Igara Studio S.A. |
| 3 | // Copyright (C) 2001-2018 David Capello |
| 4 | // |
| 5 | // This program is distributed under the terms of |
| 6 | // the End-User License Agreement for Aseprite. |
| 7 | |
| 8 | #ifdef HAVE_CONFIG_H |
| 9 | #include "config.h" |
| 10 | #endif |
| 11 | |
| 12 | #include "app/cmd/deselect_mask.h" |
| 13 | #include "app/commands/command.h" |
| 14 | #include "app/context_access.h" |
| 15 | #include "app/modules/gui.h" |
| 16 | #include "app/tx.h" |
| 17 | #include "doc/mask.h" |
| 18 | #include "doc/sprite.h" |
| 19 | |
| 20 | namespace app { |
| 21 | |
| 22 | class DeselectMaskCommand : public Command { |
| 23 | public: |
| 24 | DeselectMaskCommand(); |
| 25 | |
| 26 | protected: |
| 27 | bool onEnabled(Context* context) override; |
| 28 | void onExecute(Context* context) override; |
| 29 | }; |
| 30 | |
| 31 | DeselectMaskCommand::DeselectMaskCommand() |
| 32 | : Command(CommandId::DeselectMask(), CmdRecordableFlag) |
| 33 | { |
| 34 | } |
| 35 | |
| 36 | bool DeselectMaskCommand::onEnabled(Context* context) |
| 37 | { |
| 38 | return context->checkFlags(ContextFlags::ActiveDocumentIsWritable | |
| 39 | ContextFlags::HasVisibleMask); |
| 40 | } |
| 41 | |
| 42 | void DeselectMaskCommand::onExecute(Context* context) |
| 43 | { |
| 44 | ContextWriter writer(context); |
| 45 | Doc* document(writer.document()); |
| 46 | { |
| 47 | Tx tx(writer.context(), "Deselect", DoesntModifyDocument); |
| 48 | tx(new cmd::DeselectMask(document)); |
| 49 | tx.commit(); |
| 50 | } |
| 51 | update_screen_for_document(document); |
| 52 | } |
| 53 | |
| 54 | Command* CommandFactory::createDeselectMaskCommand() |
| 55 | { |
| 56 | return new DeselectMaskCommand; |
| 57 | } |
| 58 | |
| 59 | } // namespace app |
| 60 |