Simplify signals of TreeSearchPanel

This commit is contained in:
Alexander Montag 2024-09-26 05:37:19 +00:00
parent 1145ce0252
commit af15dde4c8
3 changed files with 7 additions and 15 deletions

View File

@ -533,10 +533,8 @@ void TaskTree::_notification(int p_what) {
tree->connect("multi_selected", callable_mp(this, &TaskTree::_on_item_selected).unbind(3), CONNECT_DEFERRED);
tree->connect("item_activated", callable_mp(this, &TaskTree::_on_item_activated));
tree->connect("item_collapsed", callable_mp(this, &TaskTree::_on_item_collapsed));
// TODO: Simplify these signals into one (candidate names: changed, updated, update_requested):
tree_search->search_panel->connect("text_changed", callable_mp(this, &TaskTree::_update_tree).unbind(1));
tree_search->search_panel->connect("update_requested", callable_mp(this, &TaskTree::_update_tree));
tree_search->search_panel->connect("visibility_changed", callable_mp(this, &TaskTree::_update_tree));
tree_search->search_panel->connect("filter_toggled", callable_mp(this, &TaskTree::_update_tree));
} break;
case NOTIFICATION_THEME_CHANGED: {
_do_update_theme_item_cache();

View File

@ -82,35 +82,30 @@ void TreeSearchPanel::_add_spacer(float p_width_multiplier) {
add_child(spacer);
}
void TreeSearchPanel::_emit_text_changed(const String &p_text) {
this->emit_signal("text_changed", p_text);
}
void TreeSearchPanel::_emit_text_submitted(const String &p_text) {
this->emit_signal("text_submitted");
}
void TreeSearchPanel::_emit_filter_toggled() {
this->emit_signal("filter_toggled");
void TreeSearchPanel::_emit_update_requested(){
emit_signal("update_requested");
}
void TreeSearchPanel::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_READY: {
_initialize_controls();
line_edit_search->connect("text_changed", callable_mp(this, &TreeSearchPanel::_emit_text_changed));
line_edit_search->connect("text_changed", callable_mp(this, &TreeSearchPanel::_emit_update_requested).unbind(1));
_initialize_close_callbacks();
line_edit_search->connect("text_submitted", callable_mp(this, &TreeSearchPanel::_emit_text_submitted));
check_button_filter_highlight->connect("pressed", callable_mp(this, &TreeSearchPanel::_emit_filter_toggled));
check_button_filter_highlight->connect("pressed", callable_mp(this, &TreeSearchPanel::_emit_update_requested));
break;
}
}
}
void TreeSearchPanel::_bind_methods() {
ADD_SIGNAL(MethodInfo("text_changed"));
ADD_SIGNAL(MethodInfo("update_requested"));
ADD_SIGNAL(MethodInfo("text_submitted"));
ADD_SIGNAL(MethodInfo("filter_toggled"));
}
TreeSearchPanel::TreeSearchPanel() {

View File

@ -53,9 +53,8 @@ private:
void _add_spacer(float width_multiplier = 1.f);
void _on_draw_highlight(TreeItem *p_item, Rect2 p_rect);
void _emit_text_changed(const String &p_text);
void _emit_text_submitted(const String &p_text);
void _emit_filter_toggled();
void _emit_update_requested();
void _notification(int p_what);
protected: