2026-04-15 08:24:06 +08:00
|
|
|
#include "EditorHostCommandBridge.h"
|
2026-04-12 01:49:08 +08:00
|
|
|
|
|
|
|
|
#include <string>
|
2026-04-15 19:30:58 +08:00
|
|
|
#include <utility>
|
2026-04-12 01:49:08 +08:00
|
|
|
|
|
|
|
|
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 19:30:58 +08:00
|
|
|
void EditorHostCommandBridge::BindEditCommandRoutes(
|
|
|
|
|
EditorEditCommandRoute* hierarchyRoute,
|
|
|
|
|
EditorEditCommandRoute* projectRoute) {
|
|
|
|
|
m_hierarchyRoute = hierarchyRoute;
|
|
|
|
|
m_projectRoute = projectRoute;
|
|
|
|
|
}
|
|
|
|
|
|
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 {
|
|
|
|
|
if (commandId == "file.exit") {
|
2026-04-15 19:30:58 +08:00
|
|
|
return BuildExecutableResult("Exit editor.");
|
2026-04-12 01:49:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (commandId == "help.about") {
|
2026-04-15 19:30:58 +08:00
|
|
|
return BuildDisabledResult("About dialog is unavailable in the current shell.");
|
2026-04-12 01:49:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (commandId.rfind("edit.", 0u) == 0u) {
|
|
|
|
|
return EvaluateEditCommand(commandId);
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-15 19:30:58 +08:00
|
|
|
return EvaluateUnsupportedHostCommand(commandId);
|
2026-04-12 01:49:08 +08:00
|
|
|
}
|
|
|
|
|
|
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") {
|
2026-04-15 19:30:58 +08:00
|
|
|
result.message = EvaluateHostCommand(commandId).message;
|
2026-04-12 01:49:08 +08:00
|
|
|
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 19:30:58 +08:00
|
|
|
UIEditorHostCommandEvaluationResult EditorHostCommandBridge::BuildExecutableResult(
|
|
|
|
|
std::string_view message) const {
|
|
|
|
|
UIEditorHostCommandEvaluationResult result = {};
|
|
|
|
|
result.executable = true;
|
|
|
|
|
result.message = std::string(message);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UIEditorHostCommandEvaluationResult EditorHostCommandBridge::EvaluateFileCommand(
|
|
|
|
|
std::string_view commandId) const {
|
|
|
|
|
if (commandId == "file.exit") {
|
|
|
|
|
return BuildExecutableResult("Exit editor.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return BuildDisabledResult(
|
|
|
|
|
"Only file.exit has a bound host owner in the current shell.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UIEditorHostCommandEvaluationResult EditorHostCommandBridge::EvaluateAssetCommand(
|
|
|
|
|
std::string_view commandId) const {
|
|
|
|
|
(void)commandId;
|
|
|
|
|
return BuildDisabledResult(
|
|
|
|
|
"Asset commands have no bound Project/AssetDatabase owner in the current shell.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UIEditorHostCommandEvaluationResult EditorHostCommandBridge::EvaluateRunCommand(
|
|
|
|
|
std::string_view commandId) const {
|
|
|
|
|
(void)commandId;
|
|
|
|
|
return BuildDisabledResult(
|
|
|
|
|
"Run commands have no bound play-mode owner in the current shell.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UIEditorHostCommandEvaluationResult EditorHostCommandBridge::EvaluateScriptCommand(
|
|
|
|
|
std::string_view commandId) const {
|
|
|
|
|
(void)commandId;
|
|
|
|
|
return BuildDisabledResult(
|
|
|
|
|
"Script commands have no bound script-pipeline owner in the current shell.");
|
|
|
|
|
}
|
|
|
|
|
|
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) {
|
2026-04-15 19:30:58 +08:00
|
|
|
return BuildDisabledResult("Editor session is unavailable.");
|
2026-04-12 01:49:08 +08:00
|
|
|
}
|
|
|
|
|
|
2026-04-15 19:30:58 +08:00
|
|
|
if (m_session->activeRoute == EditorActionRoute::None) {
|
2026-04-12 01:49:08 +08:00
|
|
|
return BuildDisabledResult("No active edit route.");
|
|
|
|
|
}
|
2026-04-15 19:30:58 +08:00
|
|
|
|
|
|
|
|
EditorEditCommandRoute* route = ResolveEditCommandRoute(m_session->activeRoute);
|
|
|
|
|
if (route == nullptr) {
|
|
|
|
|
switch (m_session->activeRoute) {
|
|
|
|
|
case EditorActionRoute::Hierarchy:
|
|
|
|
|
return BuildDisabledResult("Hierarchy command route is unavailable in the current window.");
|
|
|
|
|
case EditorActionRoute::Project:
|
|
|
|
|
return BuildDisabledResult("Project command route is unavailable in the current window.");
|
|
|
|
|
case EditorActionRoute::Inspector:
|
|
|
|
|
return BuildDisabledResult("Inspector does not expose edit commands yet.");
|
|
|
|
|
case EditorActionRoute::Console:
|
|
|
|
|
return BuildDisabledResult("Console does not expose edit commands yet.");
|
|
|
|
|
case EditorActionRoute::Scene:
|
|
|
|
|
case EditorActionRoute::Game:
|
|
|
|
|
return BuildDisabledResult("Viewport panels do not expose edit commands yet.");
|
|
|
|
|
case EditorActionRoute::None:
|
|
|
|
|
default:
|
|
|
|
|
return BuildDisabledResult("Current panel does not expose edit commands.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return route->EvaluateEditCommand(commandId);
|
2026-04-12 01:49:08 +08:00
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-15 19:30:58 +08:00
|
|
|
EditorEditCommandRoute* route =
|
|
|
|
|
ResolveEditCommandRoute(m_session != nullptr ? m_session->activeRoute : EditorActionRoute::None);
|
|
|
|
|
if (route == nullptr) {
|
|
|
|
|
result.message = "Edit command route is unavailable.";
|
|
|
|
|
return result;
|
2026-04-12 01:49:08 +08:00
|
|
|
}
|
2026-04-15 19:30:58 +08:00
|
|
|
|
|
|
|
|
return route->DispatchEditCommand(commandId);
|
2026-04-12 01:49:08 +08:00
|
|
|
}
|
|
|
|
|
|
2026-04-15 19:30:58 +08:00
|
|
|
UIEditorHostCommandEvaluationResult EditorHostCommandBridge::EvaluateUnsupportedHostCommand(
|
2026-04-12 01:49:08 +08:00
|
|
|
std::string_view commandId) const {
|
2026-04-15 19:30:58 +08:00
|
|
|
if (commandId.rfind("file.", 0u) == 0u) {
|
|
|
|
|
return EvaluateFileCommand(commandId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (commandId.rfind("assets.", 0u) == 0u) {
|
|
|
|
|
return EvaluateAssetCommand(commandId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (commandId.rfind("run.", 0u) == 0u) {
|
|
|
|
|
return EvaluateRunCommand(commandId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (commandId.rfind("scripts.", 0u) == 0u) {
|
|
|
|
|
return EvaluateScriptCommand(commandId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return BuildDisabledResult("Host command has no owner in the current shell.");
|
2026-04-12 01:49:08 +08:00
|
|
|
}
|
|
|
|
|
|
2026-04-15 19:30:58 +08:00
|
|
|
EditorEditCommandRoute* EditorHostCommandBridge::ResolveEditCommandRoute(
|
|
|
|
|
EditorActionRoute route) const {
|
|
|
|
|
switch (route) {
|
|
|
|
|
case EditorActionRoute::Hierarchy:
|
|
|
|
|
return m_hierarchyRoute;
|
|
|
|
|
case EditorActionRoute::Project:
|
|
|
|
|
return m_projectRoute;
|
|
|
|
|
default:
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
2026-04-12 01:49:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace XCEngine::UI::Editor::App
|
2026-04-15 08:24:06 +08:00
|
|
|
|