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/cmd/unlink_cel.h" |
13 | #include "app/commands/command.h" |
14 | #include "app/context_access.h" |
15 | #include "app/i18n/strings.h" |
16 | #include "app/modules/gui.h" |
17 | #include "app/tx.h" |
18 | #include "app/ui/status_bar.h" |
19 | #include "doc/cel.h" |
20 | #include "doc/layer.h" |
21 | #include "doc/sprite.h" |
22 | |
23 | namespace app { |
24 | |
25 | class UnlinkCelCommand : public Command { |
26 | public: |
27 | UnlinkCelCommand(); |
28 | |
29 | protected: |
30 | bool onEnabled(Context* context) override; |
31 | void onExecute(Context* context) override; |
32 | }; |
33 | |
34 | UnlinkCelCommand::UnlinkCelCommand() |
35 | : Command(CommandId::UnlinkCel(), CmdRecordableFlag) |
36 | { |
37 | } |
38 | |
39 | bool UnlinkCelCommand::onEnabled(Context* context) |
40 | { |
41 | return context->checkFlags(ContextFlags::ActiveDocumentIsWritable); |
42 | } |
43 | |
44 | void UnlinkCelCommand::onExecute(Context* context) |
45 | { |
46 | ContextWriter writer(context); |
47 | Doc* document(writer.document()); |
48 | bool nonEditableLayers = false; |
49 | { |
50 | Tx tx(writer.context(), "Unlink Cel"); |
51 | |
52 | const Site* site = writer.site(); |
53 | if (site->inTimeline() && |
54 | !site->selectedLayers().empty()) { |
55 | for (Layer* layer : site->selectedLayers()) { |
56 | if (!layer->isImage()) |
57 | continue; |
58 | |
59 | if (!layer->isEditableHierarchy()) { |
60 | nonEditableLayers = true; |
61 | continue; |
62 | } |
63 | |
64 | LayerImage* layerImage = static_cast<LayerImage*>(layer); |
65 | |
66 | for (frame_t frame : site->selectedFrames().reversed()) { |
67 | Cel* cel = layerImage->cel(frame); |
68 | if (cel && cel->links()) |
69 | tx(new cmd::UnlinkCel(cel)); |
70 | } |
71 | } |
72 | } |
73 | else { |
74 | Cel* cel = writer.cel(); |
75 | if (cel && cel->links()) { |
76 | if (cel->layer()->isEditableHierarchy()) |
77 | tx(new cmd::UnlinkCel(writer.cel())); |
78 | else |
79 | nonEditableLayers = true; |
80 | } |
81 | } |
82 | |
83 | tx.commit(); |
84 | } |
85 | |
86 | if (nonEditableLayers) |
87 | StatusBar::instance()->showTip(1000, |
88 | Strings::statusbar_tips_locked_layers()); |
89 | |
90 | update_screen_for_document(document); |
91 | } |
92 | |
93 | Command* CommandFactory::createUnlinkCelCommand() |
94 | { |
95 | return new UnlinkCelCommand; |
96 | } |
97 | |
98 | } // namespace app |
99 |