mirror of
https://github.com/godotengine/godot.git
synced 2025-10-19 16:03:29 +00:00
Merge pull request #96539 from KoBeWi/feat_context_menu_plugin4.x_2-electric_boogaloo
Add EditorContextMenuPluginManager and refactor menu plugins
This commit is contained in:
commit
a4e77d94bc
13 changed files with 288 additions and 252 deletions
|
@ -215,11 +215,12 @@ void SceneTreeDock::shortcut_input(const Ref<InputEvent> &p_event) {
|
|||
} else if (ED_IS_SHORTCUT("scene_tree/delete", p_event)) {
|
||||
_tool_selected(TOOL_ERASE);
|
||||
} else {
|
||||
int match_option = EditorNode::get_editor_data().match_context_menu_shortcut(EditorData::CONTEXT_SLOT_SCENE_TREE, p_event);
|
||||
if (match_option) {
|
||||
_tool_selected(match_option);
|
||||
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());
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Tool selection was successful, accept the event to stop propagation.
|
||||
|
@ -1492,10 +1493,8 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
|
|||
} break;
|
||||
|
||||
default: {
|
||||
// Editor context plugin.
|
||||
if (p_tool >= EditorData::CONTEXT_MENU_ITEM_ID_BASE) {
|
||||
List<Node *> selection = editor_selection->get_selected_node_list();
|
||||
EditorNode::get_editor_data().scene_tree_options_pressed(EditorData::CONTEXT_SLOT_SCENE_TREE, p_tool, selection);
|
||||
if (p_tool >= EditorContextMenuPlugin::BASE_ID) {
|
||||
EditorContextMenuPluginManager::get_singleton()->activate_custom_option(EditorContextMenuPlugin::CONTEXT_SLOT_SCENE_TREE, p_tool, _get_selection_array());
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -3367,6 +3366,18 @@ void SceneTreeDock::_normalize_drop(Node *&to_node, int &to_pos, int p_type) {
|
|||
}
|
||||
}
|
||||
|
||||
Array SceneTreeDock::_get_selection_array() {
|
||||
List<Node *> selection = editor_selection->get_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);
|
||||
|
@ -3767,7 +3778,7 @@ void SceneTreeDock::_tree_rmb(const Vector2 &p_menu_pos) {
|
|||
String node_path = root->get_path().rel_path_to(E->get()->get_path());
|
||||
p_paths.push_back(node_path);
|
||||
}
|
||||
EditorNode::get_editor_data().add_options_from_plugins(menu, EditorData::CONTEXT_SLOT_SCENE_TREE, p_paths);
|
||||
EditorContextMenuPluginManager::get_singleton()->add_options_from_plugins(menu, EditorContextMenuPlugin::CONTEXT_SLOT_SCENE_TREE, p_paths);
|
||||
|
||||
menu->reset_size();
|
||||
menu->set_position(p_menu_pos);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue