diff options
Diffstat (limited to 'editor')
-rw-r--r-- | editor/editor_node.cpp | 22 | ||||
-rw-r--r-- | editor/editor_node.h | 2 | ||||
-rw-r--r-- | editor/editor_plugin.cpp | 6 | ||||
-rw-r--r-- | editor/editor_plugin.h | 2 |
4 files changed, 11 insertions, 21 deletions
diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index fd02d3a8bb..64b5f50b91 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -2743,16 +2743,13 @@ void EditorNode::_tool_menu_option(int p_idx) { } break; case TOOLS_CUSTOM: { if (tool_menu->get_item_submenu(p_idx) == "") { - Array params = tool_menu->get_item_metadata(p_idx); - - Object *handler = ObjectDB::get_instance(params[0]); - String callback = params[1]; - Variant *ud = ¶ms[2]; + Callable callback = tool_menu->get_item_metadata(p_idx); Callable::CallError ce; + Variant result; + callback.call(nullptr, 0, result, ce); - handler->call(callback, (const Variant **)&ud, 1, ce); if (ce.error != Callable::CallError::CALL_OK) { - String err = Variant::get_call_error_text(handler, callback, (const Variant **)&ud, 1, ce); + String err = Variant::get_callable_error_text(callback, nullptr, 0, ce); ERR_PRINT("Error calling function from tool menu: " + err); } } // else it's a submenu so don't do anything. @@ -5086,17 +5083,10 @@ Variant EditorNode::drag_files_and_dirs(const Vector<String> &p_paths, Control * return drag_data; } -void EditorNode::add_tool_menu_item(const String &p_name, Object *p_handler, const String &p_callback, const Variant &p_ud) { - ERR_FAIL_NULL(p_handler); +void EditorNode::add_tool_menu_item(const String &p_name, const Callable &p_callback) { int idx = tool_menu->get_item_count(); tool_menu->add_item(p_name, TOOLS_CUSTOM); - - Array parameters; - parameters.push_back(p_handler->get_instance_id()); - parameters.push_back(p_callback); - parameters.push_back(p_ud); - - tool_menu->set_item_metadata(idx, parameters); + tool_menu->set_item_metadata(idx, p_callback); } void EditorNode::add_tool_submenu_item(const String &p_name, PopupMenu *p_submenu) { diff --git a/editor/editor_node.h b/editor/editor_node.h index 7eec2f265f..ab8d268801 100644 --- a/editor/editor_node.h +++ b/editor/editor_node.h @@ -830,7 +830,7 @@ public: Variant drag_resource(const Ref<Resource> &p_res, Control *p_from); Variant drag_files_and_dirs(const Vector<String> &p_paths, Control *p_from); - void add_tool_menu_item(const String &p_name, Object *p_handler, const String &p_callback, const Variant &p_ud = Variant()); + void add_tool_menu_item(const String &p_name, const Callable &p_callback); void add_tool_submenu_item(const String &p_name, PopupMenu *p_submenu); void remove_tool_menu_item(const String &p_name); diff --git a/editor/editor_plugin.cpp b/editor/editor_plugin.cpp index 49d8e58955..f974ba9998 100644 --- a/editor/editor_plugin.cpp +++ b/editor/editor_plugin.cpp @@ -489,8 +489,8 @@ void EditorPlugin::remove_control_from_container(CustomControlContainer p_locati } } -void EditorPlugin::add_tool_menu_item(const String &p_name, Object *p_handler, const String &p_callback, const Variant &p_ud) { - EditorNode::get_singleton()->add_tool_menu_item(p_name, p_handler, p_callback, p_ud); +void EditorPlugin::add_tool_menu_item(const String &p_name, const Callable &p_callable) { + EditorNode::get_singleton()->add_tool_menu_item(p_name, p_callable); } void EditorPlugin::add_tool_submenu_item(const String &p_name, Object *p_submenu) { @@ -826,7 +826,7 @@ void EditorPlugin::_bind_methods() { ClassDB::bind_method(D_METHOD("remove_control_from_docks", "control"), &EditorPlugin::remove_control_from_docks); ClassDB::bind_method(D_METHOD("remove_control_from_bottom_panel", "control"), &EditorPlugin::remove_control_from_bottom_panel); ClassDB::bind_method(D_METHOD("remove_control_from_container", "container", "control"), &EditorPlugin::remove_control_from_container); - ClassDB::bind_method(D_METHOD("add_tool_menu_item", "name", "handler", "callback", "ud"), &EditorPlugin::add_tool_menu_item, DEFVAL(Variant())); + ClassDB::bind_method(D_METHOD("add_tool_menu_item", "name", "callable"), &EditorPlugin::add_tool_menu_item); ClassDB::bind_method(D_METHOD("add_tool_submenu_item", "name", "submenu"), &EditorPlugin::add_tool_submenu_item); ClassDB::bind_method(D_METHOD("remove_tool_menu_item", "name"), &EditorPlugin::remove_tool_menu_item); ClassDB::bind_method(D_METHOD("add_custom_type", "type", "base", "script", "icon"), &EditorPlugin::add_custom_type); diff --git a/editor/editor_plugin.h b/editor/editor_plugin.h index 11063066d6..03908b43ca 100644 --- a/editor/editor_plugin.h +++ b/editor/editor_plugin.h @@ -174,7 +174,7 @@ public: void remove_control_from_docks(Control *p_control); void remove_control_from_bottom_panel(Control *p_control); - void add_tool_menu_item(const String &p_name, Object *p_handler, const String &p_callback, const Variant &p_ud = Variant()); + void add_tool_menu_item(const String &p_name, const Callable &p_callable); void add_tool_submenu_item(const String &p_name, Object *p_submenu); void remove_tool_menu_item(const String &p_name); |