Files
XCEngine/editor/src/Core/UndoManager.h
ssdfasd 5c3566774b docs: 更新 containers 和 threading 模块文档
- containers: 更新 string 类的多个方法文档
- threading: 更新 mutex 和 task-group 方法文档
2026-03-26 01:59:14 +08:00

61 lines
1.6 KiB
C++

#pragma once
#include "IUndoManager.h"
#include <optional>
#include <string>
#include <vector>
namespace XCEngine {
namespace Editor {
class ISelectionManager;
class SceneManager;
class UndoManager : public IUndoManager {
public:
UndoManager(SceneManager& sceneManager, ISelectionManager& selectionManager);
void ClearHistory() override;
bool CanUndo() const override;
bool CanRedo() const override;
const std::string& GetUndoLabel() const override;
const std::string& GetRedoLabel() const override;
void Undo() override;
void Redo() override;
UndoStateSnapshot CaptureCurrentState() const override;
void PushCommand(const std::string& label, UndoStateSnapshot before, UndoStateSnapshot after) override;
void BeginInteractiveChange(const std::string& label) override;
bool HasPendingInteractiveChange() const override;
void FinalizeInteractiveChange() override;
void CancelInteractiveChange() override;
private:
struct CommandEntry {
std::string label;
UndoStateSnapshot before;
UndoStateSnapshot after;
};
struct PendingInteractiveChange {
std::string label;
UndoStateSnapshot before;
};
bool ApplyState(const UndoStateSnapshot& state);
static bool AreStatesEqual(const UndoStateSnapshot& lhs, const UndoStateSnapshot& rhs);
SceneManager& m_sceneManager;
ISelectionManager& m_selectionManager;
std::vector<CommandEntry> m_history;
size_t m_nextIndex = 0;
std::optional<PendingInteractiveChange> m_pendingInteractiveChange;
std::string m_emptyLabel;
};
} // namespace Editor
} // namespace XCEngine