refactor(new_editor): streamline internal layout and command routing

This commit is contained in:
2026-04-15 19:30:58 +08:00
parent 9654f4d91a
commit df8f433fbb
84 changed files with 3250 additions and 3008 deletions

View File

@@ -1,6 +1,7 @@
#include "EditorHostCommandBridge.h"
#include <string>
#include <utility>
namespace XCEngine::UI::Editor::App {
@@ -8,44 +9,32 @@ void EditorHostCommandBridge::BindSession(EditorSession& session) {
m_session = &session;
}
void EditorHostCommandBridge::BindEditCommandRoutes(
EditorEditCommandRoute* hierarchyRoute,
EditorEditCommandRoute* projectRoute) {
m_hierarchyRoute = hierarchyRoute;
m_projectRoute = projectRoute;
}
void EditorHostCommandBridge::SetExitRequestHandler(std::function<void()> handler) {
m_requestExit = std::move(handler);
}
UIEditorHostCommandEvaluationResult EditorHostCommandBridge::EvaluateHostCommand(
std::string_view commandId) const {
UIEditorHostCommandEvaluationResult result = {};
if (commandId == "file.exit") {
result.executable = true;
result.message = "Exit command is ready.";
return result;
return BuildExecutableResult("Exit editor.");
}
if (commandId == "help.about") {
result.executable = true;
result.message = "About placeholder is ready.";
return result;
return BuildDisabledResult("About dialog is unavailable in the current shell.");
}
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.");
return EvaluateUnsupportedHostCommand(commandId);
}
UIEditorHostCommandDispatchResult EditorHostCommandBridge::DispatchHostCommand(
@@ -62,8 +51,7 @@ UIEditorHostCommandDispatchResult EditorHostCommandBridge::DispatchHostCommand(
}
if (commandId == "help.about") {
result.commandExecuted = true;
result.message = "About dialog will be wired after modal layer lands.";
result.message = EvaluateHostCommand(commandId).message;
return result;
}
@@ -83,34 +71,76 @@ UIEditorHostCommandEvaluationResult EditorHostCommandBridge::BuildDisabledResult
return result;
}
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.");
}
UIEditorHostCommandEvaluationResult EditorHostCommandBridge::EvaluateEditCommand(
std::string_view commandId) const {
if (m_session == nullptr) {
return BuildDisabledResult("Editor session is not attached yet.");
return BuildDisabledResult("Editor session is unavailable.");
}
switch (m_session->activeRoute) {
case EditorActionRoute::Hierarchy:
if (SupportsHierarchyEditCommands(commandId)) {
return UIEditorHostCommandEvaluationResult{
true,
"Hierarchy edit route placeholder is active."
};
}
return BuildDisabledResult("Current hierarchy route does not expose this command yet.");
case EditorActionRoute::Project:
if (SupportsProjectEditCommands(commandId)) {
return UIEditorHostCommandEvaluationResult{
true,
"Project edit route placeholder is active."
};
}
return BuildDisabledResult("Current project route does not expose this command yet.");
case EditorActionRoute::None:
if (m_session->activeRoute == EditorActionRoute::None) {
return BuildDisabledResult("No active edit route.");
default:
return BuildDisabledResult("Current panel does not expose edit commands yet.");
}
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);
}
UIEditorHostCommandDispatchResult EditorHostCommandBridge::DispatchEditCommand(
@@ -122,35 +152,47 @@ UIEditorHostCommandDispatchResult EditorHostCommandBridge::DispatchEditCommand(
return result;
}
result.commandExecuted = true;
switch (m_session != nullptr ? m_session->activeRoute : EditorActionRoute::None) {
case EditorActionRoute::Hierarchy:
result.message = "Hierarchy edit command route reached.";
break;
case EditorActionRoute::Project:
result.message = "Project edit command route reached.";
break;
default:
result.message = "Edit command route reached.";
break;
EditorEditCommandRoute* route =
ResolveEditCommandRoute(m_session != nullptr ? m_session->activeRoute : EditorActionRoute::None);
if (route == nullptr) {
result.message = "Edit command route is unavailable.";
return result;
}
return result;
return route->DispatchEditCommand(commandId);
}
bool EditorHostCommandBridge::SupportsHierarchyEditCommands(
UIEditorHostCommandEvaluationResult EditorHostCommandBridge::EvaluateUnsupportedHostCommand(
std::string_view commandId) const {
return commandId == "edit.cut" ||
commandId == "edit.copy" ||
commandId == "edit.paste" ||
commandId == "edit.duplicate" ||
commandId == "edit.delete" ||
commandId == "edit.rename";
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.");
}
bool EditorHostCommandBridge::SupportsProjectEditCommands(
std::string_view commandId) const {
return commandId == "edit.delete" ||
commandId == "edit.rename";
EditorEditCommandRoute* EditorHostCommandBridge::ResolveEditCommandRoute(
EditorActionRoute route) const {
switch (route) {
case EditorActionRoute::Hierarchy:
return m_hierarchyRoute;
case EditorActionRoute::Project:
return m_projectRoute;
default:
return nullptr;
}
}
} // namespace XCEngine::UI::Editor::App