Files
XCEngine/new_editor/include/XCEditor/Foundation/UIEditorCommandDispatcher.h

108 lines
3.0 KiB
C
Raw Normal View History

#pragma once
2026-04-10 00:41:28 +08:00
#include <XCEditor/Foundation/UIEditorCommandRegistry.h>
#include <cstdint>
#include <string>
#include <string_view>
namespace XCEngine::UI::Editor {
2026-04-10 16:40:11 +08:00
struct UIEditorHostCommandEvaluationResult {
bool executable = false;
std::string message = {};
};
struct UIEditorHostCommandDispatchResult {
bool commandExecuted = false;
std::string message = {};
};
class UIEditorHostCommandHandler {
public:
virtual ~UIEditorHostCommandHandler() = default;
virtual UIEditorHostCommandEvaluationResult EvaluateHostCommand(
std::string_view commandId) const = 0;
virtual UIEditorHostCommandDispatchResult DispatchHostCommand(
std::string_view commandId) = 0;
};
enum class UIEditorCommandEvaluationCode : std::uint8_t {
None = 0,
InvalidCommandRegistry,
UnknownCommandId,
2026-04-10 16:40:11 +08:00
MissingActivePanel,
MissingHostCommandHandler,
HostCommandDisabled
};
struct UIEditorCommandEvaluationResult {
UIEditorCommandEvaluationCode code = UIEditorCommandEvaluationCode::None;
bool executable = false;
std::string commandId = {};
std::string displayName = {};
UIEditorWorkspaceCommand workspaceCommand = {};
UIEditorWorkspaceCommandResult previewResult = {};
std::string message = {};
2026-04-10 16:40:11 +08:00
UIEditorCommandKind kind = UIEditorCommandKind::Workspace;
[[nodiscard]] bool IsExecutable() const {
return executable;
}
};
enum class UIEditorCommandDispatchStatus : std::uint8_t {
Dispatched = 0,
Rejected
};
struct UIEditorCommandDispatchResult {
UIEditorCommandDispatchStatus status = UIEditorCommandDispatchStatus::Rejected;
bool commandExecuted = false;
std::string commandId = {};
std::string displayName = {};
UIEditorWorkspaceCommand workspaceCommand = {};
UIEditorWorkspaceCommandResult commandResult = {};
std::string message = {};
2026-04-10 16:40:11 +08:00
UIEditorCommandKind kind = UIEditorCommandKind::Workspace;
};
std::string_view GetUIEditorCommandDispatchStatusName(
UIEditorCommandDispatchStatus status);
class UIEditorCommandDispatcher {
public:
UIEditorCommandDispatcher() = default;
explicit UIEditorCommandDispatcher(UIEditorCommandRegistry commandRegistry);
const UIEditorCommandRegistry& GetCommandRegistry() const {
return m_commandRegistry;
}
2026-04-10 16:40:11 +08:00
void SetHostCommandHandler(UIEditorHostCommandHandler* handler) {
m_hostCommandHandler = handler;
}
UIEditorHostCommandHandler* GetHostCommandHandler() const {
return m_hostCommandHandler;
}
UIEditorCommandRegistryValidationResult ValidateConfiguration() const;
UIEditorCommandEvaluationResult Evaluate(
std::string_view commandId,
const UIEditorWorkspaceController& controller) const;
UIEditorCommandDispatchResult Dispatch(
std::string_view commandId,
UIEditorWorkspaceController& controller) const;
private:
UIEditorCommandRegistry m_commandRegistry = {};
2026-04-10 16:40:11 +08:00
UIEditorHostCommandHandler* m_hostCommandHandler = nullptr;
};
} // namespace XCEngine::UI::Editor