Merge pull request #86044 from KoBeWi/can't_add_if_can't_add

Disable Add button when theme item name is empty
This commit is contained in:
Yuri Sizov 2023-12-18 18:18:09 +01:00
commit 2552821f06
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);