:github_url: hide .. DO NOT EDIT THIS FILE!!! .. Generated automatically from Godot engine sources. .. Generator: https://github.com/godotengine/godot/tree/master/doc/tools/make_rst.py. .. XML source: https://github.com/godotengine/godot/tree/master/doc/classes/EditorContextMenuPlugin.xml. .. _class_EditorContextMenuPlugin: EditorContextMenuPlugin ======================= **Inherits:** :ref:`RefCounted` **<** :ref:`Object` Plugin for adding custom context menus in the editor. .. rst-class:: classref-introduction-group Description ----------- **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. .. rst-class:: classref-reftable-group Methods ------- .. table:: :widths: auto +--------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | |void| | :ref:`_popup_menu`\ (\ paths\: :ref:`PackedStringArray`\ ) |virtual| | +--------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | |void| | :ref:`add_context_menu_item`\ (\ name\: :ref:`String`, callback\: :ref:`Callable`, icon\: :ref:`Texture2D` = null\ ) | +--------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | |void| | :ref:`add_context_menu_item_from_shortcut`\ (\ name\: :ref:`String`, shortcut\: :ref:`Shortcut`, icon\: :ref:`Texture2D` = null\ ) | +--------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | |void| | :ref:`add_menu_shortcut`\ (\ shortcut\: :ref:`Shortcut`, callback\: :ref:`Callable`\ ) | +--------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ .. rst-class:: classref-section-separator ---- .. rst-class:: classref-descriptions-group Enumerations ------------ .. _enum_EditorContextMenuPlugin_ContextMenuSlot: .. rst-class:: classref-enumeration enum **ContextMenuSlot**: :ref:`🔗` .. _class_EditorContextMenuPlugin_constant_CONTEXT_SLOT_SCENE_TREE: .. rst-class:: classref-enumeration-constant :ref:`ContextMenuSlot` **CONTEXT_SLOT_SCENE_TREE** = ``0`` Context menu of Scene dock. :ref:`_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. .. _class_EditorContextMenuPlugin_constant_CONTEXT_SLOT_FILESYSTEM: .. rst-class:: classref-enumeration-constant :ref:`ContextMenuSlot` **CONTEXT_SLOT_FILESYSTEM** = ``1`` Context menu of FileSystem dock. :ref:`_popup_menu` and option callback will be called with list of paths of the currently selected files. .. _class_EditorContextMenuPlugin_constant_CONTEXT_SLOT_FILESYSTEM_CREATE: .. rst-class:: classref-enumeration-constant :ref:`ContextMenuSlot` **CONTEXT_SLOT_FILESYSTEM_CREATE** = ``3`` The "Create..." submenu of FileSystem dock's context menu. :ref:`_popup_menu` and option callback will be called with list of paths of the currently selected files. .. _class_EditorContextMenuPlugin_constant_CONTEXT_SLOT_SCRIPT_EDITOR: .. rst-class:: classref-enumeration-constant :ref:`ContextMenuSlot` **CONTEXT_SLOT_SCRIPT_EDITOR** = ``2`` Context menu of Scene dock. :ref:`_popup_menu` will be called with the path to the currently edited script, while option callback will receive reference to that script. .. rst-class:: classref-section-separator ---- .. rst-class:: classref-descriptions-group Method Descriptions ------------------- .. _class_EditorContextMenuPlugin_private_method__popup_menu: .. rst-class:: classref-method |void| **_popup_menu**\ (\ paths\: :ref:`PackedStringArray`\ ) |virtual| :ref:`🔗` Called when creating a context menu, custom options can be added by using the :ref:`add_context_menu_item` or :ref:`add_context_menu_item_from_shortcut` functions. ``paths`` contains currently selected paths (depending on menu), which can be used to conditionally add options. .. rst-class:: classref-item-separator ---- .. _class_EditorContextMenuPlugin_method_add_context_menu_item: .. rst-class:: classref-method |void| **add_context_menu_item**\ (\ name\: :ref:`String`, callback\: :ref:`Callable`, icon\: :ref:`Texture2D` = null\ ) :ref:`🔗` 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 :ref:`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 :ref:`add_context_menu_item_from_shortcut` instead. .. rst-class:: classref-item-separator ---- .. _class_EditorContextMenuPlugin_method_add_context_menu_item_from_shortcut: .. rst-class:: classref-method |void| **add_context_menu_item_from_shortcut**\ (\ name\: :ref:`String`, shortcut\: :ref:`Shortcut`, icon\: :ref:`Texture2D` = null\ ) :ref:`🔗` 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 :ref:`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) .. rst-class:: classref-item-separator ---- .. _class_EditorContextMenuPlugin_method_add_menu_shortcut: .. rst-class:: classref-method |void| **add_menu_shortcut**\ (\ shortcut\: :ref:`Shortcut`, callback\: :ref:`Callable`\ ) :ref:`🔗` Registers a shortcut associated with the plugin's context menu. This method should be called once (e.g. in plugin's :ref:`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 :ref:`Array` argument; array contents depend on context menu slot. :: func _init(): add_menu_shortcut(SHORTCUT, handle) .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)` .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)` .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)` .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)` .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)` .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)` .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)` .. |void| replace:: :abbr:`void (No return value.)`