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