yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
message_undo_actions.h
Go to the documentation of this file.
1#ifndef YAZE_APP_EDITOR_MESSAGE_UNDO_ACTIONS_H_
2#define YAZE_APP_EDITOR_MESSAGE_UNDO_ACTIONS_H_
3
4#include <cstddef>
5#include <functional>
6#include <string>
7#include <utility>
8
9#include "absl/status/status.h"
10#include "absl/strings/str_format.h"
13
14namespace yaze {
15namespace editor {
16
26
37 public:
38 using ApplyFn = std::function<void(const MessageSnapshot&)>;
39
41 ApplyFn apply_fn)
42 : before_(std::move(before)),
43 after_(std::move(after)),
44 apply_fn_(std::move(apply_fn)) {}
45
46 absl::Status Undo() override {
48 return absl::OkStatus();
49 }
50
51 absl::Status Redo() override {
53 return absl::OkStatus();
54 }
55
56 std::string Description() const override {
57 return absl::StrFormat("Edit message %d", before_.message_index);
58 }
59
60 size_t MemoryUsage() const override {
61 return before_.message.Data.size() + after_.message.Data.size() +
62 before_.parsed_text.size() + after_.parsed_text.size();
63 }
64
65 private:
69};
70
71} // namespace editor
72} // namespace yaze
73
74#endif // YAZE_APP_EDITOR_MESSAGE_UNDO_ACTIONS_H_
Undoable action for message text edits.
MessageEditAction(MessageSnapshot before, MessageSnapshot after, ApplyFn apply_fn)
std::string Description() const override
Human-readable description (e.g., "Paint 12 tiles on map 5")
size_t MemoryUsage() const override
Approximate memory footprint for budget enforcement.
std::function< void(const MessageSnapshot &)> ApplyFn
Abstract base for all undoable actions (Command pattern)
Definition undo_action.h:20
std::vector< uint8_t > Data