0.2.0-dev Download ZIP
135 lines ·7.7 KB Raw
| 1 | <?xml version="1.0" encoding="UTF-8" ?> |
| 2 | <class name="EditorContextMenuPlugin" inherits="RefCounted" api_type="editor" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd"> |
| 3 | <brief_description> |
| 4 | Plugin for adding custom context menus in the editor. |
| 5 | </brief_description> |
| 6 | <description> |
| 7 | [EditorContextMenuPlugin] allows for the addition of custom options in the editor's context menu. Register them with [method EditorPlugin.add_context_menu_plugin]. |
| 8 | See [enum ContextMenuSlot] for the list of available areas where context menu plugins are supported. |
| 9 | </description> |
| 10 | <tutorials> |
| 11 | </tutorials> |
| 12 | <methods> |
| 13 | <method name="_get_menu_options" qualifiers="virtual"> |
| 14 | <return type="void" /> |
| 15 | <param index="0" name="data" type="Dictionary[StringName, Variant]" /> |
| 16 | <description> |
| 17 | Called when creating a context menu, custom options can be added by using the [method add_context_menu_item] or [method add_context_menu_item_from_shortcut] functions. [param data] contains the context data, which differs depending on the context menu slot. See the descriptions of [enum ContextMenuSlot] for more information. |
| 18 | </description> |
| 19 | </method> |
| 20 | <method name="_popup_menu" qualifiers="virtual" deprecated="Use [method _get_menu_options] instead."> |
| 21 | <return type="void" /> |
| 22 | <param index="0" name="paths" type="PackedStringArray" /> |
| 23 | <description> |
| 24 | [b]Note:[/b] Implementing this method makes the shortcut callbacks receive legacy data (for compatibility reasons). |
| 25 | </description> |
| 26 | </method> |
| 27 | <method name="add_context_menu_item"> |
| 28 | <return type="void" /> |
| 29 | <param index="0" name="name" type="String" /> |
| 30 | <param index="1" name="callback" type="Callable" /> |
| 31 | <param index="2" name="icon" type="Texture2D" default="null" /> |
| 32 | <description> |
| 33 | Add custom option to the context menu of the plugin's specified slot. [param callback] should be a method that takes a single argument of type [Dictionary]. It will be called when the option is activated and the data received in the callback is the same as in [method _get_menu_options]. |
| 34 | [codeblock] |
| 35 | func _get_menu_options(data): |
| 36 | add_context_menu_item("File Custom options", handle, ICON) |
| 37 | [/codeblock] |
| 38 | If you want to assign shortcut to the menu item, use [method add_context_menu_item_from_shortcut] instead. |
| 39 | </description> |
| 40 | </method> |
| 41 | <method name="add_context_menu_item_from_shortcut"> |
| 42 | <return type="void" /> |
| 43 | <param index="0" name="name" type="String" /> |
| 44 | <param index="1" name="shortcut" type="Shortcut" /> |
| 45 | <param index="2" name="icon" type="Texture2D" default="null" /> |
| 46 | <description> |
| 47 | Add custom option to the context menu of the plugin's specified slot. The option will have the [param shortcut] assigned and reuse its callback. The shortcut has to be registered beforehand with [method add_menu_shortcut]. |
| 48 | [codeblock] |
| 49 | func _init(): |
| 50 | add_menu_shortcut(SHORTCUT, handle) |
| 51 | |
| 52 | func _get_menu_options(paths): |
| 53 | add_context_menu_item_from_shortcut("File Custom options", SHORTCUT, ICON) |
| 54 | [/codeblock] |
| 55 | </description> |
| 56 | </method> |
| 57 | <method name="add_context_submenu_item"> |
| 58 | <return type="void" /> |
| 59 | <param index="0" name="name" type="String" /> |
| 60 | <param index="1" name="menu" type="PopupMenu" /> |
| 61 | <param index="2" name="icon" type="Texture2D" default="null" /> |
| 62 | <description> |
| 63 | 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. |
| 64 | [codeblock] |
| 65 | func _get_menu_options(data): |
| 66 | var popup_menu = PopupMenu.new() |
| 67 | popup_menu.add_item("Blue") |
| 68 | popup_menu.add_item("White") |
| 69 | popup_menu.id_pressed.connect(_on_color_submenu_option) |
| 70 | |
| 71 | add_context_submenu_item("Set Node Color", popup_menu) |
| 72 | [/codeblock] |
| 73 | </description> |
| 74 | </method> |
| 75 | <method name="add_menu_shortcut"> |
| 76 | <return type="void" /> |
| 77 | <param index="0" name="shortcut" type="Shortcut" /> |
| 78 | <param index="1" name="callback" type="Callable" /> |
| 79 | <description> |
| 80 | Registers a shortcut associated with the plugin's context menu. This method should be called once (e.g. in the plugin's [method Object._init]). [param callback] will be called when user presses the specified [param shortcut] while the menu's context is in effect (e.g. FileSystem dock is focused). Callback should take single data [Dictionary], same as in [method add_context_menu_item]. |
| 81 | [codeblock] |
| 82 | func _init(): |
| 83 | add_menu_shortcut(SHORTCUT, handle) |
| 84 | [/codeblock] |
| 85 | </description> |
| 86 | </method> |
| 87 | </methods> |
| 88 | <constants> |
| 89 | <constant name="CONTEXT_SLOT_SCENE_TREE" value="0" enum="ContextMenuSlot"> |
| 90 | Context menu of Scene dock. The data [Dictionary] contains: |
| 91 | [code]&"selected_nodes": Array[Node][/code] - The list of currently selected nodes (same as [method EditorSelection.get_top_selected_nodes]). |
| 92 | </constant> |
| 93 | <constant name="CONTEXT_SLOT_FILESYSTEM" value="1" enum="ContextMenuSlot"> |
| 94 | Context menu of FileSystem dock. The data [Dictionary] contains: |
| 95 | [code]&"selected_files": PackedStringArray[/code] - The list of selected files. |
| 96 | </constant> |
| 97 | <constant name="CONTEXT_SLOT_SCRIPT_EDITOR" value="2" enum="ContextMenuSlot"> |
| 98 | Context menu of Script editor's script tabs and Shader editor's shader tabs. The data [Dictionary] contains: |
| 99 | [code]&"selected_resource": Resource[/code] - The currently selected resource. Can be a [Script], a [Shader], a text file, or [code]null[/code] in case of help pages. |
| 100 | [code]&"path": String[/code] - The path of the selected file. If a help page is selected, the path will be the name of the opened class, prefixed with [code]help:[/code]. |
| 101 | </constant> |
| 102 | <constant name="CONTEXT_SLOT_FILESYSTEM_CREATE" value="3" enum="ContextMenuSlot"> |
| 103 | The "Create..." submenu of FileSystem dock's context menu, or the "New" section of the main context menu when empty space is clicked. The data [Dictionary] contains: |
| 104 | [code]&"base_directory": String[/code] - Path to the base directory where a file should be created. |
| 105 | [code]&"needs_prefix": bool[/code] - Whether the option needs a "New" prefix (for consistency with native options). |
| 106 | [codeblock] |
| 107 | func _get_menu_options(data): |
| 108 | if data["needs_prefix"]: |
| 109 | add_context_menu_item("New Image File...", create_image) |
| 110 | else: |
| 111 | add_context_menu_item("Image File...", create_image) |
| 112 | [/codeblock] |
| 113 | </constant> |
| 114 | <constant name="CONTEXT_SLOT_SCRIPT_EDITOR_CODE" value="4" enum="ContextMenuSlot"> |
| 115 | Context menu of Script editor's code editor. The data [Dictionary] contains: |
| 116 | [code]&"code_edit": CodeEdit[/code] - The code editor instance. |
| 117 | [code]&"file_path": String[/code] - Path to the currently edited file. |
| 118 | </constant> |
| 119 | <constant name="CONTEXT_SLOT_SCENE_TABS" value="5" enum="ContextMenuSlot"> |
| 120 | Context menu of scene tabs. The data [Dictionary] contains: |
| 121 | [code]&"selected_scene": String[/code] - Scene path of the selected/clicked scene tab. Empty if empty space was clicked. |
| 122 | </constant> |
| 123 | <constant name="CONTEXT_SLOT_2D_EDITOR" value="6" enum="ContextMenuSlot"> |
| 124 | Context menu of the 2D editor's viewport. The data [Dictionary] contains: |
| 125 | [code]&"hovered_nodes": Array[CanvasItem][/code] - The [CanvasItem] nodes under the cursor. |
| 126 | [code]&"mouse_position": Vector2[/code] - The local mouse position in the 2D scene. |
| 127 | </constant> |
| 128 | <constant name="CONTEXT_SLOT_INSPECTOR_PROPERTY" value="7" enum="ContextMenuSlot"> |
| 129 | Context menu of an editor property in the inspector. The data [Dictionary] contains: |
| 130 | [code]&"property": EditorProperty[/code] - The clicked [EditorProperty] object. |
| 131 | [code]&"object": Object[/code] - The object edited by the inspector. |
| 132 | [code]&"property_name": StringName[/code] - The name of the object's property that was clicked. |
| 133 | </constant> |
| 134 | </constants> |
| 135 | </class> |