| 1 | // Aseprite |
|---|---|
| 2 | // Copyright (C) 2001-2018 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/app.h" |
| 12 | #include "app/commands/command.h" |
| 13 | #include "app/console.h" |
| 14 | #include "app/context_access.h" |
| 15 | #include "app/doc_undo.h" |
| 16 | #include "app/doc_api.h" |
| 17 | #include "app/modules/editors.h" |
| 18 | #include "app/modules/gui.h" |
| 19 | #include "app/tx.h" |
| 20 | #include "app/ui/editor/editor.h" |
| 21 | #include "doc/layer.h" |
| 22 | #include "doc/sprite.h" |
| 23 | #include "ui/ui.h" |
| 24 | |
| 25 | namespace app { |
| 26 | |
| 27 | class DuplicateLayerCommand : public Command { |
| 28 | public: |
| 29 | DuplicateLayerCommand(); |
| 30 | |
| 31 | protected: |
| 32 | bool onEnabled(Context* context) override; |
| 33 | void onExecute(Context* context) override; |
| 34 | }; |
| 35 | |
| 36 | DuplicateLayerCommand::DuplicateLayerCommand() |
| 37 | : Command(CommandId::DuplicateLayer(), CmdRecordableFlag) |
| 38 | { |
| 39 | } |
| 40 | |
| 41 | bool DuplicateLayerCommand::onEnabled(Context* context) |
| 42 | { |
| 43 | return context->checkFlags(ContextFlags::ActiveDocumentIsWritable | |
| 44 | ContextFlags::HasActiveLayer); |
| 45 | } |
| 46 | |
| 47 | void DuplicateLayerCommand::onExecute(Context* context) |
| 48 | { |
| 49 | ContextWriter writer(context); |
| 50 | Doc* document = writer.document(); |
| 51 | |
| 52 | { |
| 53 | Tx tx(writer.context(), "Layer Duplication"); |
| 54 | LayerImage* sourceLayer = static_cast<LayerImage*>(writer.layer()); |
| 55 | DocApi api = document->getApi(tx); |
| 56 | api.duplicateLayerAfter(sourceLayer, |
| 57 | sourceLayer->parent(), |
| 58 | sourceLayer); |
| 59 | tx.commit(); |
| 60 | } |
| 61 | |
| 62 | update_screen_for_document(document); |
| 63 | } |
| 64 | |
| 65 | Command* CommandFactory::createDuplicateLayerCommand() |
| 66 | { |
| 67 | return new DuplicateLayerCommand; |
| 68 | } |
| 69 | |
| 70 | } // namespace app |
| 71 |