2026-04-06 18:05:34 +08:00
|
|
|
#pragma once
|
|
|
|
|
|
2026-04-10 00:41:28 +08:00
|
|
|
#include <XCEditor/Foundation/UIEditorCommandDispatcher.h>
|
2026-04-06 18:05:34 +08:00
|
|
|
|
|
|
|
|
#include <XCEngine/UI/Input/UIShortcutRegistry.h>
|
|
|
|
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <string_view>
|
|
|
|
|
|
2026-04-06 20:02:34 +08:00
|
|
|
namespace XCEngine::UI::Editor {
|
2026-04-06 18:05:34 +08:00
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-10 16:40:11 +08:00
|
|
|
void SetHostCommandHandler(UIEditorHostCommandHandler* handler) {
|
|
|
|
|
m_commandDispatcher.SetHostCommandHandler(handler);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UIEditorHostCommandHandler* GetHostCommandHandler() const {
|
|
|
|
|
return m_commandDispatcher.GetHostCommandHandler();
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-06 18:05:34 +08:00
|
|
|
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 = {};
|
|
|
|
|
};
|
|
|
|
|
|
2026-04-06 20:02:34 +08:00
|
|
|
} // namespace XCEngine::UI::Editor
|