Inheritance #

RefCounted

- AESContext
- AStar2D
- AStar3D
- AStarGrid2D
- AudioEffectInstance (1)
- AudioSample
- AudioSamplePlayback
- AudioStreamPlayback (5)
- CameraFeed
- CharFXTransform
- ConfigFile
- Crypto
- DTLSServer
- DirAccess
- ENetConnection
- EditorContextMenuPlugin
- EditorDebuggerPlugin
- EditorDebuggerSession
- EditorExportPlatform (6)
- EditorExportPlugin
- EditorExportPreset
- EditorFeatureProfile
- EditorFileSystemImportFormatSupportQuery
- EditorInspectorPlugin
- EditorResourceConversionPlugin
- EditorResourcePreviewGenerator
- EditorResourceTooltipPlugin
- EditorSceneFormatImporter (4)
- EditorScenePostImport
- EditorScenePostImportPlugin
- EditorScript
- EditorTranslationParserPlugin
- EncodedObjectAsID
- EngineProfiler
- Expression
- FileAccess
- GLTFObjectModelProperty
- HMACContext
- HTTPClient
- HashingContext
- ImageFormatLoader (1)
- JavaClass
- JavaObject
- JavaScriptObject
- KinematicCollision2D
- KinematicCollision3D
- Lightmapper (1)
- MeshConvexDecompositionSettings
- MeshDataTool
- MultiplayerAPI (2)
- Mutex
- NavigationPathQueryParameters2D
- NavigationPathQueryParameters3D
- NavigationPathQueryResult2D
- NavigationPathQueryResult3D
- Node3DGizmo (1)
- OggPacketSequencePlayback
- OpenXRAPIExtension
- PCKPacker
- PackedDataContainerRef
- PacketPeer (8)
- PhysicsPointQueryParameters2D
- PhysicsPointQueryParameters3D
- PhysicsRayQueryParameters2D
- PhysicsRayQueryParameters3D
- PhysicsShapeQueryParameters2D
- PhysicsShapeQueryParameters3D
- PhysicsTestMotionParameters2D
- PhysicsTestMotionParameters3D
- PhysicsTestMotionResult2D
- PhysicsTestMotionResult3D
- RDAttachmentFormat
- RDFramebufferPass
- RDPipelineColorBlendState
- RDPipelineColorBlendStateAttachment
- RDPipelineDepthStencilState
- RDPipelineMultisampleState
- RDPipelineRasterizationState
- RDPipelineSpecializationConstant
- RDSamplerState
- RDShaderSource
- RDTextureFormat
- RDTextureView
- RDUniform
- RDVertexAttribute
- RandomNumberGenerator
- RegEx
- RegExMatch
- RenderSceneBuffers (2)
- RenderSceneBuffersConfiguration
- Resource (103)
- ResourceFormatLoader
- ResourceFormatSaver
- ResourceImporter (16)
- SceneState
- SceneTreeTimer
- Semaphore
- SkinReference
- StreamPeer (5)
- SurfaceTool
- TCPServer
- TLSOptions
- TextLine
- TextParagraph
- TextServer (1)
- Thread
- TranslationDomain
- TriangleMesh
- Tween
- Tweener (5)
- UDPServer
- UPNP
- UPNPDevice
- WeakRef
- WebRTCPeerConnection (1)
- XMLParser
- XRInterface (4)
- XRPose
- XRTracker (2)
- ZIPPacker
- ZIPReader
EditorContextMenuPlugin

Table of contents

EditorContextMenuPlugin #

is_refcounted, is_instantiable, editor, not_builtin_classes

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.

Members #

Methods #

virtual func _popup_menu(paths: PackedStringArray) -> void#

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.

func add_context_menu_item(icon: Texture2D = null) -> void#

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.

func add_context_menu_item_from_shortcut(icon: Texture2D = null) -> void#

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)

func add_context_submenu_item(icon: Texture2D = null) -> void#

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)

func add_menu_shortcut(callback: Callable) -> void#

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)

Annotations #

Constants #

const CONTEXT_SLOT_SCENE_TREE = 0 enum ContextMenuSlot#

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.

const CONTEXT_SLOT_FILESYSTEM = 1 enum ContextMenuSlot#

Context menu of FileSystem dock. _popup_menu and option callback will be called with list of paths of the currently selected files.

const CONTEXT_SLOT_SCRIPT_EDITOR = 2 enum ContextMenuSlot#

Context menu of Script editor's script tabs. _popup_menu will be called with the path to the currently edited script, while option callback will receive reference to that script.

const CONTEXT_SLOT_FILESYSTEM_CREATE = 3 enum ContextMenuSlot#

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.

const CONTEXT_SLOT_SCRIPT_EDITOR_CODE = 4 enum ContextMenuSlot#

Context menu of Script editor's code editor. _popup_menu will be called with the path to the CodeEdit node. You can fetch it using this code:

func _popup_menu(paths):
    var code_edit = Engine.get_main_loop().root.get_node(paths[0]);

The option callback will receive reference to that node. You can use CodeEdit methods to perform symbol lookups etc.

const CONTEXT_SLOT_SCENE_TABS = 5 enum ContextMenuSlot#

Context menu of scene tabs. _popup_menu will be called with the path of the clicked scene, or empty PackedStringArray if the menu was opened on empty space. The option callback will receive the path of the clicked scene, or empty String if none was clicked.

const CONTEXT_SLOT_2D_EDITOR = 6 enum ContextMenuSlot#

Context menu of 2D editor's basic right-click menu. _popup_menu will be called with paths to all CanvasItem nodes under the cursor. You can fetch them using this code:

func _popup_menu(paths):
    var canvas_item = Engine.get_main_loop().root.get_node(paths[0]); # Replace 0 with the desired index.

The paths array is empty if there weren't any nodes under cursor. The option callback will receive a typed array of CanvasItem nodes.

Constructors #

Enums #

ContextMenuSlot#

enum ContextMenuSlot { CONTEXT_SLOT_SCENE_TREE = 0, CONTEXT_SLOT_FILESYSTEM = 1, CONTEXT_SLOT_SCRIPT_EDITOR = 2, CONTEXT_SLOT_FILESYSTEM_CREATE = 3, CONTEXT_SLOT_SCRIPT_EDITOR_CODE = 4, CONTEXT_SLOT_SCENE_TABS = 5, CONTEXT_SLOT_2D_EDITOR = 6, }

Operators #

Signals #

Theme Items #

Tutorials #