Up to date

This page is up to date for Godot 4.2. If you still find outdated information, please open an issue.

EditorCommandPalette

继承: ConfirmationDialog < AcceptDialog < Window < Viewport < Node < Object

Godot 编辑器的命令面板。

描述

该对象包含所有可用命令及其快捷方式文本。这些命令可以通过 Editor > 命令面板 菜单访问。

命令键名使用斜杠分隔符来区分部分,例如:"example/command1",那么 example 将是部分名称。

var command_palette = EditorInterface.get_command_palette()
# external_command 是将在命令执行时调用的函数。
var command_callable = Callable(self, "external_command").bind(arguments)
command_palette.add_command("command", "test/command",command_callable)

注意:不应直接实例化此类。相反,使用 EditorInterface.get_command_palette 访问单例。

属性

bool

dialog_hide_on_ok

false (overrides AcceptDialog)

方法

void

add_command ( String command_name, String key_name, Callable binded_callable, String shortcut_text="None" )

void

remove_command ( String key_name )


方法说明

void add_command ( String command_name, String key_name, Callable binded_callable, String shortcut_text="None" )

向 EditorCommandPalette 添加自定义命令。

  • command_nameStringCommand 的名称。这会显示给用户。)

  • key_nameString(特定 Command 的密钥名称。这用于唯一标识 Command。)

  • binded_callableCallableCommand 的 Callable。这将在选择 Command 时执行。)

  • shortcut_textStringCommand 的快捷键文本,如果可用。)


void remove_command ( String key_name )

从 EditorCommandPalette 中删除自定义命令。

  • key_name: String (特定 Command 的键名)