Skip to content

armgit / godot

Public Imported from GitHub
0

Godot Engine – Multi-platform 2D and 3D game engine

Rework EditorContextMenuPlugin

kobewi78c4f8db695b
diff --git a/doc/classes/EditorContextMenuPlugin.xml b/doc/classes/EditorContextMenuPlugin.xml
index 62712fa7930..c77804802f1 100644
--- a/doc/classes/EditorContextMenuPlugin.xml
+++ b/doc/classes/EditorContextMenuPlugin.xml
@@ -4,17 +4,24 @@
Plugin for adding custom context menus in the editor.
</brief_description>
<description>
- [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.
+ [EditorContextMenuPlugin] allows for the addition of custom options in the editor's context menu. Register them with [method EditorPlugin.add_context_menu_plugin].
+ See [enum ContextMenuSlot] for the list of available areas where context menu plugins are supported.
</description>
<tutorials>
</tutorials>
<methods>
- <method name="_popup_menu" qualifiers="virtual">
+ <method name="_get_menu_options" qualifiers="virtual">
+ <return type="void" />
+ <param index="0" name="data" type="Dictionary[StringName, Variant]" />
+ <description>
+ 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.
+ </description>
+ </method>
+ <method name="_popup_menu" qualifiers="virtual" deprecated="Use [method _get_menu_options] instead.">
<return type="void" />
<param index="0" name="paths" type="PackedStringArray" />
<description>
- 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 paths] contains currently selected paths (depending on menu), which can be used to conditionally add options.
+ [b]Note:[/b] Implementing this method makes the shortcut callbacks receive legacy data (for compatibility reasons).
</description>
</method>
<method name="add_context_menu_item">
@@ -23,9 +30,9 @@
<param index="1" name="callback" type="Callable" />
<param index="2" name="icon" type="Texture2D" default="null" />
<description>
- Add custom option to the context menu of the plugin's specified slot. When the option is activated, [param callback] will be called. Callback should take single [Array] argument; array contents depend on context menu slot.
+ 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].
[codeblock]
- func _popup_menu(paths):
+ func _get_menu_options(data):
add_context_menu_item("File Custom options", handle, ICON)
[/codeblock]
If you want to assign shortcut to the menu item, use [method add_context_menu_item_from_shortcut] instead.
@@ -42,7 +49,7 @@
func _init():
add_menu_shortcut(SHORTCUT, handle)
- func _popup_menu(paths):
+ func _get_menu_options(paths):
add_context_menu_item_from_shortcut("File Custom options", SHORTCUT, ICON)
[/codeblock]
</description>
@@ -55,7 +62,7 @@
<description>
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.
[codeblock]
- func _popup_menu(paths):
+ func _get_menu_options(data):
var popup_menu = PopupMenu.new()
popup_menu.add_item("Blue")
popup_menu.add_item("White")
@@ -70,7 +77,7 @@
<param index="0" name="shortcut" type="Shortcut" />
<param index="1" name="callback" type="Callable" />
<description>
- Registers a shortcut associated with the plugin's context menu. This method should be called once (e.g. in 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 [Array] argument; array contents depend on context menu slot.
+ 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].
[codeblock]
func _init():
add_menu_shortcut(SHORTCUT, handle)
@@ -80,45 +87,49 @@
</methods>
<constants>
<constant name="CONTEXT_SLOT_SCENE_TREE" value="0" enum="ContextMenuSlot">
- Context menu of Scene dock. [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.
+ Context menu of Scene dock. The data [Dictionary] contains:
+ [code]&amp;"selected_nodes": Array[Node][/code] - The list of currently selected nodes (same as [method EditorSelection.get_top_selected_nodes]).
</constant>
<constant name="CONTEXT_SLOT_FILESYSTEM" value="1" enum="ContextMenuSlot">
- Context menu of FileSystem dock. [method _popup_menu] and option callback will be called with list of paths of the currently selected files.
+ Context menu of FileSystem dock. The data [Dictionary] contains:
+ [code]&amp;"selected_files": PackedStringArray[/code] - The list of selected files.
</constant>
<constant name="CONTEXT_SLOT_SCRIPT_EDITOR" value="2" enum="ContextMenuSlot">
- Context menu of Script editor's script tabs. [method _popup_menu] will be called with the path to the currently edited script, while option callback will receive reference to that script.
+ Context menu of Script editor's script tabs and Shader editor's shader tabs. The data [Dictionary] contains:
+ [code]&amp;"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.
+ [code]&amp;"resource_path": String[/code] - The path of the selected resource.
</constant>
<constant name="CONTEXT_SLOT_FILESYSTEM_CREATE" value="3" enum="ContextMenuSlot">
- The "Create..." submenu of FileSystem dock's context menu, or the "New" section of the main context menu when empty space is clicked. [method _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.
+ 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:
+ [code]&amp;"base_directory": String[/code] - Path to the base directory where a file should be created.
+ [code]&amp;"needs_prefix": bool[/code] - Whether the option needs a "New" prefix (for consistency with native options).
[codeblock]
- func _popup_menu(paths):
- if paths.is_empty():
+ func _get_menu_options(data):
+ if data["needs_prefix"]:
add_context_menu_item("New Image File...", create_image)
else:
add_context_menu_item("Image File...", create_image)
[/codeblock]
</constant>
<constant name="CONTEXT_SLOT_SCRIPT_EDITOR_CODE" value="4" enum="ContextMenuSlot">
- Context menu of Script editor's code editor. [method _popup_menu] will be called with the path to the [CodeEdit] node. You can fetch it using this code:
- [codeblock]
- func _popup_menu(paths):
- var code_edit = Engine.get_main_loop().root.get_node(paths[0])
- [/codeblock]
- The option callback will receive reference to that node. You can use [CodeEdit] methods to perform symbol lookups etc.
+ Context menu of Script editor's code editor. The data [Dictionary] contains:
+ [code]&amp;"code_edit": CodeEdit[/code] - The code editor instance.
+ [code]&amp;"file_path": String[/code] - Path to the currently edited file.
</constant>
<constant name="CONTEXT_SLOT_SCENE_TABS" value="5" enum="ContextMenuSlot">
- Context menu of scene tabs. [method _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 menu of scene tabs. The data [Dictionary] contains:
+ [code]&amp;"selected_scene": String[/code] - Scene path of the selected/clicked scene tab. Empty if empty space was clicked.
</constant>
<constant name="CONTEXT_SLOT_2D_EDITOR" value="6" enum="ContextMenuSlot">
- Context menu of 2D editor's basic right-click menu. [method _popup_menu] will be called with paths to all [CanvasItem] nodes under the cursor. You can fetch them using this code:
- [codeblock]
- func _popup_menu(paths):
- var canvas_item = Engine.get_main_loop().root.get_node(paths[0]) # Replace 0 with the desired index.
- [/codeblock]
- 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 menu of the 2D editor's viewport. The data [Dictionary] contains:
+ [code]&amp;"hovered_nodes": Array[CanvasItem][/code] - The [CanvasItem] nodes under the cursor.
+ [code]&amp;"mouse_position": Vector2[/code] - The local mouse position in the 2D scene.
</constant>
<constant name="CONTEXT_SLOT_INSPECTOR_PROPERTY" value="7" enum="ContextMenuSlot">
- Context menu of the inspectors right-click menu. [method _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 its ID via [method @GlobalScope.instance_from_id] after converting it to an int. The option callback will receive the EditorProperty directly.
+ Context menu of an editor property in the inspector. The data [Dictionary] contains:
+ [code]&amp;"property": EditorProperty[/code] - The clicked [EditorProperty] object.
+ [code]&amp;"object": Object[/code] - The object edited by the inspector.
+ [code]&amp;"property_name": StringName[/code] - The name of the object's property that was clicked.
</constant>
</constants>
</class>
diff --git a/editor/docks/filesystem_dock.cpp b/editor/docks/filesystem_dock.cpp
index e7ebadaacb3..a63f2d404de 100644
--- a/editor/docks/filesystem_dock.cpp
+++ b/editor/docks/filesystem_dock.cpp
@@ -2734,13 +2734,8 @@ void FileSystemDock::_file_option(int p_option, const Vector<String> &p_selected
default: {
if (p_option >= EditorContextMenuPlugin::BASE_ID) {
- if (!EditorContextMenuPluginManager::get_singleton()->activate_custom_option(EditorContextMenuPlugin::CONTEXT_SLOT_FILESYSTEM, p_option, p_selected)) {
- // For create new file option, pass the path location of mouse click position instead, to plugin callback.
- String fpath = current_path;
- if (!fpath.ends_with("/")) {
- fpath = fpath.get_base_dir();
- }
- EditorContextMenuPluginManager::get_singleton()->activate_custom_option(EditorContextMenuPlugin::CONTEXT_SLOT_FILESYSTEM_CREATE, p_option, { fpath });
+ if (!EditorContextMenuPluginManager::get_singleton()->activate_custom_option(EditorContextMenuPlugin::CONTEXT_SLOT_FILESYSTEM, p_option)) {
+ EditorContextMenuPluginManager::get_singleton()->activate_custom_option(EditorContextMenuPlugin::CONTEXT_SLOT_FILESYSTEM_CREATE, p_option);
}
} else if (p_option >= CONVERT_BASE_ID) {
selected_conversion_id = p_option - CONVERT_BASE_ID;
@@ -3683,7 +3678,16 @@ void FileSystemDock::_file_and_folders_fill_popup(PopupMenu *p_popup, const Vect
p_popup->add_icon_shortcut(get_editor_theme_icon(SNAME("ExternalLink")), ED_GET_SHORTCUT("filesystem_dock/open_in_external_program"), FILE_MENU_OPEN_EXTERNAL);
}
#endif
- EditorContextMenuPluginManager::get_singleton()->add_options_from_plugins(p_popup, EditorContextMenuPlugin::CONTEXT_SLOT_FILESYSTEM, p_paths);
+
+ if (EditorContextMenuPluginManager::get_singleton()->has_plugins_for_slot(EditorContextMenuPlugin::CONTEXT_SLOT_FILESYSTEM)) {
+ EditorContextMenuPlugin::OptionsData context_data;
+ context_data["selected_files"] = p_paths;
+ EditorContextMenuPluginManager::get_singleton()->add_options_from_plugins(p_popup, EditorContextMenuPlugin::CONTEXT_SLOT_FILESYSTEM, context_data);
+
+#ifndef DISABLE_DEPRECATED
+ EditorContextMenuPluginManager::get_singleton()->add_options_from_plugins(p_popup, EditorContextMenuPlugin::CONTEXT_SLOT_FILESYSTEM, p_paths, p_paths, 1000);
+#endif
+ }
}
void FileSystemDock::_add_create_options(PopupMenu *p_popup, const String &p_base_folder) {
@@ -3699,7 +3703,17 @@ void FileSystemDock::_add_create_options(PopupMenu *p_popup, const String &p_bas
p_popup->add_icon_item(get_editor_theme_icon(SNAME("TextFile")), prefix_new ? TTRC("New TextFile...") : TTRC("TextFile..."), FILE_MENU_NEW_TEXTFILE);
p_popup->set_item_shortcut(-1, ED_GET_SHORTCUT("filesystem_dock/new_textfile"));
// Options for CONTEXT_SLOT_FILESYSTEM_CREATE are added with an offset, to avoid conflicts in case plugins add options for both FileSystem slots.
- EditorContextMenuPluginManager::get_singleton()->add_options_from_plugins(p_popup, EditorContextMenuPlugin::CONTEXT_SLOT_FILESYSTEM_CREATE, prefix_new ? PackedStringArray() : PackedStringArray{ p_base_folder }, 500);
+ if (EditorContextMenuPluginManager::get_singleton()->has_plugins_for_slot(EditorContextMenuPlugin::CONTEXT_SLOT_FILESYSTEM_CREATE)) {
+ EditorContextMenuPlugin::OptionsData context_data;
+ context_data["base_directory"] = prefix_new ? "res://" : p_base_folder;
+ context_data["needs_prefix"] = prefix_new;
+ EditorContextMenuPluginManager::get_singleton()->add_options_from_plugins(p_popup, EditorContextMenuPlugin::CONTEXT_SLOT_FILESYSTEM_CREATE, context_data, 500);
+
+#ifndef DISABLE_DEPRECATED
+ const PackedStringArray legacy_data = prefix_new ? PackedStringArray() : PackedStringArray{ p_base_folder };
+ EditorContextMenuPluginManager::get_singleton()->add_options_from_plugins(p_popup, EditorContextMenuPlugin::CONTEXT_SLOT_FILESYSTEM_CREATE, legacy_data, legacy_data, 1500);
+#endif
+ }
}
void FileSystemDock::_tree_rmb_select(const Vector2 &p_pos, MouseButton p_button) {
@@ -3921,34 +3935,61 @@ void FileSystemDock::_tree_gui_input(Ref<InputEvent> p_event) {
if (option_id > -1) {
_tree_rmb_option(option_id);
} else {
- bool create = false;
- Callable custom_callback = EditorContextMenuPluginManager::get_singleton()->match_custom_shortcut(EditorContextMenuPlugin::CONTEXT_SLOT_FILESYSTEM, p_event);
- if (!custom_callback.is_valid()) {
- create = true;
- custom_callback = EditorContextMenuPluginManager::get_singleton()->match_custom_shortcut(EditorContextMenuPlugin::CONTEXT_SLOT_FILESYSTEM_CREATE, p_event);
- }
-
- if (custom_callback.is_valid()) {
- Vector<String> selected = _tree_get_selected(false);
- if (create) {
- if (selected.is_empty()) {
- selected.append("res://");
- } else if (selected.size() == 1) {
- selected.write[0] = selected[0].get_base_dir();
- } else {
- return;
- }
- }
- EditorContextMenuPluginManager::get_singleton()->invoke_callback(custom_callback, selected);
- } else {
+ const PackedStringArray selected = _tree_get_selected(false);
+ if (!_handle_custom_context_callback(p_event, selected)) {
return;
}
}
-
accept_event();
}
}
+bool FileSystemDock::_handle_custom_context_callback(Ref<InputEvent> p_event, const PackedStringArray &p_selected) {
+ bool create = false;
+ Callable custom_callback = EditorContextMenuPluginManager::get_singleton()->match_custom_shortcut(EditorContextMenuPlugin::CONTEXT_SLOT_FILESYSTEM, p_event);
+ if (!custom_callback.is_valid()) {
+ create = true;
+ custom_callback = EditorContextMenuPluginManager::get_singleton()->match_custom_shortcut(EditorContextMenuPlugin::CONTEXT_SLOT_FILESYSTEM_CREATE, p_event);
+ }
+
+ if (!custom_callback.is_valid()) {
+ return false;
+ }
+
+ String base_dir;
+ if (create) {
+ if (p_selected.is_empty()) {
+ base_dir = "res://";
+ } else if (p_selected.size() == 1) {
+ base_dir = p_selected[0].get_base_dir();
+ } else {
+ return false;
+ }
+ }
+
+#ifndef DISABLE_DEPRECATED
+ if (p_event->get_meta("_legacy_shortcut", false)) {
+ if (create && p_selected.is_empty()) {
+ EditorContextMenuPluginManager::get_singleton()->invoke_callback(custom_callback, PackedStringArray{ "res://" });
+ } else {
+ EditorContextMenuPluginManager::get_singleton()->invoke_callback(custom_callback, p_selected);
+ }
+ return true;
+ }
+#endif
+
+ EditorContextMenuPlugin::OptionsData context_data;
+ if (create) {
+ context_data["base_directory"] = base_dir;
+ context_data["needs_prefix"] = p_selected.is_empty();
+ } else {
+ context_data["selected_files"] = p_selected;
+ }
+ EditorContextMenuPluginManager::get_singleton()->invoke_callback(custom_callback, context_data);
+
+ return true;
+}
+
void FileSystemDock::_file_list_gui_input(Ref<InputEvent> p_event) {
Ref<InputEventMouseMotion> mm = p_event;
if (mm.is_valid() && holding_branch) {
@@ -3997,18 +4038,11 @@ void FileSystemDock::_file_list_gui_input(Ref<InputEvent> p_event) {
if (option_id > -1) {
_file_list_rmb_option(option_id);
} else {
- Callable custom_callback = EditorContextMenuPluginManager::get_singleton()->match_custom_shortcut(EditorContextMenuPlugin::CONTEXT_SLOT_FILESYSTEM, p_event);
- if (!custom_callback.is_valid()) {
- custom_callback = EditorContextMenuPluginManager::get_singleton()->match_custom_shortcut(EditorContextMenuPlugin::CONTEXT_SLOT_FILESYSTEM_CREATE, p_event);
- }
-
- if (custom_callback.is_valid()) {
- EditorContextMenuPluginManager::get_singleton()->invoke_callback(custom_callback, _file_list_get_selected());
- } else {
+ const PackedStringArray selected = _file_list_get_selected();
+ if (!_handle_custom_context_callback(p_event, selected)) {
return;
}
}
-
accept_event();
}
diff --git a/editor/docks/filesystem_dock.h b/editor/docks/filesystem_dock.h
index fcdc1898be7..aa4286da8a4 100644
--- a/editor/docks/filesystem_dock.h
+++ b/editor/docks/filesystem_dock.h
@@ -291,6 +291,7 @@ private:
void _file_list_gui_input(Ref<InputEvent> p_event);
void _tree_gui_input(Ref<InputEvent> p_event);
+ bool _handle_custom_context_callback(Ref<InputEvent> p_event, const PackedStringArray &p_selected);
HashSet<String> _get_valid_conversions_for_file_paths(const Vector<String> &p_paths);
diff --git a/editor/docks/scene_tree_dock.cpp b/editor/docks/scene_tree_dock.cpp
index d691091be2b..02d8a65f050 100644
--- a/editor/docks/scene_tree_dock.cpp
+++ b/editor/docks/scene_tree_dock.cpp
@@ -262,7 +262,24 @@ void SceneTreeDock::shortcut_input(const Ref<InputEvent> &p_event) {
} else {
const Callable custom_callback = EditorContextMenuPluginManager::get_singleton()->match_custom_shortcut(EditorContextMenuPlugin::CONTEXT_SLOT_SCENE_TREE, p_event);
if (custom_callback.is_valid()) {
- EditorContextMenuPluginManager::get_singleton()->invoke_callback(custom_callback, _get_selection_array());
+ const List<Node *> selection = editor_selection->get_top_selected_node_list();
+ TypedArray<Node> selected_nodes;
+ selected_nodes.reserve(selection.size());
+ for (const Node *node : selection) {
+ selected_nodes.push_back(node);
+ }
+
+#ifndef DISABLE_DEPRECATED
+ if (p_event->get_meta("_legacy_shortcut", false)) {
+ EditorContextMenuPluginManager::get_singleton()->invoke_callback(custom_callback, selected_nodes);
+ accept_event();
+ return;
+ }
+#endif
+
+ EditorContextMenuPlugin::OptionsData context_data;
+ context_data["selected_nodes"] = selected_nodes;
+ EditorContextMenuPluginManager::get_singleton()->invoke_callback(custom_callback, context_data);
} else {
return;
}
@@ -1628,7 +1645,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
default: {
if (p_tool >= EditorContextMenuPlugin::BASE_ID) {
- EditorContextMenuPluginManager::get_singleton()->activate_custom_option(EditorContextMenuPlugin::CONTEXT_SLOT_SCENE_TREE, p_tool, _get_selection_array());
+ EditorContextMenuPluginManager::get_singleton()->activate_custom_option(EditorContextMenuPlugin::CONTEXT_SLOT_SCENE_TREE, p_tool);
break;
}
@@ -3648,18 +3665,6 @@ void SceneTreeDock::_normalize_drop(Node *&to_node, int &to_pos, int p_type) {
}
}
-Array SceneTreeDock::_get_selection_array() {
- const List<Node *> selection = editor_selection->get_top_selected_node_list();
- TypedArray<Node> array;
- array.resize(selection.size());
-
- int i = 0;
- for (const Node *E : selection) {
- array[i++] = E;
- }
- return array;
-}
-
void SceneTreeDock::_files_dropped(const Vector<String> &p_files, NodePath p_to, int p_type) {
Node *node = get_node(p_to);
ERR_FAIL_NULL(node);
@@ -3873,7 +3878,16 @@ void SceneTreeDock::_tree_rmb(const Vector2 &p_menu_pos) {
menu->add_icon_shortcut(get_editor_theme_icon(SNAME("Add")), ED_GET_SHORTCUT("scene_tree/add_child_node"), TOOL_NEW);
menu->add_icon_shortcut(get_editor_theme_icon(SNAME("Instance")), ED_GET_SHORTCUT("scene_tree/instantiate_scene"), TOOL_INSTANTIATE);
- EditorContextMenuPluginManager::get_singleton()->add_options_from_plugins(menu, EditorContextMenuPlugin::CONTEXT_SLOT_SCENE_TREE, PackedStringArray());
+
+ if (EditorContextMenuPluginManager::get_singleton()->has_plugins_for_slot(EditorContextMenuPlugin::CONTEXT_SLOT_SCENE_TREE)) {
+ EditorContextMenuPlugin::OptionsData context_data;
+ context_data["selected_nodes"] = TypedArray<Node>();
+
+ EditorContextMenuPluginManager::get_singleton()->add_options_from_plugins(menu, EditorContextMenuPlugin::CONTEXT_SLOT_SCENE_TREE, context_data);
+#ifndef DISABLE_DEPRECATED
+ EditorContextMenuPluginManager::get_singleton()->add_options_from_plugins(menu, EditorContextMenuPlugin::CONTEXT_SLOT_SCENE_TREE, PackedStringArray(), TypedArray<Node>(), 500);
+#endif
+ }
menu->reset_size();
menu->set_position(p_menu_pos);
@@ -4146,13 +4160,26 @@ void SceneTreeDock::_tree_rmb(const Vector2 &p_menu_pos) {
#undef BEGIN_SECTION
#undef END_SECTION
- Vector<String> p_paths;
- Node *root = EditorNode::get_singleton()->get_edited_scene();
- for (const List<Node *>::Element *E = selection.front(); E; E = E->next()) {
- String node_path = String(root->get_path().rel_path_to(E->get()->get_path()));
- p_paths.push_back(node_path);
+ if (EditorContextMenuPluginManager::get_singleton()->has_plugins_for_slot(EditorContextMenuPlugin::CONTEXT_SLOT_SCENE_TREE)) {
+ TypedArray<Node> selected_nodes;
+ selected_nodes.reserve(selection.size());
+ for (const Node *node : selection) {
+ selected_nodes.append(node);
+ }
+ EditorContextMenuPlugin::OptionsData context_data;
+ context_data["selected_nodes"] = selected_nodes;
+ EditorContextMenuPluginManager::get_singleton()->add_options_from_plugins(menu, EditorContextMenuPlugin::CONTEXT_SLOT_SCENE_TREE, context_data);
+
+#ifndef DISABLE_DEPRECATED
+ Vector<String> p_paths;
+ Node *root = EditorNode::get_singleton()->get_edited_scene();
+ for (const Node *node : selection) {
+ const String node_path = (String)root->get_path().rel_path_to(node->get_path());
+ p_paths.push_back(node_path);
+ }
+ EditorContextMenuPluginManager::get_singleton()->add_options_from_plugins(menu, EditorContextMenuPlugin::CONTEXT_SLOT_SCENE_TREE, p_paths, selected_nodes, 500);
+#endif
}
- EditorContextMenuPluginManager::get_singleton()->add_options_from_plugins(menu, EditorContextMenuPlugin::CONTEXT_SLOT_SCENE_TREE, p_paths);
menu->reset_size();
menu->set_position(p_menu_pos);
diff --git a/editor/docks/scene_tree_dock.h b/editor/docks/scene_tree_dock.h
index 3cc1960ef90..9bec42e23fa 100644
--- a/editor/docks/scene_tree_dock.h
+++ b/editor/docks/scene_tree_dock.h
@@ -262,7 +262,6 @@ class SceneTreeDock : public EditorDock {
bool _has_tracks_to_delete(Node *p_node, List<Node *> &p_to_delete) const;
void _normalize_drop(Node *&to_node, int &to_pos, int p_type);
- Array _get_selection_array();
void _nodes_dragged(const Array &p_nodes, NodePath p_to, int p_type);
void _files_dropped(const Vector<String> &p_files, NodePath p_to, int p_type);
diff --git a/editor/inspector/editor_context_menu_plugin.cpp b/editor/inspector/editor_context_menu_plugin.cpp
index d17a20c7723..e5e75f4173e 100644
--- a/editor/inspector/editor_context_menu_plugin.cpp
+++ b/editor/inspector/editor_context_menu_plugin.cpp
@@ -36,10 +36,24 @@
#include "scene/gui/popup_menu.h"
#include "scene/resources/texture.h"
-void EditorContextMenuPlugin::get_options(const Vector<String> &p_paths) {
+void EditorContextMenuPlugin::get_options(const OptionsData &p_data) {
+ context_data = p_data;
+ GDVIRTUAL_CALL(_get_menu_options, p_data);
+}
+
+#ifndef DISABLE_DEPRECATED
+void EditorContextMenuPlugin::get_options(const Vector<String> &p_paths, const Variant &p_data) {
+ legacy_data = p_data;
+ legacy_mode = true;
GDVIRTUAL_CALL(_popup_menu, p_paths);
+ legacy_mode = false;
}
+bool EditorContextMenuPlugin::has_legacy_shortcuts() const {
+ return GDVIRTUAL_IS_OVERRIDDEN(_popup_menu);
+}
+#endif
+
void EditorContextMenuPlugin::add_menu_shortcut(const Ref<Shortcut> &p_shortcut, const Callable &p_callable) {
context_menu_shortcuts.insert(p_shortcut, p_callable);
}
@@ -52,6 +66,9 @@ void EditorContextMenuPlugin::add_context_menu_item(const String &p_name, const
item.item_name = p_name;
item.callable = p_callable;
item.icon = p_texture;
+#ifndef DISABLE_DEPRECATED
+ item.legacy = legacy_mode;
+#endif
context_menu_items.insert(p_name, item);
}
@@ -64,6 +81,9 @@ void EditorContextMenuPlugin::add_context_menu_item_from_shortcut(const String &
item.callable = *callback;
item.icon = p_texture;
item.shortcut = p_shortcut;
+#ifndef DISABLE_DEPRECATED
+ item.legacy = legacy_mode;
+#endif
context_menu_items.insert(p_name, item);
}
@@ -83,7 +103,10 @@ void EditorContextMenuPlugin::_bind_methods() {
ClassDB::bind_method(D_METHOD("add_context_menu_item_from_shortcut", "name", "shortcut", "icon"), &EditorContextMenuPlugin::add_context_menu_item_from_shortcut, DEFVAL(Ref<Texture2D>()));
ClassDB::bind_method(D_METHOD("add_context_submenu_item", "name", "menu", "icon"), &EditorContextMenuPlugin::add_context_submenu_item, DEFVAL(Ref<Texture2D>()));
+ GDVIRTUAL_BIND(_get_menu_options, "data");
+#ifndef DISABLE_DEPRECATED
GDVIRTUAL_BIND(_popup_menu, "paths");
+#endif
BIND_ENUM_CONSTANT(CONTEXT_SLOT_SCENE_TREE);
BIND_ENUM_CONSTANT(CONTEXT_SLOT_FILESYSTEM);
@@ -119,7 +142,7 @@ bool EditorContextMenuPluginManager::has_plugins_for_slot(ContextMenuSlot p_slot
return false;
}
-void EditorContextMenuPluginManager::add_options_from_plugins(PopupMenu *p_popup, ContextMenuSlot p_slot, const Vector<String> &p_paths, int p_id_offset) {
+void EditorContextMenuPluginManager::add_options_from_plugins(PopupMenu *p_popup, ContextMenuSlot p_slot, const EditorContextMenuPlugin::OptionsData &p_data, int p_id_offset) {
bool separator_added = false;
const int icon_size = p_popup->get_theme_constant(SNAME("class_icon_size"), EditorStringName(Editor));
int id = EditorContextMenuPlugin::BASE_ID + p_id_offset;
@@ -129,10 +152,10 @@ void EditorContextMenuPluginManager::add_options_from_plugins(PopupMenu *p_popup
continue;
}
plugin->context_menu_items.clear();
- plugin->get_options(p_paths);
+ plugin->get_options(p_data);
HashMap<String, EditorContextMenuPlugin::ContextMenuItem> &items = plugin->context_menu_items;
- if (items.size() > 0 && !separator_added) {
+ if (!separator_added && !items.is_empty()) {
separator_added = true;
p_popup->add_separator();
}
@@ -160,6 +183,51 @@ void EditorContextMenuPluginManager::add_options_from_plugins(PopupMenu *p_popup
}
}
+#ifndef DISABLE_DEPRECATED
+void EditorContextMenuPluginManager::add_options_from_plugins(PopupMenu *p_popup, ContextMenuSlot p_slot, const Vector<String> &p_paths, const Variant &p_data, int p_id_offset) {
+ bool separator_added = false;
+ const int icon_size = p_popup->get_theme_constant(SNAME("class_icon_size"), EditorStringName(Editor));
+ int id = EditorContextMenuPlugin::BASE_ID + p_id_offset;
+
+ for (Ref<EditorContextMenuPlugin> &plugin : plugin_list) {
+ if (plugin->slot != p_slot) {
+ continue;
+ }
+ plugin->get_options(p_paths, p_data);
+
+ HashMap<String, EditorContextMenuPlugin::ContextMenuItem> &items = plugin->context_menu_items;
+ for (KeyValue<String, EditorContextMenuPlugin::ContextMenuItem> &E : items) {
+ EditorContextMenuPlugin::ContextMenuItem &item = E.value;
+ if (!item.legacy) {
+ continue;
+ }
+
+ if (!separator_added) {
+ separator_added = true;
+ p_popup->add_separator();
+ }
+ item.id = id;
+
+ if (item.submenu) {
+ p_popup->add_submenu_node_item(item.item_name, item.submenu, id);
+ } else {
+ p_popup->add_item(item.item_name, id);
+ }
+
+ if (item.icon.is_valid()) {
+ p_popup->set_item_icon(-1, item.icon);
+ p_popup->set_item_icon_max_width(-1, icon_size);
+ }
+
+ if (item.shortcut.is_valid()) {
+ p_popup->set_item_shortcut(-1, item.shortcut, true);
+ }
+ id++;
+ }
+ }
+}
+#endif
+
Callable EditorContextMenuPluginManager::match_custom_shortcut(EditorContextMenuPlugin::ContextMenuSlot p_slot, const Ref<InputEvent> &p_event) {
for (Ref<EditorContextMenuPlugin> &plugin : plugin_list) {
if (plugin->slot != p_slot) {
@@ -168,6 +236,11 @@ Callable EditorContextMenuPluginManager::match_custom_shortcut(EditorContextMenu
for (KeyValue<Ref<Shortcut>, Callable> &E : plugin->context_menu_shortcuts) {
if (E.key->matches_event(p_event)) {
+#ifndef DISABLE_DEPRECATED
+ if (plugin->has_legacy_shortcuts()) {
+ p_event->set_meta("_legacy_shortcut", true); // Sorry :(
+ }
+#endif
return E.value;
}
}
@@ -175,7 +248,7 @@ Callable EditorContextMenuPluginManager::match_custom_shortcut(EditorContextMenu
return Callable();
}
-bool EditorContextMenuPluginManager::activate_custom_option(ContextMenuSlot p_slot, int p_option, const Variant &p_arg) {
+bool EditorContextMenuPluginManager::activate_custom_option(ContextMenuSlot p_slot, int p_option) {
for (Ref<EditorContextMenuPlugin> &plugin : plugin_list) {
if (plugin->slot != p_slot) {
continue;
@@ -183,7 +256,13 @@ bool EditorContextMenuPluginManager::activate_custom_option(ContextMenuSlot p_sl
for (KeyValue<String, EditorContextMenuPlugin::ContextMenuItem> &E : plugin->context_menu_items) {
if (E.value.id == p_option) {
- invoke_callback(E.value.callable, p_arg);
+#ifndef DISABLE_DEPRECATED
+ if (E.value.legacy) {
+ invoke_callback(E.value.callable, plugin->legacy_data);
+ return true;
+ }
+#endif
+ invoke_callback(E.value.callable, plugin->context_data);
return true;
}
}
diff --git a/editor/inspector/editor_context_menu_plugin.h b/editor/inspector/editor_context_menu_plugin.h
index ed09216ab97..5604e718062 100644
--- a/editor/inspector/editor_context_menu_plugin.h
+++ b/editor/inspector/editor_context_menu_plugin.h
@@ -32,6 +32,7 @@
#include "core/object/gdvirtual.gen.h"
#include "core/object/ref_counted.h"
+#include "core/variant/typed_dictionary.h"
class InputEvent;
class PopupMenu;
@@ -45,6 +46,11 @@ class EditorContextMenuPlugin : public RefCounted {
static constexpr int MAX_ITEMS = 100;
+ int slot = -1;
+#ifndef DISABLE_DEPRECATED
+ bool legacy_mode = false;
+#endif
+
public:
enum ContextMenuSlot {
CONTEXT_SLOT_SCENE_TREE,
@@ -58,10 +64,8 @@ public:
};
static constexpr int BASE_ID = 2000;
-private:
- int slot = -1;
+ using OptionsData = TypedDictionary<StringName, Variant>;
-public:
struct ContextMenuItem {
int id = 0;
String item_name;
@@ -69,17 +73,34 @@ public:
Ref<Texture2D> icon;
Ref<Shortcut> shortcut;
PopupMenu *submenu = nullptr;
+#ifndef DISABLE_DEPRECATED
+ bool legacy = false;
+#endif
};
+
+private:
HashMap<String, ContextMenuItem> context_menu_items;
HashMap<Ref<Shortcut>, Callable> context_menu_shortcuts;
+ OptionsData context_data;
+#ifndef DISABLE_DEPRECATED
+ Variant legacy_data;
+#endif
+
protected:
static void _bind_methods();
+ GDVIRTUAL1(_get_menu_options, const OptionsData &);
+#ifndef DISABLE_DEPRECATED
GDVIRTUAL1(_popup_menu, Vector<String>);
+#endif
public:
- virtual void get_options(const Vector<String> &p_paths);
+ virtual void get_options(const OptionsData &p_data);
+#ifndef DISABLE_DEPRECATED
+ virtual void get_options(const Vector<String> &p_paths, const Variant &p_data);
+ bool has_legacy_shortcuts() const;
+#endif
void add_menu_shortcut(const Ref<Shortcut> &p_shortcut, const Callable &p_callable);
void add_context_menu_item(const String &p_name, const Callable &p_callable, const Ref<Texture2D> &p_texture);
@@ -104,9 +125,10 @@ public:
void remove_plugin(const Ref<EditorContextMenuPlugin> &p_plugin);
bool has_plugins_for_slot(ContextMenuSlot p_slot);
- void add_options_from_plugins(PopupMenu *p_popup, ContextMenuSlot p_slot, const Vector<String> &p_paths, int p_id_offset = 0);
+ void add_options_from_plugins(PopupMenu *p_popup, ContextMenuSlot p_slot, const EditorContextMenuPlugin::OptionsData &p_data, int p_id_offset = 0);
+ void add_options_from_plugins(PopupMenu *p_popup, ContextMenuSlot p_slot, const Vector<String> &p_paths, const Variant &p_data, int p_id_offset = 0);
Callable match_custom_shortcut(ContextMenuSlot p_slot, const Ref<InputEvent> &p_event);
- bool activate_custom_option(ContextMenuSlot p_slot, int p_option, const Variant &p_arg);
+ bool activate_custom_option(ContextMenuSlot p_slot, int p_option);
void invoke_callback(const Callable &p_callback, const Variant &p_arg);
diff --git a/editor/inspector/editor_inspector.cpp b/editor/inspector/editor_inspector.cpp
index cb1836a1174..83bbe1450dd 100644
--- a/editor/inspector/editor_inspector.cpp
+++ b/editor/inspector/editor_inspector.cpp
@@ -1329,7 +1329,20 @@ void EditorProperty::shortcut_input(const Ref<InputEvent> &p_event) {
} else {
const Callable custom_callback = EditorContextMenuPluginManager::get_singleton()->match_custom_shortcut(EditorContextMenuPlugin::CONTEXT_SLOT_INSPECTOR_PROPERTY, p_event);
if (custom_callback.is_valid()) {
- EditorContextMenuPluginManager::get_singleton()->invoke_callback(custom_callback, this);
+#ifndef DISABLE_DEPRECATED
+ if (p_event->get_meta("_legacy_shortcut", false)) {
+ EditorContextMenuPluginManager::get_singleton()->invoke_callback(custom_callback, this);
+ accept_event();
+ return;
+ }
+#endif
+
+ EditorContextMenuPlugin::OptionsData context_data;
+ context_data["property"] = this;
+ context_data["object"] = get_edited_object();
+ context_data["property_name"] = get_edited_property();
+
+ EditorContextMenuPluginManager::get_singleton()->invoke_callback(custom_callback, context_data);
accept_event();
}
}
@@ -1615,7 +1628,7 @@ void EditorProperty::menu_option(int p_option) {
} break;
default: {
if (p_option >= EditorContextMenuPlugin::BASE_ID) {
- EditorContextMenuPluginManager::get_singleton()->activate_custom_option(EditorContextMenuPlugin::CONTEXT_SLOT_INSPECTOR_PROPERTY, p_option, this);
+ EditorContextMenuPluginManager::get_singleton()->activate_custom_option(EditorContextMenuPlugin::CONTEXT_SLOT_INSPECTOR_PROPERTY, p_option);
}
}
}
@@ -1785,9 +1798,17 @@ void EditorProperty::_update_popup() {
menu->add_icon_item(theme_cache.help_icon, TTR("Open Documentation"), MENU_OPEN_DOCUMENTATION);
}
- if (EditorContextMenuPluginManager::get_singleton()) {
+ if (EditorContextMenuPluginManager::get_singleton() && EditorContextMenuPluginManager::get_singleton()->has_plugins_for_slot(EditorContextMenuPlugin::CONTEXT_SLOT_INSPECTOR_PROPERTY)) {
+ EditorContextMenuPlugin::OptionsData context_data;
+ context_data["property"] = this;
+ context_data["object"] = get_edited_object();
+ context_data["property_name"] = get_edited_property();
+ EditorContextMenuPluginManager::get_singleton()->add_options_from_plugins(menu, EditorContextMenuPlugin::CONTEXT_SLOT_INSPECTOR_PROPERTY, context_data);
+
+#ifndef DISABLE_DEPRECATED
Vector<String> property_paths = { String::num_int64(get_edited_object()->get_instance_id()), property_path };
- EditorContextMenuPluginManager::get_singleton()->add_options_from_plugins(menu, EditorContextMenuPlugin::CONTEXT_SLOT_INSPECTOR_PROPERTY, property_paths);
+ EditorContextMenuPluginManager::get_singleton()->add_options_from_plugins(menu, EditorContextMenuPlugin::CONTEXT_SLOT_INSPECTOR_PROPERTY, property_paths, this, 500);
+#endif
}
}
diff --git a/editor/scene/canvas_item_editor_plugin.cpp b/editor/scene/canvas_item_editor_plugin.cpp
index 9b326ef50fe..a49e11fdb0a 100644
--- a/editor/scene/canvas_item_editor_plugin.cpp
+++ b/editor/scene/canvas_item_editor_plugin.cpp
@@ -562,13 +562,24 @@ void CanvasItemEditor::shortcut_input(const Ref<InputEvent> &p_ev) {
Vector<SelectResult> currently_hovered;
_get_canvas_items_at_pos(transform.affine_inverse().xform(viewport->get_local_mouse_position()), currently_hovered, true);
- TypedArray<Node> nodes;
- nodes.reserve(currently_hovered.size());
+ TypedArray<CanvasItem> items;
+ items.reserve(currently_hovered.size());
for (const SelectResult &result : currently_hovered) {
- nodes.append(result.item);
+ items.append(result.item);
}
- EditorContextMenuPluginManager::get_singleton()->invoke_callback(custom_callback, nodes);
+#ifndef DISABLE_DEPRECATED
+ if (p_ev->get_meta("_legacy_shortcut", false)) {
+ EditorContextMenuPluginManager::get_singleton()->invoke_callback(custom_callback, items);
+ accept_event();
+ return;
+ }
+#endif
+
+ EditorContextMenuPlugin::OptionsData context_data;
+ context_data["hovered_nodes"] = items;
+ context_data["mouse_position"] = transform.affine_inverse().xform(viewport->get_local_mouse_position());
+ EditorContextMenuPluginManager::get_singleton()->invoke_callback(custom_callback, context_data);
accept_event();
}
}
@@ -1066,15 +1077,7 @@ void CanvasItemEditor::_add_node_pressed(int p_result) {
} break;
default: {
if (p_result >= EditorContextMenuPlugin::BASE_ID) {
- TypedArray<Node> nodes;
- nodes.resize(selection_results.size());
-
- int i = 0;
- for (const SelectResult &result : selection_results) {
- nodes[i] = result.item;
- i++;
- }
- EditorContextMenuPluginManager::get_singleton()->activate_custom_option(EditorContextMenuPlugin::CONTEXT_SLOT_2D_EDITOR, p_result, nodes);
+ EditorContextMenuPluginManager::get_singleton()->activate_custom_option(EditorContextMenuPlugin::CONTEXT_SLOT_2D_EDITOR, p_result);
}
}
}
@@ -2569,19 +2572,29 @@ bool CanvasItemEditor::_gui_input_select(const Ref<InputEvent> &p_event) {
}
}
- // Context menu plugin receives paths of nodes under cursor. It's a complex operation, so perform it only when necessary.
if (EditorContextMenuPluginManager::get_singleton()->has_plugins_for_slot(EditorContextMenuPlugin::CONTEXT_SLOT_2D_EDITOR)) {
- selection_results.clear();
- _get_canvas_items_at_pos(transform.affine_inverse().xform(viewport->get_local_mouse_position()), selection_results, true);
+ Vector<SelectResult> currently_hovered;
+ _get_canvas_items_at_pos(transform.affine_inverse().xform(b->get_position()), currently_hovered, true);
- PackedStringArray paths;
- paths.resize(selection_results.size());
- String *paths_write = paths.ptrw();
+ TypedArray<CanvasItem *> items;
+ items.reserve(currently_hovered.size());
+ for (const SelectResult &result : currently_hovered) {
+ items.push_back(result.item);
+ }
+
+ EditorContextMenuPlugin::OptionsData context_data;
+ context_data["hovered_nodes"] = items;
+ context_data["mouse_position"] = transform.affine_inverse().xform(b->get_position());
+ EditorContextMenuPluginManager::get_singleton()->add_options_from_plugins(add_node_menu, EditorContextMenuPlugin::CONTEXT_SLOT_2D_EDITOR, context_data);
- for (int i = 0; i < paths.size(); i++) {
- paths_write[i] = String(selection_results[i].item->get_path());
+#ifndef DISABLE_DEPRECATED
+ PackedStringArray paths;
+ paths.reserve_exact(currently_hovered.size());
+ for (const SelectResult &result : currently_hovered) {
+ paths.append((String)result.item->get_path());
}
- EditorContextMenuPluginManager::get_singleton()->add_options_from_plugins(add_node_menu, EditorContextMenuPlugin::CONTEXT_SLOT_2D_EDITOR, paths);
+ EditorContextMenuPluginManager::get_singleton()->add_options_from_plugins(add_node_menu, EditorContextMenuPlugin::CONTEXT_SLOT_2D_EDITOR, paths, items, 500);
+#endif
}
add_node_menu->reset_size();
diff --git a/editor/scene/editor_scene_tabs.cpp b/editor/scene/editor_scene_tabs.cpp
index 0a78d340270..36bd4add8f8 100644
--- a/editor/scene/editor_scene_tabs.cpp
+++ b/editor/scene/editor_scene_tabs.cpp
@@ -223,9 +223,6 @@ void EditorSceneTabs::_update_context_menu(int p_index) {
DISABLE_LAST_OPTION_IF(EditorNode::get_editor_data().get_edited_scene_count() == tab_id + 1);
scene_tabs_context_menu->add_shortcut(ED_GET_SHORTCUT("editor/close_all_scenes"), EditorNode::SCENE_CLOSE_ALL);
scene_tabs_context_menu->set_item_text(-1, TTRC("Close All Tabs"));
-
- const PackedStringArray paths = { EditorNode::get_editor_data().get_scene_path(tab_id) };
- EditorContextMenuPluginManager::get_singleton()->add_options_from_plugins(scene_tabs_context_menu, EditorContextMenuPlugin::CONTEXT_SLOT_SCENE_TABS, paths);
} else {
scene_tabs_context_menu->add_separator();
scene_tabs_context_menu->add_shortcut(ED_GET_SHORTCUT("editor/reopen_closed_scene"), EditorNode::SCENE_OPEN_PREV);
@@ -233,11 +230,20 @@ void EditorSceneTabs::_update_context_menu(int p_index) {
DISABLE_LAST_OPTION_IF(!EditorNode::get_singleton()->has_previous_closed_scenes());
scene_tabs_context_menu->add_shortcut(ED_GET_SHORTCUT("editor/close_all_scenes"), EditorNode::SCENE_CLOSE_ALL);
scene_tabs_context_menu->set_item_text(-1, TTRC("Close All Tabs"));
-
- EditorContextMenuPluginManager::get_singleton()->add_options_from_plugins(scene_tabs_context_menu, EditorContextMenuPlugin::CONTEXT_SLOT_SCENE_TABS, {});
}
#undef DISABLE_LAST_OPTION_IF
+ if (EditorContextMenuPluginManager::get_singleton()->has_plugins_for_slot(EditorContextMenuPlugin::CONTEXT_SLOT_SCENE_TABS)) {
+ EditorContextMenuPlugin::OptionsData context_data;
+ context_data["selected_scene"] = (tab_id >= 0 ? EditorNode::get_editor_data().get_scene_path(tab_id) : String());
+ EditorContextMenuPluginManager::get_singleton()->add_options_from_plugins(scene_tabs_context_menu, EditorContextMenuPlugin::CONTEXT_SLOT_SCENE_TABS, context_data);
+
+#ifndef DISABLE_DEPRECATED
+ const PackedStringArray paths = tab_id >= 0 ? PackedStringArray{ EditorNode::get_editor_data().get_scene_path(tab_id) } : PackedStringArray();
+ EditorContextMenuPluginManager::get_singleton()->add_options_from_plugins(scene_tabs_context_menu, EditorContextMenuPlugin::CONTEXT_SLOT_SCENE_TABS, paths, context_data["selected_scene"], 500);
+#endif
+ }
+
last_hovered_tab = tab_id;
}
@@ -247,7 +253,7 @@ int EditorSceneTabs::get_option_tab() const {
void EditorSceneTabs::_custom_menu_option(int p_option) {
if (p_option >= EditorContextMenuPlugin::BASE_ID) {
- EditorContextMenuPluginManager::get_singleton()->activate_custom_option(EditorContextMenuPlugin::CONTEXT_SLOT_SCENE_TABS, p_option, last_hovered_tab >= 0 ? EditorNode::get_editor_data().get_scene_path(last_hovered_tab) : String());
+ EditorContextMenuPluginManager::get_singleton()->activate_custom_option(EditorContextMenuPlugin::CONTEXT_SLOT_SCENE_TABS, p_option);
}
}
@@ -428,7 +434,18 @@ void EditorSceneTabs::shortcut_input(const Ref<InputEvent> &p_event) {
} else {
const Callable custom_callback = EditorContextMenuPluginManager::get_singleton()->match_custom_shortcut(EditorContextMenuPlugin::CONTEXT_SLOT_SCENE_TABS, p_event);
if (custom_callback.is_valid()) {
- EditorContextMenuPluginManager::get_singleton()->invoke_callback(custom_callback, last_hovered_tab >= 0 ? EditorNode::get_editor_data().get_scene_path(last_hovered_tab) : String());
+#ifndef DISABLE_DEPRECATED
+ if (p_event->get_meta("_legacy_shortcut", false)) {
+ EditorContextMenuPluginManager::get_singleton()->invoke_callback(custom_callback, last_hovered_tab >= 0 ? EditorNode::get_editor_data().get_scene_path(last_hovered_tab) : String());
+ accept_event();
+ return;
+ }
+#endif
+
+ EditorContextMenuPlugin::OptionsData context_data;
+ context_data["selected_scene"] = (get_current_tab() >= 0 ? EditorNode::get_editor_data().get_scene_path(get_current_tab()) : String());
+ EditorContextMenuPluginManager::get_singleton()->invoke_callback(custom_callback, context_data);
+
accept_event();
}
}
diff --git a/editor/script/script_editor_plugin.cpp b/editor/script/script_editor_plugin.cpp
index 413c38f0b9a..f7904b46c12 100644
--- a/editor/script/script_editor_plugin.cpp
+++ b/editor/script/script_editor_plugin.cpp
@@ -360,20 +360,34 @@ void DocumentList::_show_context_menu() {
return;
}
- ScriptEditorBase *seb = Object::cast_to<ScriptEditorBase>(script_editor->tab_container->get_tab_control(selected));
script_editor->_setup_popup_menu(context_menu, true);
script_editor->_prepare_popup_menu(context_menu, true);
// Context menu plugin.
- PackedStringArray selected_paths;
- if (seb) {
- Ref<Resource> res = seb->get_edited_resource();
- if (res.is_valid()) {
- String path = res->get_path();
- selected_paths.push_back(path);
+ if (EditorContextMenuPluginManager::get_singleton()->has_plugins_for_slot(EditorContextMenuPlugin::CONTEXT_SLOT_SCRIPT_EDITOR)) {
+ Ref<Resource> current_resource;
+ String res_path;
+ ScriptEditorBase *seb = Object::cast_to<ScriptEditorBase>(script_editor->tab_container->get_tab_control(selected));
+ if (seb) {
+ current_resource = seb->get_edited_resource();
+ if (current_resource.is_valid()) {
+ res_path = current_resource->get_path();
+ }
}
+
+ EditorContextMenuPlugin::OptionsData context_data;
+ context_data["selected_resource"] = current_resource;
+ context_data["resource_path"] = res_path;
+ EditorContextMenuPluginManager::get_singleton()->add_options_from_plugins(context_menu, EditorContextMenuPlugin::CONTEXT_SLOT_SCRIPT_EDITOR, context_data);
+
+#ifndef DISABLE_DEPRECATED
+ Vector<String> selected_paths;
+ if (current_resource.is_valid()) {
+ selected_paths.push_back(current_resource->get_path());
+ }
+ EditorContextMenuPluginManager::get_singleton()->add_options_from_plugins(context_menu, EditorContextMenuPlugin::CONTEXT_SLOT_SCRIPT_EDITOR, selected_paths, current_resource, 500);
+#endif
}
- EditorContextMenuPluginManager::get_singleton()->add_options_from_plugins(context_menu, EditorContextMenuPlugin::CONTEXT_SLOT_SCRIPT_EDITOR, selected_paths);
context_menu->set_position(get_screen_position() + get_local_mouse_position());
context_menu->reset_size();
@@ -1791,11 +1805,7 @@ void ScriptEditor::_menu_option(int p_option) {
}
if (p_option >= EditorContextMenuPlugin::BASE_ID) {
- Ref<Resource> resource;
- if (seb) {
- resource = seb->get_edited_resource();
- }
- EditorContextMenuPluginManager::get_singleton()->activate_custom_option(EditorContextMenuPlugin::CONTEXT_SLOT_SCRIPT_EDITOR, p_option, resource);
+ EditorContextMenuPluginManager::get_singleton()->activate_custom_option(EditorContextMenuPlugin::CONTEXT_SLOT_SCRIPT_EDITOR, p_option);
return;
}
@@ -3162,11 +3172,25 @@ void ScriptEditor::shortcut_input(const Ref<InputEvent> &p_event) {
const Callable custom_callback = EditorContextMenuPluginManager::get_singleton()->match_custom_shortcut(EditorContextMenuPlugin::CONTEXT_SLOT_SCRIPT_EDITOR, p_event);
if (custom_callback.is_valid()) {
- Ref<Resource> resource;
+ Ref<Resource> current_resource;
if (ScriptEditorBase *current = _get_current_editor()) {
- resource = current->get_edited_resource();
+ current_resource = current->get_edited_resource();
+ }
+
+#ifndef DISABLE_DEPRECATED
+ if (p_event->get_meta("_legacy_shortcut", false)) {
+ Ref<Script> current_script = current_resource;
+ EditorContextMenuPluginManager::get_singleton()->invoke_callback(custom_callback, current_script);
+ accept_event();
+ return;
}
- EditorContextMenuPluginManager::get_singleton()->invoke_callback(custom_callback, resource);
+#endif
+
+ EditorContextMenuPlugin::OptionsData context_data;
+ context_data["selected_resource"] = current_resource;
+ context_data["resource_path"] = current_resource.is_valid() ? current_resource->get_path() : String();
+ EditorContextMenuPluginManager::get_singleton()->invoke_callback(custom_callback, context_data);
+
accept_event();
}
}
diff --git a/editor/script/script_text_editor.cpp b/editor/script/script_text_editor.cpp
index 098b3288072..da39f7be519 100644
--- a/editor/script/script_text_editor.cpp
+++ b/editor/script/script_text_editor.cpp
@@ -1619,13 +1619,24 @@ void ScriptTextEditor::_update_connected_methods() {
}
void ScriptTextEditor::shortcut_input(const Ref<InputEvent> &p_event) {
- if (!p_event->is_pressed() || p_event->is_echo()) {
+ if (!code_editor->is_visible_in_tree() || !p_event->is_pressed() || p_event->is_echo()) {
return;
}
const Callable custom_callback = EditorContextMenuPluginManager::get_singleton()->match_custom_shortcut(EditorContextMenuPlugin::CONTEXT_SLOT_SCRIPT_EDITOR_CODE, p_event);
if (custom_callback.is_valid()) {
- EditorContextMenuPluginManager::get_singleton()->invoke_callback(custom_callback, code_editor->get_text_editor());
+#ifndef DISABLE_DEPRECATED
+ if (p_event->get_meta("_legacy_shortcut", false)) {
+ EditorContextMenuPluginManager::get_singleton()->invoke_callback(custom_callback, code_editor->get_text_editor());
+ accept_event();
+ return;
+ }
+#endif
+ EditorContextMenuPlugin::OptionsData context_data;
+ context_data["code_edit"] = code_editor->get_text_editor();
+ context_data["file_path"] = get_edited_resource()->get_path();
+
+ EditorContextMenuPluginManager::get_singleton()->invoke_callback(custom_callback, context_data);
accept_event();
}
}
@@ -1807,7 +1818,7 @@ bool ScriptTextEditor::_edit_option(int p_op) {
return true;
}
if (p_op >= EditorContextMenuPlugin::BASE_ID) {
- EditorContextMenuPluginManager::get_singleton()->activate_custom_option(EditorContextMenuPlugin::CONTEXT_SLOT_SCRIPT_EDITOR_CODE, p_op, tx);
+ EditorContextMenuPluginManager::get_singleton()->activate_custom_option(EditorContextMenuPlugin::CONTEXT_SLOT_SCRIPT_EDITOR_CODE, p_op);
}
}
}
@@ -2536,8 +2547,19 @@ void ScriptTextEditor::_make_ste_context_menu(bool p_selection, bool p_color, bo
}
}
- const PackedStringArray paths = { String(code_editor->get_text_editor()->get_path()) };
- EditorContextMenuPluginManager::get_singleton()->add_options_from_plugins(context_menu, EditorContextMenuPlugin::CONTEXT_SLOT_SCRIPT_EDITOR_CODE, paths);
+ if (EditorContextMenuPluginManager::get_singleton()->has_plugins_for_slot(EditorContextMenuPlugin::CONTEXT_SLOT_SCRIPT_EDITOR_CODE)) {
+ EditorContextMenuPlugin::OptionsData context_data;
+ context_data["code_edit"] = code_editor->get_text_editor();
+ context_data["file_path"] = get_edited_resource()->get_path();
+
+ EditorContextMenuPluginManager::get_singleton()->add_options_from_plugins(context_menu, EditorContextMenuPlugin::CONTEXT_SLOT_SCRIPT_EDITOR_CODE, context_data);
+
+#ifndef DISABLE_DEPRECATED
+ const PackedStringArray paths = { String(code_editor->get_text_editor()->get_path()) };
+ Ref<Script> edited_script = get_edited_resource();
+ EditorContextMenuPluginManager::get_singleton()->add_options_from_plugins(context_menu, EditorContextMenuPlugin::CONTEXT_SLOT_SCRIPT_EDITOR_CODE, paths, code_editor->get_text_editor(), 500);
+#endif
+ }
_show_context_menu(p_position);
}