/*************************************************************************/ /* property_selector.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ /* "Software"), to deal in the Software without restriction, including */ /* without limitation the rights to use, copy, modify, merge, publish, */ /* distribute, sublicense, and/or sell copies of the Software, and to */ /* permit persons to whom the Software is furnished to do so, subject to */ /* the following conditions: */ /* */ /* The above copyright notice and this permission notice shall be */ /* included in all copies or substantial portions of the Software. */ /* */ /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "property_selector.h" #include "core/object/class_db.h" #include "core/math/color.h" #include "core/error_macros.h" #include "core/containers/list.h" #include "core/containers/map.h" #include "core/object/method_bind.h" #include "core/os/input_event.h" #include "core/os/keyboard.h" #include "core/os/memory.h" #include "core/object/script_language.h" #include "core/string_name.h" #include "core/typedefs.h" #include "editor/doc/doc_data.h" #include "editor/editor_help.h" #include "editor/editor_node.h" #include "scene/gui/box_container.h" #include "scene/gui/button.h" #include "scene/gui/control.h" #include "scene/gui/line_edit.h" #include "scene/gui/rich_text_label.h" #include "scene/gui/tree.h" #include "scene/main/node.h" #include "scene/resources/texture.h" void PropertySelector::_text_changed(const String &p_newtext) { _update_search(); } void PropertySelector::_sbox_input(const Ref &p_ie) { Ref k = p_ie; if (k.is_valid()) { switch (k->get_scancode()) { case KEY_UP: case KEY_DOWN: case KEY_PAGEUP: case KEY_PAGEDOWN: { search_options->call("_gui_input", k); search_box->accept_event(); TreeItem *root = search_options->get_root(); if (!root->get_children()) { break; } TreeItem *current = search_options->get_selected(); TreeItem *item = search_options->get_next_selected(root); while (item) { item->deselect(0); item = search_options->get_next_selected(item); } current->select(0); } break; } } } void PropertySelector::_update_search() { if (properties) { set_title(TTR("Select Property")); } else if (virtuals_only) { set_title(TTR("Select Virtual Method")); } else { set_title(TTR("Select Method")); } search_options->clear(); help_bit->set_text(""); TreeItem *root = search_options->create_item(); // Allow using spaces in place of underscores in the search string (makes the search more fault-tolerant). const String search_text = search_box->get_text().replace(" ", "_"); if (properties) { List props; if (instance) { instance->get_property_list(&props, true); } else if (type != Variant::NIL) { Variant v; Variant::CallError ce; v = Variant::construct(type, nullptr, 0, ce); v.get_property_list(&props); } else { Object *obj = ObjectDB::get_instance(script); if (Object::cast_to