1 | // Aseprite |
---|---|
2 | // Copyright (C) 2019-2022 Igara Studio S.A. |
3 | // Copyright (C) 2001-2015 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/set_tag_name.h" |
13 | |
14 | #include "app/doc.h" |
15 | #include "app/doc_event.h" |
16 | #include "doc/sprite.h" |
17 | #include "doc/tag.h" |
18 | #include "doc/tags.h" |
19 | |
20 | namespace app { |
21 | namespace cmd { |
22 | |
23 | SetTagName::SetTagName(doc::Tag* tag, const std::string& name) |
24 | : WithTag(tag) |
25 | , m_oldName(tag->name()) |
26 | , m_newName(name) |
27 | { |
28 | } |
29 | |
30 | void SetTagName::onExecute() |
31 | { |
32 | tag()->setName(m_newName); |
33 | tag()->incrementVersion(); |
34 | } |
35 | |
36 | void SetTagName::onUndo() |
37 | { |
38 | tag()->setName(m_oldName); |
39 | tag()->incrementVersion(); |
40 | } |
41 | |
42 | void SetTagName::onFireNotifications() |
43 | { |
44 | Tag* tag = this->tag(); |
45 | Sprite* sprite = tag->owner()->sprite(); |
46 | Doc* doc = static_cast<Doc*>(sprite->document()); |
47 | DocEvent ev(doc); |
48 | ev.sprite(sprite); |
49 | ev.tag(tag); |
50 | doc->notify_observers<DocEvent&>(&DocObserver::onTagRename, ev); |
51 | } |
52 | |
53 | } // namespace cmd |
54 | } // namespace app |
55 |