| 1 | // Aseprite | 
|---|---|
| 2 | // Copyright (C) 2019-2020 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/reselect_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 ReselectMaskCommand : public Command { | 
| 23 | public: | 
| 24 | ReselectMaskCommand(); | 
| 25 | |
| 26 | protected: | 
| 27 | bool onEnabled(Context* context) override; | 
| 28 | void onExecute(Context* context) override; | 
| 29 | }; | 
| 30 | |
| 31 | ReselectMaskCommand::ReselectMaskCommand() | 
| 32 | : Command(CommandId::ReselectMask(), CmdRecordableFlag) | 
| 33 | { | 
| 34 | } | 
| 35 | |
| 36 | bool ReselectMaskCommand::onEnabled(Context* context) | 
| 37 | { | 
| 38 | if (!context->checkFlags(ContextFlags::ActiveDocumentIsWritable | | 
| 39 | ContextFlags::HasActiveSprite)) | 
| 40 | return false; | 
| 41 | |
| 42 | const ContextReader reader(context); | 
| 43 | const Doc* document(reader.document()); | 
| 44 | return | 
| 45 | document && // The document does exist | 
| 46 | !document->isMaskVisible() && // The mask is hidden | 
| 47 | document->mask() && // The mask does exist | 
| 48 | !document->mask()->isEmpty(); // But it is not empty | 
| 49 | } | 
| 50 | |
| 51 | void ReselectMaskCommand::onExecute(Context* context) | 
| 52 | { | 
| 53 | ContextWriter writer(context); | 
| 54 | Doc* document(writer.document()); | 
| 55 | { | 
| 56 | Tx tx(writer.context(), "Reselect", DoesntModifyDocument); | 
| 57 | tx(new cmd::ReselectMask(document)); | 
| 58 | tx.commit(); | 
| 59 | } | 
| 60 | |
| 61 | update_screen_for_document(document); | 
| 62 | } | 
| 63 | |
| 64 | Command* CommandFactory::createReselectMaskCommand() | 
| 65 | { | 
| 66 | return new ReselectMaskCommand; | 
| 67 | } | 
| 68 | |
| 69 | } // namespace app | 
| 70 | 
