Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Delete All button to ItemList editor #44352

Merged
merged 1 commit into from
Sep 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions editor/plugins/item_list_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ void ItemListEditor::_node_removed(Node *p_node) {
void ItemListEditor::_notification(int p_notification) {
if (p_notification == NOTIFICATION_ENTER_TREE || p_notification == NOTIFICATION_THEME_CHANGED) {
add_button->set_icon(get_theme_icon(SNAME("Add"), SNAME("EditorIcons")));
clear_button->set_icon(get_theme_icon(SNAME("Remove"), SNAME("EditorIcons")));
del_button->set_icon(get_theme_icon(SNAME("Remove"), SNAME("EditorIcons")));
} else if (p_notification == NOTIFICATION_READY) {
get_tree()->connect("node_removed", callable_mp(this, &ItemListEditor::_node_removed));
Expand All @@ -258,6 +259,12 @@ void ItemListEditor::_add_pressed() {
item_plugins[selected_idx]->add_item();
}

void ItemListEditor::_clear_pressed() {
for (int i = item_plugins[selected_idx]->get_item_count() - 1; i >= 0; i--) {
item_plugins[selected_idx]->erase(i);
}
}

void ItemListEditor::_delete_pressed() {
if (selected_idx == -1) {
return;
Expand Down Expand Up @@ -350,6 +357,11 @@ ItemListEditor::ItemListEditor() {

hbc->add_spacer();

clear_button = memnew(Button);
Copy link
Contributor

@EricEzaM EricEzaM Dec 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the name in the code match the name given in the display? For consistency?

delete_all_button, _delete_all_pressed()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe. I thought it's easier to distinguish this way.

clear_button->set_text(TTR("Delete All"));
hbc->add_child(clear_button);
clear_button->connect("pressed", callable_mp(this, &ItemListEditor::_clear_pressed));

del_button = memnew(Button);
del_button->set_text(TTR("Delete"));
hbc->add_child(del_button);
Expand Down
2 changes: 2 additions & 0 deletions editor/plugins/item_list_editor_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ class ItemListEditor : public HBoxContainer {
Tree *tree;
Button *add_button;
Button *del_button;
Button *clear_button;

int selected_idx;

Expand All @@ -213,6 +214,7 @@ class ItemListEditor : public HBoxContainer {

void _add_pressed();
void _delete_pressed();
void _clear_pressed();

void _node_removed(Node *p_node);

Expand Down