52 lines
2.2 KiB
Markdown
52 lines
2.2 KiB
Markdown
|
|
# EditActionRouter
|
||
|
|
|
||
|
|
**命名空间**: `XCEngine::Editor::Actions`
|
||
|
|
|
||
|
|
**类型**: `header-helper`
|
||
|
|
|
||
|
|
**源文件**: `editor/src/Actions/EditActionRouter.h`
|
||
|
|
|
||
|
|
**描述**: 把全局 Edit 菜单和快捷键解析为上下文敏感的实体编辑或资源编辑动作。
|
||
|
|
|
||
|
|
## 概述
|
||
|
|
|
||
|
|
`EditActionRouter` 是当前编辑器“上下文式编辑命令”的核心桥接层。它先通过 `ResolveEditActionTarget` 读取:
|
||
|
|
|
||
|
|
- 当前活动路由 `EditorActionRoute`
|
||
|
|
- 当前选中的实体
|
||
|
|
- 当前选中的资源项
|
||
|
|
|
||
|
|
然后再决定 `Open`、`Delete`、`Rename`、`Copy`、`Paste`、`Duplicate`、`Navigate Back` 这些动作是否可用,以及真正应该调用哪个 `Commands` 函数。
|
||
|
|
|
||
|
|
## 当前实现
|
||
|
|
|
||
|
|
- `Project` 路由下,编辑动作主要映射到 [`ProjectCommands`](../../Commands/ProjectCommands/ProjectCommands.md)
|
||
|
|
- `Hierarchy` 路由下,编辑动作主要映射到 [`EntityCommands`](../../Commands/EntityCommands/EntityCommands.md)
|
||
|
|
- `HandleEditShortcuts` 统一处理快捷键
|
||
|
|
- `DrawEditActions` 统一绘制菜单项
|
||
|
|
- `Undo` / `Redo` 由当前上下文的 `IUndoManager` 直接提供
|
||
|
|
|
||
|
|
`EditActionTarget` 本身是一个轻量快照结构,不持有复杂状态,也不缓存引用生命周期。
|
||
|
|
|
||
|
|
## 设计说明
|
||
|
|
|
||
|
|
很多编辑器最容易退化的地方,就是每个面板各写一套删除、复制、粘贴逻辑。
|
||
|
|
`EditActionRouter` 的作用正好相反:它把不同面板共享的“编辑语义”集中到一处,只把具体数据对象交给路由判断。
|
||
|
|
|
||
|
|
这和 Unity 菜单栏的思路很接近:同一个 `Delete` 菜单项,在不同焦点上下文里对应不同对象,但用户感知到的是统一操作。
|
||
|
|
|
||
|
|
## 当前限制
|
||
|
|
|
||
|
|
- `Cut` 仍然是禁用占位动作,没有真正实现
|
||
|
|
- `Inspector` 没有独立路由,因此不会接管复制粘贴等全局编辑行为
|
||
|
|
- `Paste` 当前只在 Hierarchy 路由下生效,不支持资源粘贴
|
||
|
|
- 没有多选批处理版本的删除、复制与重命名
|
||
|
|
|
||
|
|
## 相关文档
|
||
|
|
|
||
|
|
- [Actions](../Actions.md)
|
||
|
|
- [ActionRouting](../ActionRouting/ActionRouting.md)
|
||
|
|
- [EditorActions](../EditorActions/EditorActions.md)
|
||
|
|
- [EntityCommands](../../Commands/EntityCommands/EntityCommands.md)
|
||
|
|
- [ProjectCommands](../../Commands/ProjectCommands/ProjectCommands.md)
|