class_editorcontextmenuplugin.rst 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. :github_url: hide
  2. .. DO NOT EDIT THIS FILE!!!
  3. .. Generated automatically from Godot engine sources.
  4. .. Generator: https://github.com/godotengine/godot/tree/master/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/master/doc/classes/EditorContextMenuPlugin.xml.
  6. .. _class_EditorContextMenuPlugin:
  7. EditorContextMenuPlugin
  8. =======================
  9. **Inherits:** :ref:`RefCounted<class_RefCounted>` **<** :ref:`Object<class_Object>`
  10. Plugin for adding custom context menus in the editor.
  11. .. rst-class:: classref-introduction-group
  12. Description
  13. -----------
  14. **EditorContextMenuPlugin** allows for the addition of custom options in the editor's context menu.
  15. Currently, context menus are supported for three commonly used areas: the file system, scene tree, and editor script list panel.
  16. .. rst-class:: classref-reftable-group
  17. Methods
  18. -------
  19. .. table::
  20. :widths: auto
  21. +--------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  22. | |void| | :ref:`_popup_menu<class_EditorContextMenuPlugin_private_method__popup_menu>`\ (\ paths\: :ref:`PackedStringArray<class_PackedStringArray>`\ ) |virtual| |
  23. +--------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  24. | |void| | :ref:`add_context_menu_item<class_EditorContextMenuPlugin_method_add_context_menu_item>`\ (\ name\: :ref:`String<class_String>`, callback\: :ref:`Callable<class_Callable>`, icon\: :ref:`Texture2D<class_Texture2D>` = null\ ) |
  25. +--------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  26. | |void| | :ref:`add_context_menu_item_from_shortcut<class_EditorContextMenuPlugin_method_add_context_menu_item_from_shortcut>`\ (\ name\: :ref:`String<class_String>`, shortcut\: :ref:`Shortcut<class_Shortcut>`, icon\: :ref:`Texture2D<class_Texture2D>` = null\ ) |
  27. +--------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  28. | |void| | :ref:`add_context_submenu_item<class_EditorContextMenuPlugin_method_add_context_submenu_item>`\ (\ name\: :ref:`String<class_String>`, menu\: :ref:`PopupMenu<class_PopupMenu>`, icon\: :ref:`Texture2D<class_Texture2D>` = null\ ) |
  29. +--------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  30. | |void| | :ref:`add_menu_shortcut<class_EditorContextMenuPlugin_method_add_menu_shortcut>`\ (\ shortcut\: :ref:`Shortcut<class_Shortcut>`, callback\: :ref:`Callable<class_Callable>`\ ) |
  31. +--------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  32. .. rst-class:: classref-section-separator
  33. ----
  34. .. rst-class:: classref-descriptions-group
  35. Enumerations
  36. ------------
  37. .. _enum_EditorContextMenuPlugin_ContextMenuSlot:
  38. .. rst-class:: classref-enumeration
  39. enum **ContextMenuSlot**: :ref:`🔗<enum_EditorContextMenuPlugin_ContextMenuSlot>`
  40. .. _class_EditorContextMenuPlugin_constant_CONTEXT_SLOT_SCENE_TREE:
  41. .. rst-class:: classref-enumeration-constant
  42. :ref:`ContextMenuSlot<enum_EditorContextMenuPlugin_ContextMenuSlot>` **CONTEXT_SLOT_SCENE_TREE** = ``0``
  43. Context menu of Scene dock. :ref:`_popup_menu()<class_EditorContextMenuPlugin_private_method__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.
  44. .. _class_EditorContextMenuPlugin_constant_CONTEXT_SLOT_FILESYSTEM:
  45. .. rst-class:: classref-enumeration-constant
  46. :ref:`ContextMenuSlot<enum_EditorContextMenuPlugin_ContextMenuSlot>` **CONTEXT_SLOT_FILESYSTEM** = ``1``
  47. Context menu of FileSystem dock. :ref:`_popup_menu()<class_EditorContextMenuPlugin_private_method__popup_menu>` and option callback will be called with list of paths of the currently selected files.
  48. .. _class_EditorContextMenuPlugin_constant_CONTEXT_SLOT_SCRIPT_EDITOR:
  49. .. rst-class:: classref-enumeration-constant
  50. :ref:`ContextMenuSlot<enum_EditorContextMenuPlugin_ContextMenuSlot>` **CONTEXT_SLOT_SCRIPT_EDITOR** = ``2``
  51. Context menu of Script editor's script tabs. :ref:`_popup_menu()<class_EditorContextMenuPlugin_private_method__popup_menu>` will be called with the path to the currently edited script, while option callback will receive reference to that script.
  52. .. _class_EditorContextMenuPlugin_constant_CONTEXT_SLOT_FILESYSTEM_CREATE:
  53. .. rst-class:: classref-enumeration-constant
  54. :ref:`ContextMenuSlot<enum_EditorContextMenuPlugin_ContextMenuSlot>` **CONTEXT_SLOT_FILESYSTEM_CREATE** = ``3``
  55. The "Create..." submenu of FileSystem dock's context menu. :ref:`_popup_menu()<class_EditorContextMenuPlugin_private_method__popup_menu>` and option callback will be called with list of paths of the currently selected files.
  56. .. _class_EditorContextMenuPlugin_constant_CONTEXT_SLOT_SCRIPT_EDITOR_CODE:
  57. .. rst-class:: classref-enumeration-constant
  58. :ref:`ContextMenuSlot<enum_EditorContextMenuPlugin_ContextMenuSlot>` **CONTEXT_SLOT_SCRIPT_EDITOR_CODE** = ``4``
  59. Context menu of Script editor's code editor. :ref:`_popup_menu()<class_EditorContextMenuPlugin_private_method__popup_menu>` will be called with the path to the :ref:`CodeEdit<class_CodeEdit>` node. You can fetch it using this code:
  60. ::
  61. func _popup_menu(paths):
  62. var code_edit = Engine.get_main_loop().root.get_node(paths[0]);
  63. The option callback will receive reference to that node. You can use :ref:`CodeEdit<class_CodeEdit>` methods to perform symbol lookups etc.
  64. .. _class_EditorContextMenuPlugin_constant_CONTEXT_SLOT_SCENE_TABS:
  65. .. rst-class:: classref-enumeration-constant
  66. :ref:`ContextMenuSlot<enum_EditorContextMenuPlugin_ContextMenuSlot>` **CONTEXT_SLOT_SCENE_TABS** = ``5``
  67. Context menu of scene tabs. :ref:`_popup_menu()<class_EditorContextMenuPlugin_private_method__popup_menu>` will be called with the path of the clicked scene, or empty :ref:`PackedStringArray<class_PackedStringArray>` if the menu was opened on empty space. The option callback will receive the path of the clicked scene, or empty :ref:`String<class_String>` if none was clicked.
  68. .. _class_EditorContextMenuPlugin_constant_CONTEXT_SLOT_2D_EDITOR:
  69. .. rst-class:: classref-enumeration-constant
  70. :ref:`ContextMenuSlot<enum_EditorContextMenuPlugin_ContextMenuSlot>` **CONTEXT_SLOT_2D_EDITOR** = ``6``
  71. Context menu of 2D editor's basic right-click menu. :ref:`_popup_menu()<class_EditorContextMenuPlugin_private_method__popup_menu>` will be called with paths to all :ref:`CanvasItem<class_CanvasItem>` nodes under the cursor. You can fetch them using this code:
  72. ::
  73. func _popup_menu(paths):
  74. var canvas_item = Engine.get_main_loop().root.get_node(paths[0]); # Replace 0 with the desired index.
  75. The paths array is empty if there weren't any nodes under cursor. The option callback will receive a typed array of :ref:`CanvasItem<class_CanvasItem>` nodes.
  76. .. rst-class:: classref-section-separator
  77. ----
  78. .. rst-class:: classref-descriptions-group
  79. Method Descriptions
  80. -------------------
  81. .. _class_EditorContextMenuPlugin_private_method__popup_menu:
  82. .. rst-class:: classref-method
  83. |void| **_popup_menu**\ (\ paths\: :ref:`PackedStringArray<class_PackedStringArray>`\ ) |virtual| :ref:`🔗<class_EditorContextMenuPlugin_private_method__popup_menu>`
  84. Called when creating a context menu, custom options can be added by using the :ref:`add_context_menu_item()<class_EditorContextMenuPlugin_method_add_context_menu_item>` or :ref:`add_context_menu_item_from_shortcut()<class_EditorContextMenuPlugin_method_add_context_menu_item_from_shortcut>` functions. ``paths`` contains currently selected paths (depending on menu), which can be used to conditionally add options.
  85. .. rst-class:: classref-item-separator
  86. ----
  87. .. _class_EditorContextMenuPlugin_method_add_context_menu_item:
  88. .. rst-class:: classref-method
  89. |void| **add_context_menu_item**\ (\ name\: :ref:`String<class_String>`, callback\: :ref:`Callable<class_Callable>`, icon\: :ref:`Texture2D<class_Texture2D>` = null\ ) :ref:`🔗<class_EditorContextMenuPlugin_method_add_context_menu_item>`
  90. 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<class_Array>` argument; array contents depend on context menu slot.
  91. ::
  92. func _popup_menu(paths):
  93. add_context_menu_item("File Custom options", handle, ICON)
  94. If you want to assign shortcut to the menu item, use :ref:`add_context_menu_item_from_shortcut()<class_EditorContextMenuPlugin_method_add_context_menu_item_from_shortcut>` instead.
  95. .. rst-class:: classref-item-separator
  96. ----
  97. .. _class_EditorContextMenuPlugin_method_add_context_menu_item_from_shortcut:
  98. .. rst-class:: classref-method
  99. |void| **add_context_menu_item_from_shortcut**\ (\ name\: :ref:`String<class_String>`, shortcut\: :ref:`Shortcut<class_Shortcut>`, icon\: :ref:`Texture2D<class_Texture2D>` = null\ ) :ref:`🔗<class_EditorContextMenuPlugin_method_add_context_menu_item_from_shortcut>`
  100. 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()<class_EditorContextMenuPlugin_method_add_menu_shortcut>`.
  101. ::
  102. func _init():
  103. add_menu_shortcut(SHORTCUT, handle)
  104. func _popup_menu(paths):
  105. add_context_menu_item_from_shortcut("File Custom options", SHORTCUT, ICON)
  106. .. rst-class:: classref-item-separator
  107. ----
  108. .. _class_EditorContextMenuPlugin_method_add_context_submenu_item:
  109. .. rst-class:: classref-method
  110. |void| **add_context_submenu_item**\ (\ name\: :ref:`String<class_String>`, menu\: :ref:`PopupMenu<class_PopupMenu>`, icon\: :ref:`Texture2D<class_Texture2D>` = null\ ) :ref:`🔗<class_EditorContextMenuPlugin_method_add_context_submenu_item>`
  111. 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 :ref:`PopupMenu<class_PopupMenu>` every time.
  112. ::
  113. func _popup_menu(paths):
  114. var popup_menu = PopupMenu.new()
  115. popup_menu.add_item("Blue")
  116. popup_menu.add_item("White")
  117. popup_menu.id_pressed.connect(_on_color_submenu_option)
  118. add_context_submenu_item("Set Node Color", popup_menu)
  119. .. rst-class:: classref-item-separator
  120. ----
  121. .. _class_EditorContextMenuPlugin_method_add_menu_shortcut:
  122. .. rst-class:: classref-method
  123. |void| **add_menu_shortcut**\ (\ shortcut\: :ref:`Shortcut<class_Shortcut>`, callback\: :ref:`Callable<class_Callable>`\ ) :ref:`🔗<class_EditorContextMenuPlugin_method_add_menu_shortcut>`
  124. Registers a shortcut associated with the plugin's context menu. This method should be called once (e.g. in plugin's :ref:`Object._init()<class_Object_private_method__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<class_Array>` argument; array contents depend on context menu slot.
  125. ::
  126. func _init():
  127. add_menu_shortcut(SHORTCUT, handle)
  128. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  129. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  130. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  131. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  132. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  133. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
  134. .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`
  135. .. |void| replace:: :abbr:`void (No return value.)`