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.
CONTEXT_SLOT_SCENE_TREE = 0Context 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.
CONTEXT_SLOT_FILESYSTEM = 1Context menu of FileSystem dock. _popup_menu() and option callback will be called with list of paths of the currently selected files.
CONTEXT_SLOT_SCRIPT_EDITOR = 2Context 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.
CONTEXT_SLOT_FILESYSTEM_CREATE = 3The "Create..." submenu of FileSystem dock's context menu, or the "New" section of the main context menu when empty space is clicked. _popup_menu() and option callback will be called with the path of the currently selected folder. When clicking the empty space, the list of paths for popup method will be empty.
func _popup_menu(paths):
if paths.is_empty():
add_context_menu_item("New Image File...", create_image)
else:
add_context_menu_item("Image File...", create_image)CONTEXT_SLOT_SCRIPT_EDITOR_CODE = 4Context 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.
CONTEXT_SLOT_SCENE_TABS = 5Context 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.
CONTEXT_SLOT_2D_EDITOR = 6Context 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.
CONTEXT_SLOT_INSPECTOR_PROPERTY = 7Context menu of the inspectors right-click menu. _popup_menu() will be called with an array of two items: The first will be the object's ID, the second will be the property name. An object can be retrieved from it's ID via instance_from_id() after converting it to an int. The option callback will receive the EditorProperty directly.