#pragma once #include "Core/IEditorContext.h" #include "Core/IUndoManager.h" #include #include namespace XCEngine { namespace Editor { namespace UndoUtils { template 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::forward(func)(); undoManager.PushCommand(label, std::move(before), undoManager.CaptureCurrentState()); } else { auto result = std::forward(func)(); undoManager.PushCommand(label, std::move(before), undoManager.CaptureCurrentState()); return result; } } } // namespace UndoUtils } // namespace Editor } // namespace XCEngine