Fixed a number of issues related to the Dictionary export property for the editor

* Fixed a problem when buttons were deleted on the same frame they were pressed (inside update_property)
* Prevent usage of nul key for a dictionary.
* Provide symetry in the interface for both the array property and dictionary property by first clicking on the field to instantiating the dictionary.
	Array (Nil), Array (size 0), Array (size 1)
	Dictionary (Nil), Array (size 0), Array (size 1)
* Allow to press enter to confirm a string in line edi.
This commit is contained in:
oliperraul 2018-07-23 20:42:31 -04:00
parent aecc3a444b
commit dc2df7a146
3 changed files with 55 additions and 15 deletions

View file

@ -46,11 +46,22 @@ EditorPropertyNil::EditorPropertyNil() {
}
///////////////////// TEXT /////////////////////////
void EditorPropertyText::_text_entered(const String &p_string) {
if (updating)
return;
if (text->has_focus()) {
text->release_focus();
_text_changed(p_string);
}
}
void EditorPropertyText::_text_changed(const String &p_string) {
if (updating)
return;
emit_signal("property_changed", get_edited_property(), p_string, true);
emit_signal("property_changed", get_edited_property(), p_string);
}
void EditorPropertyText::update_property() {
@ -64,6 +75,7 @@ void EditorPropertyText::update_property() {
void EditorPropertyText::_bind_methods() {
ClassDB::bind_method(D_METHOD("_text_changed", "txt"), &EditorPropertyText::_text_changed);
ClassDB::bind_method(D_METHOD("_text_entered", "txt"), &EditorPropertyText::_text_entered);
}
EditorPropertyText::EditorPropertyText() {
@ -71,6 +83,8 @@ EditorPropertyText::EditorPropertyText() {
add_child(text);
add_focusable(text);
text->connect("text_changed", this, "_text_changed");
text->connect("text_entered", this, "_text_entered");
updating = false;
}
@ -78,12 +92,12 @@ EditorPropertyText::EditorPropertyText() {
void EditorPropertyMultilineText::_big_text_changed() {
text->set_text(big_text->get_text());
emit_signal("property_changed", get_edited_property(), big_text->get_text(), true);
emit_signal("property_changed", get_edited_property(), big_text->get_text());
}
void EditorPropertyMultilineText::_text_changed() {
emit_signal("property_changed", get_edited_property(), text->get_text(), true);
emit_signal("property_changed", get_edited_property(), text->get_text());
}
void EditorPropertyMultilineText::_open_big_text() {

View file

@ -54,6 +54,7 @@ class EditorPropertyText : public EditorProperty {
bool updating;
void _text_changed(const String &p_string);
void _text_entered(const String &p_string);
protected:
static void _bind_methods();

View file

@ -210,8 +210,8 @@ void EditorPropertyArray::update_property() {
default: {}
}
if (!array.is_array()) {
edit->set_text(arrtype + "[" + Variant::get_type_name(array.get_type()) + "]");
if (array.get_type() == Variant::NIL) {
edit->set_text(String("(Nil) ") + arrtype);
edit->set_pressed(false);
if (vbox) {
memdelete(vbox);
@ -219,7 +219,7 @@ void EditorPropertyArray::update_property() {
return;
}
edit->set_text(arrtype + "[" + itos(array.call("size")) + "]");
edit->set_text(arrtype + "(size " + itos(array.call("size")) + ")");
#ifdef TOOLS_ENABLED
@ -613,7 +613,13 @@ void EditorPropertyDictionary::_change_type(Object *p_button, int p_index) {
void EditorPropertyDictionary::_add_key_value() {
// Do not allow nil as valid key. I experienced errors with this
if (object->get_new_item_key().get_type() == Variant::NIL) {
return;
}
Dictionary dict = object->get_dict();
dict[object->get_new_item_key()] = object->get_new_item_value();
object->set_new_item_key(Variant());
object->set_new_item_value(Variant());
@ -663,9 +669,20 @@ void EditorPropertyDictionary::_change_type_menu(int p_index) {
void EditorPropertyDictionary::update_property() {
Dictionary dict = get_edited_object()->get(get_edited_property());
Variant updated_val = get_edited_object()->get(get_edited_property());
edit->set_text("Dict[" + itos(dict.size()) + "]");
if (updated_val.get_type() == Variant::NIL) {
edit->set_text("Dictionary (Nil)"); //This provides symmetry with the array property.
edit->set_pressed(false);
if (vbox) {
memdelete(vbox);
}
return;
}
Dictionary dict = updated_val;
edit->set_text("Dictionary (size " + itos(dict.size()) + ")");
#ifdef TOOLS_ENABLED
@ -695,9 +712,9 @@ void EditorPropertyDictionary::update_property() {
page->set_h_size_flags(SIZE_EXPAND_FILL);
page->connect("value_changed", this, "_page_changed");
} else {
//bye bye children of the box
while (vbox->get_child_count() > 1) {
memdelete(vbox->get_child(1));
// Queue childs for deletion, delete immediately might cause errors.
for (size_t i = 1; i < vbox->get_child_count(); i++) {
vbox->get_child(i)->queue_delete();
}
}
@ -941,10 +958,10 @@ void EditorPropertyDictionary::update_property() {
prop->update_property();
if (i == amount + 1) {
Button *add_item = memnew(Button);
add_item->set_text(TTR("Add Key/Value Pair"));
add_vbox->add_child(add_item);
add_item->connect("pressed", this, "_add_key_value");
Button *butt_add_item = memnew(Button);
butt_add_item->set_text(TTR("Add Key/Value Pair"));
butt_add_item->connect("pressed", this, "_add_key_value");
add_vbox->add_child(butt_add_item);
}
}
@ -965,8 +982,16 @@ void EditorPropertyDictionary::_notification(int p_what) {
if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) {
}
}
void EditorPropertyDictionary::_edit_pressed() {
Variant prop_val = get_edited_object()->get(get_edited_property());
if (prop_val.get_type() == Variant::NIL) {
Variant::CallError ce;
prop_val = Variant::construct(Variant::DICTIONARY, NULL, 0, ce);
get_edited_object()->set(get_edited_property(), prop_val);
}
get_edited_object()->editor_set_section_unfold(get_edited_property(), edit->is_pressed());
update_property();
}