2017-01-16 07:04:19 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* property_selector.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 12:16:55 +00:00
|
|
|
/* https://godotengine.org */
|
2017-01-16 07:04:19 +00:00
|
|
|
/*************************************************************************/
|
2020-01-01 10:16:22 +00:00
|
|
|
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
|
2017-01-16 07:04:19 +00:00
|
|
|
/* */
|
|
|
|
/* 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. */
|
|
|
|
/*************************************************************************/
|
2018-01-04 23:50:27 +00:00
|
|
|
|
2016-08-23 22:29:07 +00:00
|
|
|
#include "property_selector.h"
|
|
|
|
|
2018-09-11 16:13:45 +00:00
|
|
|
#include "core/os/keyboard.h"
|
2018-09-02 21:40:51 +00:00
|
|
|
#include "editor/editor_node.h"
|
2017-01-16 07:04:19 +00:00
|
|
|
#include "editor_scale.h"
|
2016-08-23 22:29:07 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void PropertySelector::_text_changed(const String &p_newtext) {
|
2016-08-23 22:29:07 +00:00
|
|
|
_update_search();
|
|
|
|
}
|
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
void PropertySelector::_sbox_input(const Ref<InputEvent> &p_ie) {
|
|
|
|
Ref<InputEventKey> k = p_ie;
|
2016-08-23 22:29:07 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (k.is_valid()) {
|
2018-04-05 17:59:35 +00:00
|
|
|
switch (k->get_keycode()) {
|
2016-08-23 22:29:07 +00:00
|
|
|
case KEY_UP:
|
|
|
|
case KEY_DOWN:
|
|
|
|
case KEY_PAGEUP:
|
|
|
|
case KEY_PAGEDOWN: {
|
2017-05-20 15:38:03 +00:00
|
|
|
search_options->call("_gui_input", k);
|
2016-08-23 22:29:07 +00:00
|
|
|
search_box->accept_event();
|
|
|
|
|
|
|
|
TreeItem *root = search_options->get_root();
|
2020-05-14 14:41:43 +00:00
|
|
|
if (!root->get_children()) {
|
2016-08-23 22:29:07 +00:00
|
|
|
break;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2016-08-23 22:29:07 +00:00
|
|
|
|
|
|
|
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() {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (properties) {
|
2016-08-23 22:29:07 +00:00
|
|
|
set_title(TTR("Select Property"));
|
2020-05-14 14:41:43 +00:00
|
|
|
} else if (virtuals_only) {
|
2017-09-12 10:58:18 +00:00
|
|
|
set_title(TTR("Select Virtual Method"));
|
2020-05-14 14:41:43 +00:00
|
|
|
} else {
|
2016-08-23 22:29:07 +00:00
|
|
|
set_title(TTR("Select Method"));
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2016-08-23 22:29:07 +00:00
|
|
|
|
|
|
|
search_options->clear();
|
2016-08-24 02:15:16 +00:00
|
|
|
help_bit->set_text("");
|
2016-08-23 22:29:07 +00:00
|
|
|
|
|
|
|
TreeItem *root = search_options->create_item();
|
|
|
|
|
|
|
|
if (properties) {
|
|
|
|
List<PropertyInfo> props;
|
|
|
|
|
|
|
|
if (instance) {
|
2017-03-05 15:44:50 +00:00
|
|
|
instance->get_property_list(&props, true);
|
|
|
|
} else if (type != Variant::NIL) {
|
2016-08-23 22:29:07 +00:00
|
|
|
Variant v;
|
2020-02-19 19:27:19 +00:00
|
|
|
Callable::CallError ce;
|
2020-04-01 23:20:12 +00:00
|
|
|
v = Variant::construct(type, nullptr, 0, ce);
|
2016-08-23 22:29:07 +00:00
|
|
|
|
|
|
|
v.get_property_list(&props);
|
|
|
|
} else {
|
|
|
|
Object *obj = ObjectDB::get_instance(script);
|
2017-08-24 20:58:51 +00:00
|
|
|
if (Object::cast_to<Script>(obj)) {
|
2017-03-05 15:44:50 +00:00
|
|
|
props.push_back(PropertyInfo(Variant::NIL, "Script Variables", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_CATEGORY));
|
2017-08-24 20:58:51 +00:00
|
|
|
Object::cast_to<Script>(obj)->get_script_property_list(&props);
|
2016-08-23 22:29:07 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
StringName base = base_type;
|
|
|
|
while (base) {
|
|
|
|
props.push_back(PropertyInfo(Variant::NIL, base, PROPERTY_HINT_NONE, "", PROPERTY_USAGE_CATEGORY));
|
|
|
|
ClassDB::get_property_list(base, &props, true);
|
|
|
|
base = ClassDB::get_parent_class(base);
|
2016-08-23 22:29:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-01 23:20:12 +00:00
|
|
|
TreeItem *category = nullptr;
|
2017-03-05 15:44:50 +00:00
|
|
|
|
|
|
|
bool found = false;
|
|
|
|
|
2019-06-11 18:43:37 +00:00
|
|
|
Ref<Texture2D> type_icons[Variant::VARIANT_MAX] = {
|
2020-03-12 12:37:40 +00:00
|
|
|
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")
|
2016-08-23 22:29:07 +00:00
|
|
|
};
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) {
|
|
|
|
if (E->get().usage == PROPERTY_USAGE_CATEGORY) {
|
2020-04-01 23:20:12 +00:00
|
|
|
if (category && category->get_children() == nullptr) {
|
2016-08-23 22:29:07 +00:00
|
|
|
memdelete(category); //old category was unused
|
|
|
|
}
|
|
|
|
category = search_options->create_item(root);
|
2017-03-05 15:44:50 +00:00
|
|
|
category->set_text(0, E->get().name);
|
|
|
|
category->set_selectable(0, false);
|
2016-08-23 22:29:07 +00:00
|
|
|
|
2019-06-11 18:43:37 +00:00
|
|
|
Ref<Texture2D> icon;
|
2017-03-05 15:44:50 +00:00
|
|
|
if (E->get().name == "Script Variables") {
|
2020-03-12 12:37:40 +00:00
|
|
|
icon = search_options->get_theme_icon("Script", "EditorIcons");
|
2016-08-23 22:29:07 +00:00
|
|
|
} else {
|
2018-09-02 21:40:51 +00:00
|
|
|
icon = EditorNode::get_singleton()->get_class_icon(E->get().name);
|
2016-08-23 22:29:07 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
category->set_icon(0, icon);
|
2016-08-23 22:29:07 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-05-14 14:41:43 +00:00
|
|
|
if (!(E->get().usage & PROPERTY_USAGE_EDITOR) && !(E->get().usage & PROPERTY_USAGE_SCRIPT_VARIABLE)) {
|
2016-08-23 22:29:07 +00:00
|
|
|
continue;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2016-08-23 22:29:07 +00:00
|
|
|
|
2020-05-14 14:41:43 +00:00
|
|
|
if (search_box->get_text() != String() && E->get().name.find(search_box->get_text()) == -1) {
|
2016-08-23 22:29:07 +00:00
|
|
|
continue;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2018-06-07 15:46:14 +00:00
|
|
|
|
2020-05-14 14:41:43 +00:00
|
|
|
if (type_filter.size() && type_filter.find(E->get().type) == -1) {
|
2018-06-07 15:46:14 +00:00
|
|
|
continue;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2018-06-07 15:46:14 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
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]);
|
2016-08-23 22:29:07 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (!found && search_box->get_text() != String() && E->get().name.find(search_box->get_text()) != -1) {
|
2016-08-23 22:29:07 +00:00
|
|
|
item->select(0);
|
2017-03-05 15:44:50 +00:00
|
|
|
found = true;
|
2016-08-23 22:29:07 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
item->set_selectable(0, true);
|
2016-08-23 22:29:07 +00:00
|
|
|
}
|
|
|
|
|
2020-04-01 23:20:12 +00:00
|
|
|
if (category && category->get_children() == nullptr) {
|
2016-08-23 22:29:07 +00:00
|
|
|
memdelete(category); //old category was unused
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
List<MethodInfo> methods;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (type != Variant::NIL) {
|
2016-08-23 22:29:07 +00:00
|
|
|
Variant v;
|
2020-02-19 19:27:19 +00:00
|
|
|
Callable::CallError ce;
|
2020-04-01 23:20:12 +00:00
|
|
|
v = Variant::construct(type, nullptr, 0, ce);
|
2016-08-23 22:29:07 +00:00
|
|
|
v.get_method_list(&methods);
|
|
|
|
} else {
|
|
|
|
Object *obj = ObjectDB::get_instance(script);
|
2017-08-24 20:58:51 +00:00
|
|
|
if (Object::cast_to<Script>(obj)) {
|
2016-08-23 22:29:07 +00:00
|
|
|
methods.push_back(MethodInfo("*Script Methods"));
|
2017-08-24 20:58:51 +00:00
|
|
|
Object::cast_to<Script>(obj)->get_script_method_list(&methods);
|
2016-08-23 22:29:07 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
StringName base = base_type;
|
|
|
|
while (base) {
|
|
|
|
methods.push_back(MethodInfo("*" + String(base)));
|
2017-09-12 10:58:18 +00:00
|
|
|
ClassDB::get_method_list(base, &methods, true, true);
|
2017-03-05 15:44:50 +00:00
|
|
|
base = ClassDB::get_parent_class(base);
|
2016-08-23 22:29:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-01 23:20:12 +00:00
|
|
|
TreeItem *category = nullptr;
|
2016-08-23 22:29:07 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
bool found = false;
|
|
|
|
bool script_methods = false;
|
2016-08-23 22:29:07 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (List<MethodInfo>::Element *E = methods.front(); E; E = E->next()) {
|
2016-08-23 22:29:07 +00:00
|
|
|
if (E->get().name.begins_with("*")) {
|
2020-04-01 23:20:12 +00:00
|
|
|
if (category && category->get_children() == nullptr) {
|
2016-08-23 22:29:07 +00:00
|
|
|
memdelete(category); //old category was unused
|
|
|
|
}
|
|
|
|
category = search_options->create_item(root);
|
2017-03-05 15:44:50 +00:00
|
|
|
category->set_text(0, E->get().name.replace_first("*", ""));
|
|
|
|
category->set_selectable(0, false);
|
2016-08-23 22:29:07 +00:00
|
|
|
|
2019-06-11 18:43:37 +00:00
|
|
|
Ref<Texture2D> icon;
|
2017-03-05 15:44:50 +00:00
|
|
|
script_methods = false;
|
2017-09-12 10:58:18 +00:00
|
|
|
String rep = E->get().name.replace("*", "");
|
2017-03-05 15:44:50 +00:00
|
|
|
if (E->get().name == "*Script Methods") {
|
2020-03-12 12:37:40 +00:00
|
|
|
icon = search_options->get_theme_icon("Script", "EditorIcons");
|
2017-03-05 15:44:50 +00:00
|
|
|
script_methods = true;
|
2016-08-23 22:29:07 +00:00
|
|
|
} else {
|
2018-09-02 21:40:51 +00:00
|
|
|
icon = EditorNode::get_singleton()->get_class_icon(rep);
|
2016-08-23 22:29:07 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
category->set_icon(0, icon);
|
2016-08-23 22:29:07 +00:00
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
String name = E->get().name.get_slice(":", 0);
|
2020-05-14 14:41:43 +00:00
|
|
|
if (!script_methods && name.begins_with("_") && !(E->get().flags & METHOD_FLAG_VIRTUAL)) {
|
2016-08-23 22:29:07 +00:00
|
|
|
continue;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2016-08-23 22:29:07 +00:00
|
|
|
|
2020-05-14 14:41:43 +00:00
|
|
|
if (virtuals_only && !(E->get().flags & METHOD_FLAG_VIRTUAL)) {
|
2017-09-12 10:58:18 +00:00
|
|
|
continue;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-09-12 10:58:18 +00:00
|
|
|
|
2020-05-14 14:41:43 +00:00
|
|
|
if (!virtuals_only && (E->get().flags & METHOD_FLAG_VIRTUAL)) {
|
2017-09-12 10:58:18 +00:00
|
|
|
continue;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-09-12 10:58:18 +00:00
|
|
|
|
2020-05-14 14:41:43 +00:00
|
|
|
if (search_box->get_text() != String() && name.find(search_box->get_text()) == -1) {
|
2016-08-23 22:29:07 +00:00
|
|
|
continue;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2016-08-23 22:29:07 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
TreeItem *item = search_options->create_item(category ? category : root);
|
2016-08-23 22:29:07 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
MethodInfo mi = E->get();
|
2016-08-23 22:29:07 +00:00
|
|
|
|
|
|
|
String desc;
|
2017-03-05 15:44:50 +00:00
|
|
|
if (mi.name.find(":") != -1) {
|
|
|
|
desc = mi.name.get_slice(":", 1) + " ";
|
|
|
|
mi.name = mi.name.get_slice(":", 0);
|
2020-05-14 14:41:43 +00:00
|
|
|
} else if (mi.return_val.type != Variant::NIL) {
|
2017-03-05 15:44:50 +00:00
|
|
|
desc = Variant::get_type_name(mi.return_val.type);
|
2020-05-14 14:41:43 +00:00
|
|
|
} else {
|
2017-03-05 15:44:50 +00:00
|
|
|
desc = "void ";
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2016-08-23 22:29:07 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
desc += " " + mi.name + " ( ";
|
2016-08-23 22:29:07 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < mi.arguments.size(); i++) {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (i > 0) {
|
2017-03-05 15:44:50 +00:00
|
|
|
desc += ", ";
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2016-08-23 22:29:07 +00:00
|
|
|
|
2020-05-14 14:41:43 +00:00
|
|
|
if (mi.arguments[i].type == Variant::NIL) {
|
2017-03-05 15:44:50 +00:00
|
|
|
desc += "var ";
|
2020-05-14 14:41:43 +00:00
|
|
|
} else if (mi.arguments[i].name.find(":") != -1) {
|
2017-03-05 15:44:50 +00:00
|
|
|
desc += mi.arguments[i].name.get_slice(":", 1) + " ";
|
|
|
|
mi.arguments[i].name = mi.arguments[i].name.get_slice(":", 0);
|
2020-05-14 14:41:43 +00:00
|
|
|
} else {
|
2017-03-05 15:44:50 +00:00
|
|
|
desc += Variant::get_type_name(mi.arguments[i].type) + " ";
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2016-08-23 22:29:07 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
desc += mi.arguments[i].name;
|
2016-08-23 22:29:07 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
desc += " )";
|
2016-08-23 22:29:07 +00:00
|
|
|
|
2020-05-14 14:41:43 +00:00
|
|
|
if (E->get().flags & METHOD_FLAG_CONST) {
|
2017-09-12 10:58:18 +00:00
|
|
|
desc += " const";
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-09-12 10:58:18 +00:00
|
|
|
|
2020-05-14 14:41:43 +00:00
|
|
|
if (E->get().flags & METHOD_FLAG_VIRTUAL) {
|
2017-09-12 10:58:18 +00:00
|
|
|
desc += " virtual";
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-09-12 10:58:18 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
item->set_text(0, desc);
|
|
|
|
item->set_metadata(0, name);
|
|
|
|
item->set_selectable(0, true);
|
2016-08-23 22:29:07 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (!found && search_box->get_text() != String() && name.find(search_box->get_text()) != -1) {
|
2016-08-23 22:29:07 +00:00
|
|
|
item->select(0);
|
2017-03-05 15:44:50 +00:00
|
|
|
found = true;
|
2016-08-23 22:29:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-01 23:20:12 +00:00
|
|
|
if (category && category->get_children() == nullptr) {
|
2016-08-23 22:29:07 +00:00
|
|
|
memdelete(category); //old category was unused
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-01 23:20:12 +00:00
|
|
|
get_ok()->set_disabled(root->get_children() == nullptr);
|
2016-08-23 22:29:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PropertySelector::_confirmed() {
|
|
|
|
TreeItem *ti = search_options->get_selected();
|
2020-05-14 14:41:43 +00:00
|
|
|
if (!ti) {
|
2016-08-23 22:29:07 +00:00
|
|
|
return;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
emit_signal("selected", ti->get_metadata(0));
|
2016-08-23 22:29:07 +00:00
|
|
|
hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PropertySelector::_item_selected() {
|
2016-08-24 02:15:16 +00:00
|
|
|
help_bit->set_text("");
|
2016-08-23 22:29:07 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
TreeItem *item = search_options->get_selected();
|
2020-05-14 14:41:43 +00:00
|
|
|
if (!item) {
|
2016-08-23 22:29:07 +00:00
|
|
|
return;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2016-08-23 22:29:07 +00:00
|
|
|
String name = item->get_metadata(0);
|
|
|
|
|
|
|
|
String class_type;
|
2019-07-20 06:09:57 +00:00
|
|
|
if (type != Variant::NIL) {
|
2017-03-05 15:44:50 +00:00
|
|
|
class_type = Variant::get_type_name(type);
|
2016-08-23 22:29:07 +00:00
|
|
|
|
|
|
|
} else {
|
2017-03-05 15:44:50 +00:00
|
|
|
class_type = base_type;
|
2016-08-23 22:29:07 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
DocData *dd = EditorHelp::get_doc_data();
|
2016-08-23 22:29:07 +00:00
|
|
|
String text;
|
|
|
|
|
|
|
|
if (properties) {
|
2017-03-05 15:44:50 +00:00
|
|
|
String at_class = class_type;
|
2016-08-23 22:29:07 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
while (at_class != String()) {
|
|
|
|
Map<String, DocData::ClassDoc>::Element *E = dd->class_list.find(at_class);
|
2016-08-23 22:29:07 +00:00
|
|
|
if (E) {
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < E->get().properties.size(); i++) {
|
|
|
|
if (E->get().properties[i].name == name) {
|
2020-05-28 10:02:12 +00:00
|
|
|
text = DTR(E->get().properties[i].description);
|
2016-08-23 22:29:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
at_class = ClassDB::get_parent_class(at_class);
|
2016-08-23 22:29:07 +00:00
|
|
|
}
|
|
|
|
} else {
|
2017-03-05 15:44:50 +00:00
|
|
|
String at_class = class_type;
|
2016-08-23 22:29:07 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
while (at_class != String()) {
|
|
|
|
Map<String, DocData::ClassDoc>::Element *E = dd->class_list.find(at_class);
|
2016-08-23 22:29:07 +00:00
|
|
|
if (E) {
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < E->get().methods.size(); i++) {
|
|
|
|
if (E->get().methods[i].name == name) {
|
2020-05-28 10:02:12 +00:00
|
|
|
text = DTR(E->get().methods[i].description);
|
2016-08-23 22:29:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
at_class = ClassDB::get_parent_class(at_class);
|
2016-08-23 22:29:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-14 14:41:43 +00:00
|
|
|
if (text == String()) {
|
2016-08-23 22:29:07 +00:00
|
|
|
return;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2016-08-23 22:29:07 +00:00
|
|
|
|
2016-08-24 02:15:16 +00:00
|
|
|
help_bit->set_text(text);
|
2016-08-23 22:29:07 +00:00
|
|
|
}
|
|
|
|
|
2020-02-27 21:49:16 +00:00
|
|
|
void PropertySelector::_hide_requested() {
|
2020-03-06 17:00:16 +00:00
|
|
|
_cancel_pressed(); // From AcceptDialog.
|
2020-02-27 21:49:16 +00:00
|
|
|
}
|
|
|
|
|
2016-08-23 22:29:07 +00:00
|
|
|
void PropertySelector::_notification(int p_what) {
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_what == NOTIFICATION_ENTER_TREE) {
|
2020-02-21 17:28:45 +00:00
|
|
|
connect("confirmed", callable_mp(this, &PropertySelector::_confirmed));
|
2018-11-05 02:45:25 +00:00
|
|
|
} else if (p_what == NOTIFICATION_EXIT_TREE) {
|
2020-02-21 17:28:45 +00:00
|
|
|
disconnect("confirmed", callable_mp(this, &PropertySelector::_confirmed));
|
2016-08-23 22:29:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-12 10:58:18 +00:00
|
|
|
void PropertySelector::select_method_from_base_type(const String &p_base, const String &p_current, bool p_virtuals_only) {
|
2017-03-05 15:44:50 +00:00
|
|
|
base_type = p_base;
|
|
|
|
selected = p_current;
|
|
|
|
type = Variant::NIL;
|
2020-02-12 17:24:06 +00:00
|
|
|
script = ObjectID();
|
2017-03-05 15:44:50 +00:00
|
|
|
properties = false;
|
2020-04-01 23:20:12 +00:00
|
|
|
instance = nullptr;
|
2017-09-12 10:58:18 +00:00
|
|
|
virtuals_only = p_virtuals_only;
|
2016-08-23 22:29:07 +00:00
|
|
|
|
|
|
|
popup_centered_ratio(0.6);
|
|
|
|
search_box->set_text("");
|
|
|
|
search_box->grab_focus();
|
|
|
|
_update_search();
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
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;
|
2017-08-07 10:17:31 +00:00
|
|
|
script = p_script->get_instance_id();
|
2017-03-05 15:44:50 +00:00
|
|
|
properties = false;
|
2020-04-01 23:20:12 +00:00
|
|
|
instance = nullptr;
|
2017-09-12 10:58:18 +00:00
|
|
|
virtuals_only = false;
|
2016-08-23 22:29:07 +00:00
|
|
|
|
|
|
|
popup_centered_ratio(0.6);
|
|
|
|
search_box->set_text("");
|
|
|
|
search_box->grab_focus();
|
|
|
|
_update_search();
|
|
|
|
}
|
2020-05-14 12:29:06 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
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;
|
2020-02-12 17:24:06 +00:00
|
|
|
script = ObjectID();
|
2017-03-05 15:44:50 +00:00
|
|
|
properties = false;
|
2020-04-01 23:20:12 +00:00
|
|
|
instance = nullptr;
|
2017-09-12 10:58:18 +00:00
|
|
|
virtuals_only = false;
|
2016-08-23 22:29:07 +00:00
|
|
|
|
|
|
|
popup_centered_ratio(0.6);
|
|
|
|
search_box->set_text("");
|
|
|
|
search_box->grab_focus();
|
|
|
|
_update_search();
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
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;
|
2020-02-12 17:24:06 +00:00
|
|
|
script = ObjectID();
|
2016-08-23 22:29:07 +00:00
|
|
|
{
|
|
|
|
Ref<Script> scr = p_instance->get_script();
|
2020-05-14 14:41:43 +00:00
|
|
|
if (scr.is_valid()) {
|
2017-08-07 10:17:31 +00:00
|
|
|
script = scr->get_instance_id();
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2016-08-23 22:29:07 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
properties = false;
|
2020-04-01 23:20:12 +00:00
|
|
|
instance = nullptr;
|
2017-09-12 10:58:18 +00:00
|
|
|
virtuals_only = false;
|
2016-08-23 22:29:07 +00:00
|
|
|
|
|
|
|
popup_centered_ratio(0.6);
|
|
|
|
search_box->set_text("");
|
|
|
|
search_box->grab_focus();
|
|
|
|
_update_search();
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
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;
|
2020-02-12 17:24:06 +00:00
|
|
|
script = ObjectID();
|
2017-03-05 15:44:50 +00:00
|
|
|
properties = true;
|
2020-04-01 23:20:12 +00:00
|
|
|
instance = nullptr;
|
2017-09-12 10:58:18 +00:00
|
|
|
virtuals_only = false;
|
2016-08-23 22:29:07 +00:00
|
|
|
|
|
|
|
popup_centered_ratio(0.6);
|
|
|
|
search_box->set_text("");
|
|
|
|
search_box->grab_focus();
|
|
|
|
_update_search();
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void PropertySelector::select_property_from_script(const Ref<Script> &p_script, const String &p_current) {
|
|
|
|
ERR_FAIL_COND(p_script.is_null());
|
2016-08-25 20:45:20 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
base_type = p_script->get_instance_base_type();
|
|
|
|
selected = p_current;
|
|
|
|
type = Variant::NIL;
|
2017-08-07 10:17:31 +00:00
|
|
|
script = p_script->get_instance_id();
|
2017-03-05 15:44:50 +00:00
|
|
|
properties = true;
|
2020-04-01 23:20:12 +00:00
|
|
|
instance = nullptr;
|
2017-09-12 10:58:18 +00:00
|
|
|
virtuals_only = false;
|
2016-08-23 22:29:07 +00:00
|
|
|
|
|
|
|
popup_centered_ratio(0.6);
|
|
|
|
search_box->set_text("");
|
|
|
|
search_box->grab_focus();
|
|
|
|
_update_search();
|
|
|
|
}
|
2017-12-09 21:07:45 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
void PropertySelector::select_property_from_basic_type(Variant::Type p_type, const String &p_current) {
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_COND(p_type == Variant::NIL);
|
|
|
|
base_type = "";
|
|
|
|
selected = p_current;
|
|
|
|
type = p_type;
|
2020-02-12 17:24:06 +00:00
|
|
|
script = ObjectID();
|
2017-03-05 15:44:50 +00:00
|
|
|
properties = true;
|
2020-04-01 23:20:12 +00:00
|
|
|
instance = nullptr;
|
2017-09-12 10:58:18 +00:00
|
|
|
virtuals_only = false;
|
2016-08-23 22:29:07 +00:00
|
|
|
|
|
|
|
popup_centered_ratio(0.6);
|
|
|
|
search_box->set_text("");
|
|
|
|
search_box->grab_focus();
|
|
|
|
_update_search();
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void PropertySelector::select_property_from_instance(Object *p_instance, const String &p_current) {
|
|
|
|
base_type = "";
|
|
|
|
selected = p_current;
|
|
|
|
type = Variant::NIL;
|
2020-02-12 17:24:06 +00:00
|
|
|
script = ObjectID();
|
2017-03-05 15:44:50 +00:00
|
|
|
properties = true;
|
|
|
|
instance = p_instance;
|
2017-09-12 10:58:18 +00:00
|
|
|
virtuals_only = false;
|
2016-08-23 22:29:07 +00:00
|
|
|
|
|
|
|
popup_centered_ratio(0.6);
|
|
|
|
search_box->set_text("");
|
|
|
|
search_box->grab_focus();
|
|
|
|
_update_search();
|
|
|
|
}
|
|
|
|
|
2018-06-07 15:46:14 +00:00
|
|
|
void PropertySelector::set_type_filter(const Vector<Variant::Type> &p_type_filter) {
|
|
|
|
type_filter = p_type_filter;
|
|
|
|
}
|
|
|
|
|
2016-08-23 22:29:07 +00:00
|
|
|
void PropertySelector::_bind_methods() {
|
2017-03-05 15:44:50 +00:00
|
|
|
ADD_SIGNAL(MethodInfo("selected", PropertyInfo(Variant::STRING, "name")));
|
2016-08-23 22:29:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PropertySelector::PropertySelector() {
|
2017-03-05 15:44:50 +00:00
|
|
|
VBoxContainer *vbc = memnew(VBoxContainer);
|
2016-08-23 22:29:07 +00:00
|
|
|
add_child(vbc);
|
2017-01-10 04:49:55 +00:00
|
|
|
//set_child_rect(vbc);
|
2017-03-05 15:44:50 +00:00
|
|
|
search_box = memnew(LineEdit);
|
|
|
|
vbc->add_margin_child(TTR("Search:"), search_box);
|
2020-02-21 17:28:45 +00:00
|
|
|
search_box->connect("text_changed", callable_mp(this, &PropertySelector::_text_changed));
|
|
|
|
search_box->connect("gui_input", callable_mp(this, &PropertySelector::_sbox_input));
|
2017-03-05 15:44:50 +00:00
|
|
|
search_options = memnew(Tree);
|
|
|
|
vbc->add_margin_child(TTR("Matches:"), search_options, true);
|
2016-08-23 22:29:07 +00:00
|
|
|
get_ok()->set_text(TTR("Open"));
|
|
|
|
get_ok()->set_disabled(true);
|
|
|
|
register_text_enter(search_box);
|
|
|
|
set_hide_on_ok(false);
|
2020-02-21 17:28:45 +00:00
|
|
|
search_options->connect("item_activated", callable_mp(this, &PropertySelector::_confirmed));
|
|
|
|
search_options->connect("cell_selected", callable_mp(this, &PropertySelector::_item_selected));
|
2016-08-23 22:29:07 +00:00
|
|
|
search_options->set_hide_root(true);
|
|
|
|
search_options->set_hide_folding(true);
|
2017-09-12 10:58:18 +00:00
|
|
|
virtuals_only = false;
|
2016-08-23 22:29:07 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
help_bit = memnew(EditorHelpBit);
|
|
|
|
vbc->add_margin_child(TTR("Description:"), help_bit);
|
2020-02-27 21:49:16 +00:00
|
|
|
help_bit->connect("request_hide", callable_mp(this, &PropertySelector::_hide_requested));
|
2016-08-23 22:29:07 +00:00
|
|
|
}
|