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

35 lines
967 B
C++

#pragma once
#include "Core/IEditorContext.h"
#include "Core/IUndoManager.h"
#include <type_traits>
#include <utility>
namespace XCEngine {
namespace Editor {
namespace UndoUtils {
template<typename Func>
auto ExecuteSceneCommand(IEditorContext& context, const std::string& label, Func&& func) {
auto& undoManager = context.GetUndoManager();
if (undoManager.HasPendingInteractiveChange()) {
undoManager.FinalizeInteractiveChange();
}
auto before = undoManager.CaptureCurrentState();
if constexpr (std::is_void_v<std::invoke_result_t<Func>>) {
std::forward<Func>(func)();
undoManager.PushCommand(label, std::move(before), undoManager.CaptureCurrentState());
} else {
auto result = std::forward<Func>(func)();
undoManager.PushCommand(label, std::move(before), undoManager.CaptureCurrentState());
return result;
}
}
} // namespace UndoUtils
} // namespace Editor
} // namespace XCEngine