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/cmd/set_layer_name.h" |
12 | |
13 | #include "app/doc.h" |
14 | #include "app/doc_event.h" |
15 | #include "doc/layer.h" |
16 | #include "doc/sprite.h" |
17 | |
18 | namespace app { |
19 | namespace cmd { |
20 | |
21 | SetLayerName::SetLayerName(Layer* layer, const std::string& name) |
22 | : WithLayer(layer) |
23 | , m_oldName(layer->name()) |
24 | , m_newName(name) |
25 | { |
26 | } |
27 | |
28 | void SetLayerName::onExecute() |
29 | { |
30 | layer()->setName(m_newName); |
31 | layer()->incrementVersion(); |
32 | } |
33 | |
34 | void SetLayerName::onUndo() |
35 | { |
36 | layer()->setName(m_oldName); |
37 | layer()->incrementVersion(); |
38 | } |
39 | |
40 | void SetLayerName::onFireNotifications() |
41 | { |
42 | Layer* layer = this->layer(); |
43 | Doc* doc = static_cast<Doc*>(layer->sprite()->document()); |
44 | DocEvent ev(doc); |
45 | ev.sprite(layer->sprite()); |
46 | ev.layer(layer); |
47 | doc->notify_observers<DocEvent&>(&DocObserver::onLayerNameChange, ev); |
48 | } |
49 | |
50 | } // namespace cmd |
51 | } // namespace app |
52 |