1 | // Aseprite |
---|---|
2 | // Copyright (C) 2020 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_user_data.h" |
13 | |
14 | #include "app/doc.h" |
15 | #include "app/doc_event.h" |
16 | #include "doc/sprite.h" |
17 | |
18 | #include "doc/with_user_data.h" |
19 | |
20 | namespace app { |
21 | namespace cmd { |
22 | |
23 | SetUserData::SetUserData(doc::WithUserData* obj, |
24 | const doc::UserData& userData, |
25 | app::Doc* doc) |
26 | : WithDocument(doc) |
27 | , m_objId(obj->id()) |
28 | , m_oldUserData(obj->userData()) |
29 | , m_newUserData(userData) |
30 | { |
31 | } |
32 | |
33 | void SetUserData::onExecute() |
34 | { |
35 | auto obj = doc::get<doc::WithUserData>(m_objId); |
36 | obj->setUserData(m_newUserData); |
37 | obj->incrementVersion(); |
38 | } |
39 | |
40 | void SetUserData::onUndo() |
41 | { |
42 | auto obj = doc::get<doc::WithUserData>(m_objId); |
43 | obj->setUserData(m_oldUserData); |
44 | obj->incrementVersion(); |
45 | } |
46 | |
47 | void SetUserData::onFireNotifications() |
48 | { |
49 | auto obj = doc::get<doc::WithUserData>(m_objId); |
50 | app::Doc* doc = document(); |
51 | DocEvent ev(doc); |
52 | ev.withUserData(obj); |
53 | doc->notify_observers<DocEvent&>(&DocObserver::onUserDataChange, ev); |
54 | } |
55 | |
56 | } // namespace cmd |
57 | } // namespace app |
58 |