EditorContextMenuPlugin
继承: RefCounted
< Object
Plugin for adding custom context menus in the editor.
描述
EditorContextMenuPlugin allows for the addition of custom options in the editor's context menu.
Currently, context menus are supported for three commonly used areas: the file system, scene tree, and editor script list panel.
方法
void | _popup_menu ( paths: PackedStringArray ) virtual1 |
void | add_context_menu_item ( name: String , callback: Callable , icon: Texture2D = null ) |
void | add_context_menu_item_from_shortcut ( name: String , shortcut: Shortcut , icon: Texture2D = null ) |
void | add_context_submenu_item ( name: String , menu: PopupMenu , icon: Texture2D = null ) |
void | add_menu_shortcut ( shortcut: Shortcut , callback: Callable ) |
枚举
enum ContextMenuSlot:
ContextMenuSlot CONTEXT_SLOT_SCENE_TREE = 0
Context menu of Scene dock. _popup_menu
will be called with a list of paths to currently selected nodes, while option callback will receive the list of currently selected nodes.
ContextMenuSlot CONTEXT_SLOT_FILESYSTEM = 1
Context menu of FileSystem dock. _popup_menu
and option callback will be called with list of paths of the currently selected files.
ContextMenuSlot CONTEXT_SLOT_FILESYSTEM_CREATE = 3
The "Create..." submenu of FileSystem dock's context menu. _popup_menu
and option callback will be called with list of paths of the currently selected files.
ContextMenuSlot CONTEXT_SLOT_SCRIPT_EDITOR = 2
Context menu of Scene dock. _popup_menu
will be called with the path to the currently edited script, while option callback will receive reference to that script.
方法说明
void
_popup_menu ( paths: PackedStringArray
) virtual1
Called when creating a context menu, custom options can be added by using the add_context_menu_item
or add_context_menu_item_from_shortcut
functions. paths
contains currently selected paths (depending on menu), which can be used to conditionally add options.
void
add_context_menu_item ( name: String
, callback: Callable
, icon: Texture2D
= null )
Add custom option to the context menu of the plugin's specified slot. When the option is activated, callback
will be called. Callback should take single Array
argument; array contents depend on context menu slot.
func _popup_menu(paths):
add_context_menu_item("File Custom options", handle, ICON)
If you want to assign shortcut to the menu item, use add_context_menu_item_from_shortcut
instead.
void
add_context_menu_item_from_shortcut ( name: String
, shortcut: Shortcut
, icon: Texture2D
= null )
Add custom option to the context menu of the plugin's specified slot. The option will have the shortcut
assigned and reuse its callback. The shortcut has to be registered beforehand with add_menu_shortcut
.
func _init():
add_menu_shortcut(SHORTCUT, handle)
func _popup_menu(paths):
add_context_menu_item_from_shortcut("File Custom options", SHORTCUT, ICON)
void
add_context_submenu_item ( name: String
, menu: PopupMenu
, icon: Texture2D
= null )
Add a submenu to the context menu of the plugin's specified slot. The submenu is not automatically handled, you need to connect to its signals yourself. Also the submenu is freed on every popup, so provide a new PopupMenu
every time.
func _popup_menu(paths):
var popup_menu = PopupMenu.new()
popup_menu.add_item("Blue")
popup_menu.add_item("White")
popup_menu.id_pressed.connect(_on_color_submenu_option)
add_context_menu_item("Set Node Color", popup_menu)
void
add_menu_shortcut ( shortcut: Shortcut
, callback: Callable
)
Registers a shortcut associated with the plugin's context menu. This method should be called once (e.g. in plugin's Object._init
). callback
will be called when user presses the specified shortcut
while the menu's context is in effect (e.g. FileSystem dock is focused). Callback should take single Array
argument; array contents depend on context menu slot.
func _init():
add_menu_shortcut(SHORTCUT, handle)
本方法通常需要用户覆盖才能生效。
本方法无副作用,不会修改该实例的任何成员变量。
本方法除了能接受在此处描述的参数外,还能够继续接受任意数量的参数。
本方法用于构造某个类型。
调用本方法无需实例,可直接使用类名进行调用。
本方法描述的是使用本类型作为左操作数的有效运算符。
这个值是由下列位标志构成位掩码的整数。
无返回值。