EditorContextMenuPlugin

package
v0.0.0-...-c858641 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 14, 2025 License: MIT Imports: 25 Imported by: 0

Documentation

Overview

graphics.gd/classdb/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.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Advanced

type Advanced = class

Advanced exposes a 1:1 low-level instance of the class, undocumented, for those who know what they are doing.

type Any

type Any interface {
	gd.IsClass
	AsEditorContextMenuPlugin() Instance
}

type ContextMenuSlot

type ContextMenuSlot int //gd:EditorContextMenuPlugin.ContextMenuSlot
const (
	// Context menu of Scene dock. [Instance.PopupMenu] will be called with a list of paths to currently selected nodes, while option callback will receive the list of currently selected nodes.
	ContextSlotSceneTree ContextMenuSlot = 0
	// Context menu of FileSystem dock. [Instance.PopupMenu] and option callback will be called with list of paths of the currently selected files.
	ContextSlotFilesystem ContextMenuSlot = 1
	// Context menu of Script editor's script tabs. [Instance.PopupMenu] will be called with the path to the currently edited script, while option callback will receive reference to that script.
	ContextSlotScriptEditor ContextMenuSlot = 2
	// The "Create..." submenu of FileSystem dock's context menu. [Instance.PopupMenu] and option callback will be called with list of paths of the currently selected files.
	ContextSlotFilesystemCreate ContextMenuSlot = 3
	// Context menu of Script editor's code editor. [Instance.PopupMenu] will be called with the path to the [graphics.gd/classdb/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 [graphics.gd/classdb/CodeEdit] methods to perform symbol lookups etc.
	ContextSlotScriptEditorCode ContextMenuSlot = 4
	// Context menu of scene tabs. [Instance.PopupMenu] will be called with the path of the clicked scene, or empty []string 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.
	ContextSlotSceneTabs ContextMenuSlot = 5
	// Context menu of 2D editor's basic right-click menu. [Instance.PopupMenu] will be called with paths to all [graphics.gd/classdb/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 [graphics.gd/classdb/CanvasItem] nodes.
	ContextSlot2dEditor ContextMenuSlot = 6
)

type Expanded

type Expanded [1]gdclass.EditorContextMenuPlugin

func (Expanded) AddContextMenuItem

func (self Expanded) AddContextMenuItem(name string, callback func(array []any), icon Texture2D.Instance)

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 slice argument; array contents depend on context menu slot.

editorContextMenuPlugin.AddContextMenuItem("File Custom options", func(array []any) {})

If you want to assign shortcut to the menu item, use Instance.AddContextMenuItemFromShortcut instead.

func (Expanded) AddContextMenuItemFromShortcut

func (self Expanded) AddContextMenuItemFromShortcut(name string, shortcut Shortcut.Instance, icon Texture2D.Instance)

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 Instance.AddMenuShortcut.

editorContextMenuPlugin.AddMenuShortcut(shortcut, func(array []any) {})
EditorContextMenuPlugin.Expanded(editorContextMenuPlugin).AddContextMenuItemFromShortcut("File Custom options", shortcut, icon)

func (Expanded) AddContextSubmenuItem

func (self Expanded) AddContextSubmenuItem(name string, menu PopupMenu.Instance, icon Texture2D.Instance)

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 graphics.gd/classdb/PopupMenu every time.

var popup_menu = PopupMenu.New()
popup_menu.AddItem("Blue")
popup_menu.AddItem("White")
popup_menu.OnIdPressed(func(id int) {})
editorContextMenuPlugin.AddContextSubmenuItem("Set Node Color", popup_menu)

type Extension

type Extension[T gdclass.Interface] struct{ gdclass.Extension[T, Instance] }

Extension can be embedded in a new struct to create an extension of this class. T should be the type that is embedding this [Extension]See Interface for methods that can be overridden by T.

func (*Extension[T]) AsEditorContextMenuPlugin

func (self *Extension[T]) AsEditorContextMenuPlugin() Instance

func (*Extension[T]) AsObject

func (self *Extension[T]) AsObject() [1]gd.Object

func (*Extension[T]) AsRefCounted

func (self *Extension[T]) AsRefCounted() [1]gd.RefCounted

type ID

type ID Object.ID

ID is a typed object ID (reference) to an instance of this class, use it to store references to objects with unknown lifetimes, as an ID will not panic on use if the underlying object has been destroyed.

func (ID) Instance

func (id ID) Instance() (Instance, bool)

type Implementation

type Implementation = implementation

Implementation implements Interface with empty methods.

type Instance

type Instance [1]gdclass.EditorContextMenuPlugin

Instance of the class with convieniently typed arguments and results.

var Nil Instance

Nil is a nil/null instance of the class. Equivalent to the zero value.

func New

func New() Instance

func (Instance) AddContextMenuItem

func (self Instance) AddContextMenuItem(name string, callback func(array []any))

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 slice argument; array contents depend on context menu slot.

editorContextMenuPlugin.AddContextMenuItem("File Custom options", func(array []any) {})

If you want to assign shortcut to the menu item, use Instance.AddContextMenuItemFromShortcut instead.

func (Instance) AddContextMenuItemFromShortcut

func (self Instance) AddContextMenuItemFromShortcut(name string, shortcut Shortcut.Instance)

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 Instance.AddMenuShortcut.

editorContextMenuPlugin.AddMenuShortcut(shortcut, func(array []any) {})
EditorContextMenuPlugin.Expanded(editorContextMenuPlugin).AddContextMenuItemFromShortcut("File Custom options", shortcut, icon)

func (Instance) AddContextSubmenuItem

func (self Instance) AddContextSubmenuItem(name string, menu PopupMenu.Instance)

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 graphics.gd/classdb/PopupMenu every time.

var popup_menu = PopupMenu.New()
popup_menu.AddItem("Blue")
popup_menu.AddItem("White")
popup_menu.OnIdPressed(func(id int) {})
editorContextMenuPlugin.AddContextSubmenuItem("Set Node Color", popup_menu)

func (Instance) AddMenuShortcut

func (self Instance) AddMenuShortcut(shortcut Shortcut.Instance, callback func(array []any))

Registers a shortcut associated with the plugin's context menu. This method should be called once (e.g. in plugin's graphics.gd/classdb/Object.Instance.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 slice argument; array contents depend on context menu slot.

editorContextMenuPlugin.AddMenuShortcut(shortcut, func(array []any) {})

func (Instance) AsEditorContextMenuPlugin

func (self Instance) AsEditorContextMenuPlugin() Instance

func (Instance) AsObject

func (self Instance) AsObject() [1]gd.Object

func (Instance) AsRefCounted

func (self Instance) AsRefCounted() [1]gd.RefCounted

func (Instance) ID

func (self Instance) ID() ID

func (*Instance) SetObject

func (self *Instance) SetObject(obj [1]gd.Object) bool

func (Instance) Virtual

func (self Instance) Virtual(name string) reflect.Value

type Interface

type Interface interface {
	// Called when creating a context menu, custom options can be added by using the [Instance.AddContextMenuItem] or [Instance.AddContextMenuItemFromShortcut] functions. 'paths' contains currently selected paths (depending on menu), which can be used to conditionally add options.
	PopupMenu(paths []string)
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL