Unify inspector and console panel actions

This commit is contained in:
2026-03-27 00:08:46 +08:00
parent 31675e00c8
commit 3ebad63874
15 changed files with 296 additions and 142 deletions

View File

@@ -16,14 +16,11 @@ namespace Editor {
HierarchyPanel::HierarchyPanel() : Panel("Hierarchy") {
}
HierarchyPanel::~HierarchyPanel() {
if (m_context) {
m_context->GetEventBus().Unsubscribe<SelectionChangedEvent>(m_selectionHandlerId);
m_context->GetEventBus().Unsubscribe<EntityRenameRequestedEvent>(m_renameRequestHandlerId);
}
}
void HierarchyPanel::OnAttach() {
if (!m_context || m_selectionHandlerId || m_renameRequestHandlerId) {
return;
}
m_selectionHandlerId = m_context->GetEventBus().Subscribe<SelectionChangedEvent>(
[this](const SelectionChangedEvent& event) {
OnSelectionChanged(event);
@@ -36,6 +33,21 @@ void HierarchyPanel::OnAttach() {
);
}
void HierarchyPanel::OnDetach() {
if (!m_context) {
return;
}
if (m_selectionHandlerId) {
m_context->GetEventBus().Unsubscribe<SelectionChangedEvent>(m_selectionHandlerId);
m_selectionHandlerId = 0;
}
if (m_renameRequestHandlerId) {
m_context->GetEventBus().Unsubscribe<EntityRenameRequestedEvent>(m_renameRequestHandlerId);
m_renameRequestHandlerId = 0;
}
}
void HierarchyPanel::OnSelectionChanged(const SelectionChangedEvent& event) {
if (m_renameState.IsActive() && event.primarySelection != m_renameState.Item()) {
CancelRename();