diff options
Diffstat (limited to 'editor/property_selector.cpp')
-rw-r--r-- | editor/property_selector.cpp | 71 |
1 files changed, 40 insertions, 31 deletions
diff --git a/editor/property_selector.cpp b/editor/property_selector.cpp index 6888ebdc71..00652c02c8 100644 --- a/editor/property_selector.cpp +++ b/editor/property_selector.cpp @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2021 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 */ @@ -31,6 +31,7 @@ #include "property_selector.h" #include "core/os/keyboard.h" +#include "editor/doc_tools.h" #include "editor/editor_node.h" #include "editor_scale.h" @@ -51,7 +52,7 @@ void PropertySelector::_sbox_input(const Ref<InputEvent> &p_ie) { search_box->accept_event(); TreeItem *root = search_options->get_root(); - if (!root->get_children()) { + if (!root->get_first_child()) { break; } @@ -84,6 +85,9 @@ void PropertySelector::_update_search() { 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<PropertyInfo> props; @@ -92,7 +96,7 @@ void PropertySelector::_update_search() { } else if (type != Variant::NIL) { Variant v; Callable::CallError ce; - v = Variant::construct(type, nullptr, 0, ce); + Variant::construct(type, v, nullptr, 0, ce); v.get_property_list(&props); } else { @@ -121,18 +125,23 @@ void PropertySelector::_update_search() { search_options->get_theme_icon("float", "EditorIcons"), search_options->get_theme_icon("String", "EditorIcons"), search_options->get_theme_icon("Vector2", "EditorIcons"), + search_options->get_theme_icon("Vector2i", "EditorIcons"), search_options->get_theme_icon("Rect2", "EditorIcons"), + search_options->get_theme_icon("Rect2i", "EditorIcons"), search_options->get_theme_icon("Vector3", "EditorIcons"), + search_options->get_theme_icon("Vector3i", "EditorIcons"), search_options->get_theme_icon("Transform2D", "EditorIcons"), search_options->get_theme_icon("Plane", "EditorIcons"), - search_options->get_theme_icon("Quat", "EditorIcons"), + search_options->get_theme_icon("Quaternion", "EditorIcons"), search_options->get_theme_icon("AABB", "EditorIcons"), search_options->get_theme_icon("Basis", "EditorIcons"), - search_options->get_theme_icon("Transform", "EditorIcons"), + search_options->get_theme_icon("Transform3D", "EditorIcons"), search_options->get_theme_icon("Color", "EditorIcons"), - search_options->get_theme_icon("Path", "EditorIcons"), + search_options->get_theme_icon("NodePath", "EditorIcons"), search_options->get_theme_icon("RID", "EditorIcons"), - search_options->get_theme_icon("Object", "EditorIcons"), + search_options->get_theme_icon("MiniObject", "EditorIcons"), + search_options->get_theme_icon("Callable", "EditorIcons"), + search_options->get_theme_icon("Signal", "EditorIcons"), search_options->get_theme_icon("Dictionary", "EditorIcons"), search_options->get_theme_icon("Array", "EditorIcons"), search_options->get_theme_icon("PackedByteArray", "EditorIcons"), @@ -146,7 +155,7 @@ void PropertySelector::_update_search() { for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) { if (E->get().usage == PROPERTY_USAGE_CATEGORY) { - if (category && category->get_children() == nullptr) { + if (category && category->get_first_child() == nullptr) { memdelete(category); //old category was unused } category = search_options->create_item(root); @@ -167,7 +176,7 @@ void PropertySelector::_update_search() { continue; } - if (search_box->get_text() != String() && E->get().name.find(search_box->get_text()) == -1) { + if (search_box->get_text() != String() && E->get().name.findn(search_text) == -1) { continue; } @@ -180,7 +189,7 @@ void PropertySelector::_update_search() { item->set_metadata(0, E->get().name); item->set_icon(0, type_icons[E->get().type]); - if (!found && search_box->get_text() != String() && E->get().name.find(search_box->get_text()) != -1) { + if (!found && search_box->get_text() != String() && E->get().name.findn(search_text) != -1) { item->select(0); found = true; } @@ -188,7 +197,7 @@ void PropertySelector::_update_search() { item->set_selectable(0, true); } - if (category && category->get_children() == nullptr) { + if (category && category->get_first_child() == nullptr) { memdelete(category); //old category was unused } } else { @@ -197,7 +206,7 @@ void PropertySelector::_update_search() { if (type != Variant::NIL) { Variant v; Callable::CallError ce; - v = Variant::construct(type, nullptr, 0, ce); + Variant::construct(type, v, nullptr, 0, ce); v.get_method_list(&methods); } else { Object *obj = ObjectDB::get_instance(script); @@ -221,7 +230,7 @@ void PropertySelector::_update_search() { for (List<MethodInfo>::Element *E = methods.front(); E; E = E->next()) { if (E->get().name.begins_with("*")) { - if (category && category->get_children() == nullptr) { + if (category && category->get_first_child() == nullptr) { memdelete(category); //old category was unused } category = search_options->create_item(root); @@ -255,7 +264,7 @@ void PropertySelector::_update_search() { continue; } - if (search_box->get_text() != String() && name.find(search_box->get_text()) == -1) { + if (search_box->get_text() != String() && name.findn(search_text) == -1) { continue; } @@ -270,29 +279,29 @@ void PropertySelector::_update_search() { } else if (mi.return_val.type != Variant::NIL) { desc = Variant::get_type_name(mi.return_val.type); } else { - desc = "void "; + desc = "void"; } - desc += " " + mi.name + " ( "; + desc += vformat(" %s(", mi.name); for (int i = 0; i < mi.arguments.size(); i++) { if (i > 0) { desc += ", "; } + desc += mi.arguments[i].name; + if (mi.arguments[i].type == Variant::NIL) { - desc += "var "; + desc += ": Variant"; } else if (mi.arguments[i].name.find(":") != -1) { - desc += mi.arguments[i].name.get_slice(":", 1) + " "; + desc += vformat(": %s", mi.arguments[i].name.get_slice(":", 1)); mi.arguments[i].name = mi.arguments[i].name.get_slice(":", 0); } else { - desc += Variant::get_type_name(mi.arguments[i].type) + " "; + desc += vformat(": %s", Variant::get_type_name(mi.arguments[i].type)); } - - desc += mi.arguments[i].name; } - desc += " )"; + desc += ")"; if (E->get().flags & METHOD_FLAG_CONST) { desc += " const"; @@ -306,18 +315,18 @@ void PropertySelector::_update_search() { item->set_metadata(0, name); item->set_selectable(0, true); - if (!found && search_box->get_text() != String() && name.find(search_box->get_text()) != -1) { + if (!found && search_box->get_text() != String() && name.findn(search_text) != -1) { item->select(0); found = true; } } - if (category && category->get_children() == nullptr) { + if (category && category->get_first_child() == nullptr) { memdelete(category); //old category was unused } } - get_ok()->set_disabled(root->get_children() == nullptr); + get_ok_button()->set_disabled(root->get_first_child() == nullptr); } void PropertySelector::_confirmed() { @@ -346,7 +355,7 @@ void PropertySelector::_item_selected() { class_type = base_type; } - DocData *dd = EditorHelp::get_doc_data(); + DocTools *dd = EditorHelp::get_doc_data(); String text; if (properties) { @@ -357,7 +366,7 @@ void PropertySelector::_item_selected() { if (E) { for (int i = 0; i < E->get().properties.size(); i++) { if (E->get().properties[i].name == name) { - text = E->get().properties[i].description; + text = DTR(E->get().properties[i].description); } } } @@ -372,7 +381,7 @@ void PropertySelector::_item_selected() { if (E) { for (int i = 0; i < E->get().methods.size(); i++) { if (E->get().methods[i].name == name) { - text = E->get().methods[i].description; + text = DTR(E->get().methods[i].description); } } } @@ -549,8 +558,8 @@ PropertySelector::PropertySelector() { search_box->connect("gui_input", callable_mp(this, &PropertySelector::_sbox_input)); search_options = memnew(Tree); vbc->add_margin_child(TTR("Matches:"), search_options, true); - get_ok()->set_text(TTR("Open")); - get_ok()->set_disabled(true); + get_ok_button()->set_text(TTR("Open")); + get_ok_button()->set_disabled(true); register_text_enter(search_box); set_hide_on_ok(false); search_options->connect("item_activated", callable_mp(this, &PropertySelector::_confirmed)); |