108 lines
3.0 KiB
C++
108 lines
3.0 KiB
C++
#pragma once
|
|
|
|
#include <XCEditor/Foundation/UIEditorCommandRegistry.h>
|
|
|
|
#include <cstdint>
|
|
#include <string>
|
|
#include <string_view>
|
|
|
|
namespace XCEngine::UI::Editor {
|
|
|
|
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,
|
|
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 = {};
|
|
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 = {};
|
|
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;
|
|
}
|
|
|
|
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 = {};
|
|
UIEditorHostCommandHandler* m_hostCommandHandler = nullptr;
|
|
};
|
|
|
|
} // namespace XCEngine::UI::Editor
|