Route editor actions by active target

This commit is contained in:
2026-03-26 22:10:43 +08:00
parent 5c8042775c
commit 5735e769b0
21 changed files with 609 additions and 104 deletions

View File

@@ -1,3 +1,4 @@
#include "Actions/ActionRouting.h"
#include "Actions/EditorActions.h"
#include "Commands/ProjectCommands.h"
#include "ProjectPanel.h"
@@ -32,6 +33,9 @@ void ProjectPanel::Render() {
if (!panel.IsOpen()) {
return;
}
Actions::ObserveFocusedActionRoute(*m_context, EditorActionRoute::Project);
HandleKeyboardShortcuts();
auto& manager = m_context->GetProjectManager();
@@ -146,6 +150,30 @@ void ProjectPanel::Render() {
}
}
AssetItemPtr ProjectPanel::GetSelectedItem() const {
return m_context ? Actions::GetSelectedAssetItem(*m_context) : nullptr;
}
void ProjectPanel::HandleKeyboardShortcuts() {
if (!m_context) {
return;
}
auto& manager = m_context->GetProjectManager();
const AssetItemPtr selectedItem = GetSelectedItem();
const Actions::ShortcutContext shortcutContext = Actions::FocusedWindowShortcutContext();
Actions::HandleShortcut(Actions::MakeNavigateBackAction(manager.CanNavigateBack()), shortcutContext, [&]() {
manager.NavigateBack();
});
Actions::HandleShortcut(Actions::MakeOpenAssetAction(Commands::CanOpenAsset(selectedItem)), shortcutContext, [&]() {
Commands::OpenAsset(*m_context, selectedItem);
});
Actions::HandleShortcut(Actions::MakeDeleteAssetAction(selectedItem != nullptr), shortcutContext, [&]() {
Commands::DeleteAsset(manager, manager.GetSelectedIndex());
});
}
void ProjectPanel::RenderAssetItem(const AssetItemPtr& item, int index) {
auto& manager = m_context->GetProjectManager();
bool isSelected = (manager.GetSelectedIndex() == index);