Class EditorContextMenuPlugin
Plugin for adding custom context menus in the editor.
- Inheritance
-
EditorContextMenuPlugin
Remarks
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.
Methods
_popup_menu(PackedStringArray)
Qualifiers: virtual
Called when creating a context menu, custom options can be added by using the EditorContextMenuPlugin.add_context_menu_item or EditorContextMenuPlugin.add_context_menu_item_from_shortcut functions. paths
contains currently selected paths (depending on menu), which can be used to conditionally add options.
void _popup_menu(PackedStringArray paths)
Parameters
paths
PackedStringArray
add_context_menu_item(String, Callable, Texture2D)
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 EditorContextMenuPlugin.add_context_menu_item_from_shortcut instead.
void add_context_menu_item(String name, Callable callback, Texture2D icon)
Parameters
add_context_menu_item_from_shortcut(String, Shortcut, Texture2D)
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 EditorContextMenuPlugin.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_menu_item_from_shortcut(String name, Shortcut shortcut, Texture2D icon)
Parameters
add_context_submenu_item(String, PopupMenu, Texture2D)
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_submenu_item("Set Node Color", popup_menu)
void add_context_submenu_item(String name, PopupMenu menu, Texture2D icon)
Parameters
add_menu_shortcut(Shortcut, Callable)
Registers a shortcut associated with the plugin's context menu. This method should be called once (e.g. in plugin's _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)
void add_menu_shortcut(Shortcut shortcut, Callable callback)