| 1 | // Aseprite | 
|---|---|
| 2 | // Copyright (C) 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 | #include "app/context_access.h" | 
| 13 | #include "app/modules/gui.h" | 
| 14 | #include "doc/layer.h" | 
| 15 | |
| 16 | namespace app { | 
| 17 | |
| 18 | using namespace ui; | 
| 19 | |
| 20 | class OpenGroupCommand : public Command { | 
| 21 | public: | 
| 22 | OpenGroupCommand(); | 
| 23 | |
| 24 | protected: | 
| 25 | bool onEnabled(Context* context) override; | 
| 26 | bool onChecked(Context* context) override; | 
| 27 | void onExecute(Context* context) override; | 
| 28 | |
| 29 | // TODO onGetFriendlyName() needs the Context so we can return "Open | 
| 30 | // Group" or "Close Group" depending on the context | 
| 31 | //std::string onGetFriendlyName() const override; | 
| 32 | }; | 
| 33 | |
| 34 | OpenGroupCommand::OpenGroupCommand() | 
| 35 | : Command(CommandId::OpenGroup(), CmdRecordableFlag) | 
| 36 | { | 
| 37 | } | 
| 38 | |
| 39 | bool OpenGroupCommand::onEnabled(Context* context) | 
| 40 | { | 
| 41 | const ContextReader reader(context); | 
| 42 | const Layer* layer = reader.layer(); | 
| 43 | return (layer && layer->isGroup()); | 
| 44 | } | 
| 45 | |
| 46 | bool OpenGroupCommand::onChecked(Context* context) | 
| 47 | { | 
| 48 | const ContextReader reader(context); | 
| 49 | const Layer* layer = reader.layer(); | 
| 50 | return (layer && layer->isExpanded()); | 
| 51 | } | 
| 52 | |
| 53 | void OpenGroupCommand::onExecute(Context* context) | 
| 54 | { | 
| 55 | ContextWriter writer(context); | 
| 56 | Layer* layer = writer.layer(); | 
| 57 | |
| 58 | layer->setCollapsed(layer->isExpanded()); | 
| 59 | |
| 60 | update_screen_for_document(writer.document()); | 
| 61 | } | 
| 62 | |
| 63 | Command* CommandFactory::createOpenGroupCommand() | 
| 64 | { | 
| 65 | return new OpenGroupCommand; | 
| 66 | } | 
| 67 | |
| 68 | } // namespace app | 
| 69 | 
