GFEditorActionDefinition¶
API Reference / Kernel / 类索引
- 路径:
addons/gf/kernel/editor/gf_editor_action_definition.gd - 模块:
Kernel - 继承:
RefCounted - API:
public - 类别:编辑器 API (
editor_api) - 首次版本:
3.17.0
编辑器动作声明。 把菜单、按钮、快捷键或面板入口与命令工厂解耦。动作只负责描述入口和创建命令, 具体执行、撤销和业务含义由调用方或命令实现决定。
成员概览¶
| 类型 | 名称 | 签名 |
|---|---|---|
| 属性 | action_id |
var action_id: StringName = &"" |
| 属性 | label |
var label: String = "" |
| 属性 | tooltip |
var tooltip: String = "" |
| 属性 | shortcut_text |
var shortcut_text: String = "" |
| 属性 | command_factory |
var command_factory: Callable = Callable() |
| 属性 | metadata |
var metadata: Dictionary = {} |
| 方法 | create_command |
func create_command(context: Dictionary = {}) -> GFEditorCommandBase: |
| 方法 | invoke |
func invoke(context: Dictionary = {}, undo_manager: Object = null) -> Error: |
| 方法 | is_available |
func is_available(context: Dictionary = {}) -> bool: |
| 方法 | get_debug_snapshot |
func get_debug_snapshot() -> Dictionary: |
属性¶
action_id¶
- API:
public
动作稳定标识。
label¶
- API:
public
动作显示名称。
tooltip¶
- API:
public
动作提示文本。
shortcut_text¶
- API:
public
快捷键说明文本,由具体 UI 决定是否展示。
command_factory¶
- API:
public
命令工厂。推荐签名为 func(context: Dictionary) -> GFEditorCommand。
metadata¶
- API:
public
动作元数据。
结构:
metadata: Dictionary for caller-defined editor action metadata.
方法¶
create_command¶
- API:
public
根据上下文创建命令。
参数:
| 名称 | 说明 |
|---|---|
context |
调用方传入的编辑器上下文。 |
返回:命令对象,工厂无效或返回类型不匹配时为 null。
结构:
context: Dictionary editor context passed to command_factory.
invoke¶
- API:
public
执行动作并可选接入 UndoRedo。
参数:
| 名称 | 说明 |
|---|---|
context |
调用方传入的编辑器上下文。 |
undo_manager |
EditorUndoRedoManager 或兼容对象;为空时直接执行命令。 |
返回:Godot 错误码。
结构:
context: Dictionary editor context passed to create_command().
is_available¶
- API:
public
动作是否具备可调用命令工厂。
参数:
| 名称 | 说明 |
|---|---|
context |
调用方传入的编辑器上下文。 |
返回:可创建且可执行命令时返回 true。
结构:
context: Dictionary editor context passed to create_command().
get_debug_snapshot¶
- API:
public
获取动作快照。
返回:调试信息字典。
结构:
return: Dictionary containing action_id, label, tooltip, shortcut_text, has_command_factory, and metadata.