summaryrefslogtreecommitdiff
path: root/editor/property_selector.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'editor/property_selector.cpp')
-rw-r--r--editor/property_selector.cpp259
1 files changed, 125 insertions, 134 deletions
diff --git a/editor/property_selector.cpp b/editor/property_selector.cpp
index 426ec51e4c..27b11e4fb5 100644
--- a/editor/property_selector.cpp
+++ b/editor/property_selector.cpp
@@ -35,28 +35,25 @@
#include "editor_scale.h"
void PropertySelector::_text_changed(const String &p_newtext) {
-
_update_search();
}
void PropertySelector::_sbox_input(const Ref<InputEvent> &p_ie) {
-
Ref<InputEventKey> k = p_ie;
if (k.is_valid()) {
-
- switch (k->get_scancode()) {
+ switch (k->get_keycode()) {
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())
+ if (!root->get_children()) {
break;
+ }
TreeItem *current = search_options->get_selected();
@@ -74,36 +71,36 @@ void PropertySelector::_sbox_input(const Ref<InputEvent> &p_ie) {
}
void PropertySelector::_update_search() {
-
- if (properties)
+ if (properties) {
set_title(TTR("Select Property"));
- else if (virtuals_only)
+ } else if (virtuals_only) {
set_title(TTR("Select Virtual Method"));
- else
+ } else {
set_title(TTR("Select Method"));
+ }
search_options->clear();
help_bit->set_text("");
TreeItem *root = search_options->create_item();
- if (properties) {
+ // 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;
if (instance) {
instance->get_property_list(&props, true);
} else if (type != Variant::NIL) {
Variant v;
- Variant::CallError ce;
- v = Variant::construct(type, NULL, 0, ce);
+ Callable::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<Script>(obj)) {
-
props.push_back(PropertyInfo(Variant::NIL, "Script Variables", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_CATEGORY));
Object::cast_to<Script>(obj)->get_script_property_list(&props);
}
@@ -116,52 +113,52 @@ void PropertySelector::_update_search() {
}
}
- TreeItem *category = NULL;
+ TreeItem *category = nullptr;
bool found = false;
- Ref<Texture> type_icons[Variant::VARIANT_MAX] = {
- Control::get_icon("Variant", "EditorIcons"),
- Control::get_icon("bool", "EditorIcons"),
- Control::get_icon("int", "EditorIcons"),
- Control::get_icon("float", "EditorIcons"),
- Control::get_icon("String", "EditorIcons"),
- Control::get_icon("Vector2", "EditorIcons"),
- Control::get_icon("Rect2", "EditorIcons"),
- Control::get_icon("Vector3", "EditorIcons"),
- Control::get_icon("Transform2D", "EditorIcons"),
- Control::get_icon("Plane", "EditorIcons"),
- Control::get_icon("Quat", "EditorIcons"),
- Control::get_icon("AABB", "EditorIcons"),
- Control::get_icon("Basis", "EditorIcons"),
- Control::get_icon("Transform", "EditorIcons"),
- Control::get_icon("Color", "EditorIcons"),
- Control::get_icon("Path", "EditorIcons"),
- Control::get_icon("RID", "EditorIcons"),
- Control::get_icon("Object", "EditorIcons"),
- Control::get_icon("Dictionary", "EditorIcons"),
- Control::get_icon("Array", "EditorIcons"),
- Control::get_icon("PoolByteArray", "EditorIcons"),
- Control::get_icon("PoolIntArray", "EditorIcons"),
- Control::get_icon("PoolRealArray", "EditorIcons"),
- Control::get_icon("PoolStringArray", "EditorIcons"),
- Control::get_icon("PoolVector2Array", "EditorIcons"),
- Control::get_icon("PoolVector3Array", "EditorIcons"),
- Control::get_icon("PoolColorArray", "EditorIcons")
+ Ref<Texture2D> type_icons[Variant::VARIANT_MAX] = {
+ search_options->get_theme_icon("Variant", "EditorIcons"),
+ search_options->get_theme_icon("bool", "EditorIcons"),
+ search_options->get_theme_icon("int", "EditorIcons"),
+ 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("Rect2", "EditorIcons"),
+ search_options->get_theme_icon("Vector3", "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("AABB", "EditorIcons"),
+ search_options->get_theme_icon("Basis", "EditorIcons"),
+ search_options->get_theme_icon("Transform", "EditorIcons"),
+ search_options->get_theme_icon("Color", "EditorIcons"),
+ search_options->get_theme_icon("Path", "EditorIcons"),
+ search_options->get_theme_icon("RID", "EditorIcons"),
+ search_options->get_theme_icon("Object", "EditorIcons"),
+ search_options->get_theme_icon("Dictionary", "EditorIcons"),
+ search_options->get_theme_icon("Array", "EditorIcons"),
+ search_options->get_theme_icon("PackedByteArray", "EditorIcons"),
+ search_options->get_theme_icon("PackedInt32Array", "EditorIcons"),
+ search_options->get_theme_icon("PackedFloat32Array", "EditorIcons"),
+ search_options->get_theme_icon("PackedStringArray", "EditorIcons"),
+ search_options->get_theme_icon("PackedVector2Array", "EditorIcons"),
+ search_options->get_theme_icon("PackedVector3Array", "EditorIcons"),
+ search_options->get_theme_icon("PackedColorArray", "EditorIcons")
};
for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) {
if (E->get().usage == PROPERTY_USAGE_CATEGORY) {
- if (category && category->get_children() == NULL) {
+ if (category && category->get_children() == nullptr) {
memdelete(category); //old category was unused
}
category = search_options->create_item(root);
category->set_text(0, E->get().name);
category->set_selectable(0, false);
- Ref<Texture> icon;
+ Ref<Texture2D> icon;
if (E->get().name == "Script Variables") {
- icon = get_icon("Script", "EditorIcons");
+ icon = search_options->get_theme_icon("Script", "EditorIcons");
} else {
icon = EditorNode::get_singleton()->get_class_icon(E->get().name);
}
@@ -169,21 +166,24 @@ void PropertySelector::_update_search() {
continue;
}
- if (!(E->get().usage & PROPERTY_USAGE_EDITOR) && !(E->get().usage & PROPERTY_USAGE_SCRIPT_VARIABLE))
+ if (!(E->get().usage & PROPERTY_USAGE_EDITOR) && !(E->get().usage & PROPERTY_USAGE_SCRIPT_VARIABLE)) {
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;
+ }
- if (type_filter.size() && type_filter.find(E->get().type) == -1)
+ if (type_filter.size() && type_filter.find(E->get().type) == -1) {
continue;
+ }
TreeItem *item = search_options->create_item(category ? category : root);
item->set_text(0, E->get().name);
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;
}
@@ -191,23 +191,20 @@ void PropertySelector::_update_search() {
item->set_selectable(0, true);
}
- if (category && category->get_children() == NULL) {
+ if (category && category->get_children() == nullptr) {
memdelete(category); //old category was unused
}
} else {
-
List<MethodInfo> methods;
if (type != Variant::NIL) {
Variant v;
- Variant::CallError ce;
- v = Variant::construct(type, NULL, 0, ce);
+ Callable::CallError ce;
+ v = Variant::construct(type, nullptr, 0, ce);
v.get_method_list(&methods);
} else {
-
Object *obj = ObjectDB::get_instance(script);
if (Object::cast_to<Script>(obj)) {
-
methods.push_back(MethodInfo("*Script Methods"));
Object::cast_to<Script>(obj)->get_script_method_list(&methods);
}
@@ -220,25 +217,25 @@ void PropertySelector::_update_search() {
}
}
- TreeItem *category = NULL;
+ TreeItem *category = nullptr;
bool found = false;
bool script_methods = false;
for (List<MethodInfo>::Element *E = methods.front(); E; E = E->next()) {
if (E->get().name.begins_with("*")) {
- if (category && category->get_children() == NULL) {
+ if (category && category->get_children() == nullptr) {
memdelete(category); //old category was unused
}
category = search_options->create_item(root);
category->set_text(0, E->get().name.replace_first("*", ""));
category->set_selectable(0, false);
- Ref<Texture> icon;
+ Ref<Texture2D> icon;
script_methods = false;
String rep = E->get().name.replace("*", "");
if (E->get().name == "*Script Methods") {
- icon = get_icon("Script", "EditorIcons");
+ icon = search_options->get_theme_icon("Script", "EditorIcons");
script_methods = true;
} else {
icon = EditorNode::get_singleton()->get_class_icon(rep);
@@ -249,17 +246,21 @@ void PropertySelector::_update_search() {
}
String name = E->get().name.get_slice(":", 0);
- if (!script_methods && name.begins_with("_") && !(E->get().flags & METHOD_FLAG_VIRTUAL))
+ if (!script_methods && name.begins_with("_") && !(E->get().flags & METHOD_FLAG_VIRTUAL)) {
continue;
+ }
- if (virtuals_only && !(E->get().flags & METHOD_FLAG_VIRTUAL))
+ if (virtuals_only && !(E->get().flags & METHOD_FLAG_VIRTUAL)) {
continue;
+ }
- if (!virtuals_only && (E->get().flags & METHOD_FLAG_VIRTUAL))
+ if (!virtuals_only && (E->get().flags & METHOD_FLAG_VIRTUAL)) {
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;
+ }
TreeItem *item = search_options->create_item(category ? category : root);
@@ -269,71 +270,75 @@ void PropertySelector::_update_search() {
if (mi.name.find(":") != -1) {
desc = mi.name.get_slice(":", 1) + " ";
mi.name = mi.name.get_slice(":", 0);
- } else if (mi.return_val.type != Variant::NIL)
+ } else if (mi.return_val.type != Variant::NIL) {
desc = Variant::get_type_name(mi.return_val.type);
- else
- desc = "void ";
+ } else {
+ desc = "void";
+ }
- desc += " " + mi.name + " ( ";
+ desc += vformat(" %s(", mi.name);
for (int i = 0; i < mi.arguments.size(); i++) {
-
- if (i > 0)
+ if (i > 0) {
desc += ", ";
-
- if (mi.arguments[i].type == Variant::NIL)
- desc += "var ";
- else if (mi.arguments[i].name.find(":") != -1) {
- desc += 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 += mi.arguments[i].name;
+
+ if (mi.arguments[i].type == Variant::NIL) {
+ desc += ": Variant";
+ } else if (mi.arguments[i].name.find(":") != -1) {
+ desc += vformat(": %s", mi.arguments[i].name.get_slice(":", 1));
+ mi.arguments[i].name = mi.arguments[i].name.get_slice(":", 0);
+ } else {
+ desc += vformat(": %s", Variant::get_type_name(mi.arguments[i].type));
+ }
}
- desc += " )";
+ desc += ")";
- if (E->get().flags & METHOD_FLAG_CONST)
+ if (E->get().flags & METHOD_FLAG_CONST) {
desc += " const";
+ }
- if (E->get().flags & METHOD_FLAG_VIRTUAL)
+ if (E->get().flags & METHOD_FLAG_VIRTUAL) {
desc += " virtual";
+ }
item->set_text(0, desc);
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() == NULL) {
+ if (category && category->get_children() == nullptr) {
memdelete(category); //old category was unused
}
}
- get_ok()->set_disabled(root->get_children() == NULL);
+ get_ok()->set_disabled(root->get_children() == nullptr);
}
void PropertySelector::_confirmed() {
-
TreeItem *ti = search_options->get_selected();
- if (!ti)
+ if (!ti) {
return;
+ }
emit_signal("selected", ti->get_metadata(0));
hide();
}
void PropertySelector::_item_selected() {
-
help_bit->set_text("");
TreeItem *item = search_options->get_selected();
- if (!item)
+ if (!item) {
return;
+ }
String name = item->get_metadata(0);
String class_type;
@@ -348,16 +353,14 @@ void PropertySelector::_item_selected() {
String text;
if (properties) {
-
String at_class = class_type;
while (at_class != String()) {
-
Map<String, DocData::ClassDoc>::Element *E = dd->class_list.find(at_class);
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);
}
}
}
@@ -365,16 +368,14 @@ void PropertySelector::_item_selected() {
at_class = ClassDB::get_parent_class(at_class);
}
} else {
-
String at_class = class_type;
while (at_class != String()) {
-
Map<String, DocData::ClassDoc>::Element *E = dd->class_list.find(at_class);
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);
}
}
}
@@ -383,30 +384,32 @@ void PropertySelector::_item_selected() {
}
}
- if (text == String())
+ if (text == String()) {
return;
+ }
help_bit->set_text(text);
}
-void PropertySelector::_notification(int p_what) {
+void PropertySelector::_hide_requested() {
+ _cancel_pressed(); // From AcceptDialog.
+}
+void PropertySelector::_notification(int p_what) {
if (p_what == NOTIFICATION_ENTER_TREE) {
-
- connect("confirmed", this, "_confirmed");
+ connect("confirmed", callable_mp(this, &PropertySelector::_confirmed));
} else if (p_what == NOTIFICATION_EXIT_TREE) {
- disconnect("confirmed", this, "_confirmed");
+ disconnect("confirmed", callable_mp(this, &PropertySelector::_confirmed));
}
}
void PropertySelector::select_method_from_base_type(const String &p_base, const String &p_current, bool p_virtuals_only) {
-
base_type = p_base;
selected = p_current;
type = Variant::NIL;
- script = 0;
+ script = ObjectID();
properties = false;
- instance = NULL;
+ instance = nullptr;
virtuals_only = p_virtuals_only;
popup_centered_ratio(0.6);
@@ -416,14 +419,13 @@ void PropertySelector::select_method_from_base_type(const String &p_base, const
}
void PropertySelector::select_method_from_script(const Ref<Script> &p_script, const String &p_current) {
-
ERR_FAIL_COND(p_script.is_null());
base_type = p_script->get_instance_base_type();
selected = p_current;
type = Variant::NIL;
script = p_script->get_instance_id();
properties = false;
- instance = NULL;
+ instance = nullptr;
virtuals_only = false;
popup_centered_ratio(0.6);
@@ -431,15 +433,15 @@ void PropertySelector::select_method_from_script(const Ref<Script> &p_script, co
search_box->grab_focus();
_update_search();
}
-void PropertySelector::select_method_from_basic_type(Variant::Type p_type, const String &p_current) {
+void PropertySelector::select_method_from_basic_type(Variant::Type p_type, const String &p_current) {
ERR_FAIL_COND(p_type == Variant::NIL);
base_type = "";
selected = p_current;
type = p_type;
- script = 0;
+ script = ObjectID();
properties = false;
- instance = NULL;
+ instance = nullptr;
virtuals_only = false;
popup_centered_ratio(0.6);
@@ -449,18 +451,18 @@ void PropertySelector::select_method_from_basic_type(Variant::Type p_type, const
}
void PropertySelector::select_method_from_instance(Object *p_instance, const String &p_current) {
-
base_type = p_instance->get_class();
selected = p_current;
type = Variant::NIL;
- script = 0;
+ script = ObjectID();
{
Ref<Script> scr = p_instance->get_script();
- if (scr.is_valid())
+ if (scr.is_valid()) {
script = scr->get_instance_id();
+ }
}
properties = false;
- instance = NULL;
+ instance = nullptr;
virtuals_only = false;
popup_centered_ratio(0.6);
@@ -470,13 +472,12 @@ void PropertySelector::select_method_from_instance(Object *p_instance, const Str
}
void PropertySelector::select_property_from_base_type(const String &p_base, const String &p_current) {
-
base_type = p_base;
selected = p_current;
type = Variant::NIL;
- script = 0;
+ script = ObjectID();
properties = true;
- instance = NULL;
+ instance = nullptr;
virtuals_only = false;
popup_centered_ratio(0.6);
@@ -486,7 +487,6 @@ void PropertySelector::select_property_from_base_type(const String &p_base, cons
}
void PropertySelector::select_property_from_script(const Ref<Script> &p_script, const String &p_current) {
-
ERR_FAIL_COND(p_script.is_null());
base_type = p_script->get_instance_base_type();
@@ -494,7 +494,7 @@ void PropertySelector::select_property_from_script(const Ref<Script> &p_script,
type = Variant::NIL;
script = p_script->get_instance_id();
properties = true;
- instance = NULL;
+ instance = nullptr;
virtuals_only = false;
popup_centered_ratio(0.6);
@@ -504,14 +504,13 @@ void PropertySelector::select_property_from_script(const Ref<Script> &p_script,
}
void PropertySelector::select_property_from_basic_type(Variant::Type p_type, const String &p_current) {
-
ERR_FAIL_COND(p_type == Variant::NIL);
base_type = "";
selected = p_current;
type = p_type;
- script = 0;
+ script = ObjectID();
properties = true;
- instance = NULL;
+ instance = nullptr;
virtuals_only = false;
popup_centered_ratio(0.6);
@@ -521,11 +520,10 @@ void PropertySelector::select_property_from_basic_type(Variant::Type p_type, con
}
void PropertySelector::select_property_from_instance(Object *p_instance, const String &p_current) {
-
base_type = "";
selected = p_current;
type = Variant::NIL;
- script = 0;
+ script = ObjectID();
properties = true;
instance = p_instance;
virtuals_only = false;
@@ -541,37 +539,30 @@ void PropertySelector::set_type_filter(const Vector<Variant::Type> &p_type_filte
}
void PropertySelector::_bind_methods() {
-
- ClassDB::bind_method(D_METHOD("_text_changed"), &PropertySelector::_text_changed);
- ClassDB::bind_method(D_METHOD("_confirmed"), &PropertySelector::_confirmed);
- ClassDB::bind_method(D_METHOD("_sbox_input"), &PropertySelector::_sbox_input);
- ClassDB::bind_method(D_METHOD("_item_selected"), &PropertySelector::_item_selected);
-
ADD_SIGNAL(MethodInfo("selected", PropertyInfo(Variant::STRING, "name")));
}
PropertySelector::PropertySelector() {
-
VBoxContainer *vbc = memnew(VBoxContainer);
add_child(vbc);
//set_child_rect(vbc);
search_box = memnew(LineEdit);
vbc->add_margin_child(TTR("Search:"), search_box);
- search_box->connect("text_changed", this, "_text_changed");
- search_box->connect("gui_input", this, "_sbox_input");
+ search_box->connect("text_changed", callable_mp(this, &PropertySelector::_text_changed));
+ 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);
register_text_enter(search_box);
set_hide_on_ok(false);
- search_options->connect("item_activated", this, "_confirmed");
- search_options->connect("cell_selected", this, "_item_selected");
+ search_options->connect("item_activated", callable_mp(this, &PropertySelector::_confirmed));
+ search_options->connect("cell_selected", callable_mp(this, &PropertySelector::_item_selected));
search_options->set_hide_root(true);
search_options->set_hide_folding(true);
virtuals_only = false;
help_bit = memnew(EditorHelpBit);
vbc->add_margin_child(TTR("Description:"), help_bit);
- help_bit->connect("request_hide", this, "_closed");
+ help_bit->connect("request_hide", callable_mp(this, &PropertySelector::_hide_requested));
}