2026-04-15 08:24:06 +08:00
|
|
|
#include "EditorHostCommandBridge.h"
|
2026-04-12 01:49:08 +08:00
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
|
|
namespace XCEngine::UI::Editor::App {
|
|
|
|
|
|
2026-04-15 08:24:06 +08:00
|
|
|
void EditorHostCommandBridge::BindSession(EditorSession& session) {
|
2026-04-12 01:49:08 +08:00
|
|
|
m_session = &session;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-15 08:24:06 +08:00
|
|
|
void EditorHostCommandBridge::SetExitRequestHandler(std::function<void()> handler) {
|
2026-04-12 01:49:08 +08:00
|
|
|
m_requestExit = std::move(handler);
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-15 08:24:06 +08:00
|
|
|
UIEditorHostCommandEvaluationResult EditorHostCommandBridge::EvaluateHostCommand(
|
2026-04-12 01:49:08 +08:00
|
|
|
std::string_view commandId) const {
|
|
|
|
|
UIEditorHostCommandEvaluationResult result = {};
|
|
|
|
|
|
|
|
|
|
if (commandId == "file.exit") {
|
|
|
|
|
result.executable = true;
|
|
|
|
|
result.message = "Exit command is ready.";
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (commandId == "help.about") {
|
|
|
|
|
result.executable = true;
|
|
|
|
|
result.message = "About placeholder is ready.";
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (commandId.rfind("edit.", 0u) == 0u) {
|
|
|
|
|
return EvaluateEditCommand(commandId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (commandId.rfind("file.", 0u) == 0u) {
|
|
|
|
|
return BuildDisabledResult("Document command bridge is not attached yet.");
|
|
|
|
|
}
|
|
|
|
|
if (commandId.rfind("assets.", 0u) == 0u) {
|
|
|
|
|
return BuildDisabledResult("Asset pipeline bridge is not attached yet.");
|
|
|
|
|
}
|
|
|
|
|
if (commandId.rfind("run.", 0u) == 0u) {
|
|
|
|
|
return BuildDisabledResult("Runtime bridge is not attached yet.");
|
|
|
|
|
}
|
|
|
|
|
if (commandId.rfind("scripts.", 0u) == 0u) {
|
|
|
|
|
return BuildDisabledResult("Script pipeline bridge is not attached yet.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return BuildDisabledResult("Host command is not attached yet.");
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-15 08:24:06 +08:00
|
|
|
UIEditorHostCommandDispatchResult EditorHostCommandBridge::DispatchHostCommand(
|
2026-04-12 01:49:08 +08:00
|
|
|
std::string_view commandId) {
|
|
|
|
|
UIEditorHostCommandDispatchResult result = {};
|
|
|
|
|
|
|
|
|
|
if (commandId == "file.exit") {
|
|
|
|
|
result.commandExecuted = true;
|
|
|
|
|
result.message = "Exit requested.";
|
|
|
|
|
if (m_requestExit) {
|
|
|
|
|
m_requestExit();
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (commandId == "help.about") {
|
|
|
|
|
result.commandExecuted = true;
|
|
|
|
|
result.message = "About dialog will be wired after modal layer lands.";
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (commandId.rfind("edit.", 0u) == 0u) {
|
|
|
|
|
return DispatchEditCommand(commandId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result.message = EvaluateHostCommand(commandId).message;
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-15 08:24:06 +08:00
|
|
|
UIEditorHostCommandEvaluationResult EditorHostCommandBridge::BuildDisabledResult(
|
2026-04-12 01:49:08 +08:00
|
|
|
std::string_view message) const {
|
|
|
|
|
UIEditorHostCommandEvaluationResult result = {};
|
|
|
|
|
result.executable = false;
|
|
|
|
|
result.message = std::string(message);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-15 08:24:06 +08:00
|
|
|
UIEditorHostCommandEvaluationResult EditorHostCommandBridge::EvaluateEditCommand(
|
2026-04-12 01:49:08 +08:00
|
|
|
std::string_view commandId) const {
|
|
|
|
|
if (m_session == nullptr) {
|
|
|
|
|
return BuildDisabledResult("Editor session is not attached yet.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (m_session->activeRoute) {
|
2026-04-15 08:24:06 +08:00
|
|
|
case EditorActionRoute::Hierarchy:
|
2026-04-12 01:49:08 +08:00
|
|
|
if (SupportsHierarchyEditCommands(commandId)) {
|
|
|
|
|
return UIEditorHostCommandEvaluationResult{
|
|
|
|
|
true,
|
|
|
|
|
"Hierarchy edit route placeholder is active."
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
return BuildDisabledResult("Current hierarchy route does not expose this command yet.");
|
2026-04-15 08:24:06 +08:00
|
|
|
case EditorActionRoute::Project:
|
2026-04-12 01:49:08 +08:00
|
|
|
if (SupportsProjectEditCommands(commandId)) {
|
|
|
|
|
return UIEditorHostCommandEvaluationResult{
|
|
|
|
|
true,
|
|
|
|
|
"Project edit route placeholder is active."
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
return BuildDisabledResult("Current project route does not expose this command yet.");
|
2026-04-15 08:24:06 +08:00
|
|
|
case EditorActionRoute::None:
|
2026-04-12 01:49:08 +08:00
|
|
|
return BuildDisabledResult("No active edit route.");
|
|
|
|
|
default:
|
|
|
|
|
return BuildDisabledResult("Current panel does not expose edit commands yet.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-15 08:24:06 +08:00
|
|
|
UIEditorHostCommandDispatchResult EditorHostCommandBridge::DispatchEditCommand(
|
2026-04-12 01:49:08 +08:00
|
|
|
std::string_view commandId) {
|
|
|
|
|
UIEditorHostCommandDispatchResult result = {};
|
|
|
|
|
const UIEditorHostCommandEvaluationResult evaluation = EvaluateEditCommand(commandId);
|
|
|
|
|
if (!evaluation.executable) {
|
|
|
|
|
result.message = evaluation.message;
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result.commandExecuted = true;
|
2026-04-15 08:24:06 +08:00
|
|
|
switch (m_session != nullptr ? m_session->activeRoute : EditorActionRoute::None) {
|
|
|
|
|
case EditorActionRoute::Hierarchy:
|
2026-04-12 01:49:08 +08:00
|
|
|
result.message = "Hierarchy edit command route reached.";
|
|
|
|
|
break;
|
2026-04-15 08:24:06 +08:00
|
|
|
case EditorActionRoute::Project:
|
2026-04-12 01:49:08 +08:00
|
|
|
result.message = "Project edit command route reached.";
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
result.message = "Edit command route reached.";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-15 08:24:06 +08:00
|
|
|
bool EditorHostCommandBridge::SupportsHierarchyEditCommands(
|
2026-04-12 01:49:08 +08:00
|
|
|
std::string_view commandId) const {
|
|
|
|
|
return commandId == "edit.cut" ||
|
|
|
|
|
commandId == "edit.copy" ||
|
|
|
|
|
commandId == "edit.paste" ||
|
|
|
|
|
commandId == "edit.duplicate" ||
|
|
|
|
|
commandId == "edit.delete" ||
|
|
|
|
|
commandId == "edit.rename";
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-15 08:24:06 +08:00
|
|
|
bool EditorHostCommandBridge::SupportsProjectEditCommands(
|
2026-04-12 01:49:08 +08:00
|
|
|
std::string_view commandId) const {
|
|
|
|
|
return commandId == "edit.delete" ||
|
|
|
|
|
commandId == "edit.rename";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace XCEngine::UI::Editor::App
|
2026-04-15 08:24:06 +08:00
|
|
|
|