#pragma once #include #include #include #include #include namespace XCEngine::UI::Editor { enum class UIEditorShortcutManagerValidationCode : std::uint8_t { None = 0, InvalidCommandRegistry, EmptyBindingCommandId, UnknownCommandId, MissingScopedOwnerId, EmptyShortcutKey, ConflictingBinding }; struct UIEditorShortcutManagerValidationResult { UIEditorShortcutManagerValidationCode code = UIEditorShortcutManagerValidationCode::None; std::string message = {}; [[nodiscard]] bool IsValid() const { return code == UIEditorShortcutManagerValidationCode::None; } }; enum class UIEditorShortcutDispatchStatus : std::uint8_t { NoMatch = 0, Suppressed, Dispatched, Rejected }; struct UIEditorShortcutDispatchResult { UIEditorShortcutDispatchStatus status = UIEditorShortcutDispatchStatus::NoMatch; bool matched = false; bool commandExecuted = false; std::string commandId = {}; std::string commandDisplayName = {}; std::string message = {}; XCEngine::UI::UIShortcutScope shortcutScope = XCEngine::UI::UIShortcutScope::Global; XCEngine::UI::UIElementId shortcutOwnerId = 0; UIEditorWorkspaceCommandResult commandResult = {}; }; std::string_view GetUIEditorShortcutDispatchStatusName( UIEditorShortcutDispatchStatus status); class UIEditorShortcutManager { public: UIEditorShortcutManager() = default; explicit UIEditorShortcutManager(UIEditorCommandRegistry commandRegistry); const UIEditorCommandDispatcher& GetCommandDispatcher() const { return m_commandDispatcher; } void SetHostCommandHandler(UIEditorHostCommandHandler* handler) { m_commandDispatcher.SetHostCommandHandler(handler); } UIEditorHostCommandHandler* GetHostCommandHandler() const { return m_commandDispatcher.GetHostCommandHandler(); } const UIEditorCommandRegistry& GetCommandRegistry() const { return m_commandDispatcher.GetCommandRegistry(); } const XCEngine::UI::UIShortcutRegistry& GetShortcutRegistry() const { return m_shortcutRegistry; } std::uint64_t RegisterBinding(const XCEngine::UI::UIShortcutBinding& binding); bool UnregisterBinding(std::uint64_t bindingId); void ClearBindings(); UIEditorShortcutManagerValidationResult ValidateConfiguration() const; std::string GetPreferredShortcutText(std::string_view commandId) const; UIEditorShortcutDispatchResult Dispatch( const XCEngine::UI::UIInputEvent& event, const XCEngine::UI::UIShortcutContext& shortcutContext, UIEditorWorkspaceController& controller) const; private: UIEditorShortcutDispatchResult BuildDispatchResult( UIEditorShortcutDispatchStatus status, std::string commandId, std::string commandDisplayName, std::string message, const XCEngine::UI::UIShortcutMatch* match = nullptr) const; const XCEngine::UI::UIShortcutBinding* FindPreferredBinding( std::string_view commandId) const; UIEditorCommandDispatcher m_commandDispatcher = {}; XCEngine::UI::UIShortcutRegistry m_shortcutRegistry = {}; }; } // namespace XCEngine::UI::Editor