Disable Add button when theme item name is empty

This commit is contained in:
kobewi 2023-12-11 22:21:27 +01:00
parent 6882e5042d
commit fc7cdd5c37
2 changed files with 10 additions and 0 deletions

View File

@ -2287,8 +2287,11 @@ VBoxContainer *ThemeTypeEditor::_create_item_list(Theme::DataType p_data_type) {
item_add_edit->connect("text_submitted", callable_mp(this, &ThemeTypeEditor::_item_add_lineedit_cbk).bind(p_data_type, item_add_edit));
Button *item_add_button = memnew(Button);
item_add_button->set_text(TTR("Add"));
item_add_button->set_disabled(true);
item_add_hb->add_child(item_add_button);
item_add_button->connect("pressed", callable_mp(this, &ThemeTypeEditor::_item_add_cbk).bind(p_data_type, item_add_edit));
item_add_edit->set_meta("button", item_add_button);
item_add_edit->connect("text_changed", callable_mp(this, &ThemeTypeEditor::_update_add_button).bind(item_add_edit));
return items_list;
}
@ -2850,6 +2853,11 @@ void ThemeTypeEditor::_add_default_type_items() {
ur->commit_action();
}
void ThemeTypeEditor::_update_add_button(const String &p_text, LineEdit *p_for_edit) {
Button *button = Object::cast_to<Button>(p_for_edit->get_meta("button"));
button->set_disabled(p_text.strip_edges().is_empty());
}
void ThemeTypeEditor::_item_add_cbk(int p_data_type, Control *p_control) {
LineEdit *le = Object::cast_to<LineEdit>(p_control);
if (le->get_text().strip_edges().is_empty()) {
@ -2895,6 +2903,7 @@ void ThemeTypeEditor::_item_add_cbk(int p_data_type, Control *p_control) {
ur->commit_action();
le->set_text("");
_update_add_button("", le);
}
void ThemeTypeEditor::_item_add_lineedit_cbk(String p_value, int p_data_type, Control *p_control) {

View File

@ -382,6 +382,7 @@ class ThemeTypeEditor : public MarginContainer {
void _add_type_button_cbk();
void _add_default_type_items();
void _update_add_button(const String &p_text, LineEdit *p_for_edit);
void _item_add_cbk(int p_data_type, Control *p_control);
void _item_add_lineedit_cbk(String p_value, int p_data_type, Control *p_control);
void _item_override_cbk(int p_data_type, String p_item_name);