Skip to content

Commit

Permalink
Simplify signals of TreeSearch
Browse files Browse the repository at this point in the history
  • Loading branch information
monxa committed Sep 26, 2024
1 parent 1145ce0 commit 2321587
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 15 deletions.
4 changes: 1 addition & 3 deletions editor/task_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
15 changes: 5 additions & 10 deletions editor/tree_search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
3 changes: 1 addition & 2 deletions editor/tree_search.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,8 @@ class TreeSearchPanel : public HFlowContainer {
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:
Expand Down

0 comments on commit 2321587

Please sign in to comment.