refactor(new_editor): streamline internal layout and command routing
This commit is contained in:
120
new_editor/app/Features/Hierarchy/HierarchyPanelCommands.cpp
Normal file
120
new_editor/app/Features/Hierarchy/HierarchyPanelCommands.cpp
Normal file
@@ -0,0 +1,120 @@
|
||||
#include "HierarchyPanelSupport.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
namespace XCEngine::UI::Editor::App {
|
||||
|
||||
namespace {
|
||||
|
||||
UIEditorHostCommandEvaluationResult BuildEvaluationResult(
|
||||
bool executable,
|
||||
std::string message) {
|
||||
UIEditorHostCommandEvaluationResult result = {};
|
||||
result.executable = executable;
|
||||
result.message = std::move(message);
|
||||
return result;
|
||||
}
|
||||
|
||||
UIEditorHostCommandDispatchResult BuildDispatchResult(
|
||||
bool commandExecuted,
|
||||
std::string message) {
|
||||
UIEditorHostCommandDispatchResult result = {};
|
||||
result.commandExecuted = commandExecuted;
|
||||
result.message = std::move(message);
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
UIEditorHostCommandEvaluationResult HierarchyPanel::EvaluateEditCommand(
|
||||
std::string_view commandId) const {
|
||||
const HierarchyNode* selectedNode = GetSelectedNode();
|
||||
if (selectedNode == nullptr) {
|
||||
return BuildEvaluationResult(false, "Select a hierarchy object first.");
|
||||
}
|
||||
|
||||
if (commandId == "edit.rename") {
|
||||
return BuildEvaluationResult(
|
||||
true,
|
||||
"Rename hierarchy object '" + selectedNode->label + "'.");
|
||||
}
|
||||
|
||||
if (commandId == "edit.delete") {
|
||||
return BuildEvaluationResult(
|
||||
true,
|
||||
"Delete hierarchy object '" + selectedNode->label + "'.");
|
||||
}
|
||||
|
||||
if (commandId == "edit.duplicate") {
|
||||
return BuildEvaluationResult(
|
||||
true,
|
||||
"Duplicate hierarchy object '" + selectedNode->label + "'.");
|
||||
}
|
||||
|
||||
if (commandId == "edit.cut" ||
|
||||
commandId == "edit.copy" ||
|
||||
commandId == "edit.paste") {
|
||||
return BuildEvaluationResult(
|
||||
false,
|
||||
"Hierarchy clipboard has no bound transfer owner in the current shell.");
|
||||
}
|
||||
|
||||
return BuildEvaluationResult(false, "Hierarchy does not expose this edit command.");
|
||||
}
|
||||
|
||||
UIEditorHostCommandDispatchResult HierarchyPanel::DispatchEditCommand(
|
||||
std::string_view commandId) {
|
||||
const UIEditorHostCommandEvaluationResult evaluation = EvaluateEditCommand(commandId);
|
||||
if (!evaluation.executable) {
|
||||
return BuildDispatchResult(false, evaluation.message);
|
||||
}
|
||||
|
||||
const HierarchyNode* selectedNode = GetSelectedNode();
|
||||
if (selectedNode == nullptr) {
|
||||
return BuildDispatchResult(false, "Select a hierarchy object first.");
|
||||
}
|
||||
|
||||
const std::string selectedNodeId = selectedNode->nodeId;
|
||||
const std::string selectedNodeLabel = selectedNode->label;
|
||||
|
||||
if (commandId == "edit.rename") {
|
||||
EmitRenameRequestedEvent(selectedNodeId);
|
||||
return BuildDispatchResult(
|
||||
true,
|
||||
"Hierarchy rename requested for '" + selectedNodeLabel + "'.");
|
||||
}
|
||||
|
||||
if (commandId == "edit.delete") {
|
||||
if (!m_model.DeleteNode(selectedNodeId)) {
|
||||
return BuildDispatchResult(false, "Failed to delete the selected hierarchy object.");
|
||||
}
|
||||
|
||||
RebuildItems();
|
||||
EmitSelectionEvent();
|
||||
return BuildDispatchResult(
|
||||
true,
|
||||
"Deleted hierarchy object '" + selectedNodeLabel + "'.");
|
||||
}
|
||||
|
||||
if (commandId == "edit.duplicate") {
|
||||
const std::string duplicatedNodeId = m_model.DuplicateNode(selectedNodeId);
|
||||
if (duplicatedNodeId.empty()) {
|
||||
return BuildDispatchResult(false, "Failed to duplicate the selected hierarchy object.");
|
||||
}
|
||||
|
||||
RebuildItems();
|
||||
m_selection.SetSelection(duplicatedNodeId);
|
||||
EmitSelectionEvent();
|
||||
|
||||
const HierarchyNode* duplicatedNode = m_model.FindNode(duplicatedNodeId);
|
||||
const std::string duplicatedLabel =
|
||||
duplicatedNode != nullptr ? duplicatedNode->label : selectedNodeLabel;
|
||||
return BuildDispatchResult(
|
||||
true,
|
||||
"Duplicated hierarchy object '" + duplicatedLabel + "'.");
|
||||
}
|
||||
|
||||
return BuildDispatchResult(false, "Hierarchy does not expose this edit command.");
|
||||
}
|
||||
|
||||
} // namespace XCEngine::UI::Editor::App
|
||||
Reference in New Issue
Block a user