Compare commits

..

No commits in common. "af15dde4c896b76db66689d49ced72730b8e7775" and "8d29f16963c30dcd073964b028ff6d5f1303b952" have entirely different histories.

3 changed files with 40 additions and 32 deletions

View File

@ -533,8 +533,10 @@ void TaskTree::_notification(int p_what) {
tree->connect("multi_selected", callable_mp(this, &TaskTree::_on_item_selected).unbind(3), CONNECT_DEFERRED); 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_activated", callable_mp(this, &TaskTree::_on_item_activated));
tree->connect("item_collapsed", callable_mp(this, &TaskTree::_on_item_collapsed)); tree->connect("item_collapsed", callable_mp(this, &TaskTree::_on_item_collapsed));
tree_search->search_panel->connect("update_requested", callable_mp(this, &TaskTree::_update_tree)); // 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("visibility_changed", 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; } break;
case NOTIFICATION_THEME_CHANGED: { case NOTIFICATION_THEME_CHANGED: {
_do_update_theme_item_cache(); _do_update_theme_item_cache();

View File

@ -82,30 +82,35 @@ void TreeSearchPanel::_add_spacer(float p_width_multiplier) {
add_child(spacer); 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) { void TreeSearchPanel::_emit_text_submitted(const String &p_text) {
this->emit_signal("text_submitted"); this->emit_signal("text_submitted");
} }
void TreeSearchPanel::_emit_update_requested(){ void TreeSearchPanel::_emit_filter_toggled() {
emit_signal("update_requested"); this->emit_signal("filter_toggled");
} }
void TreeSearchPanel::_notification(int p_what) { void TreeSearchPanel::_notification(int p_what) {
switch (p_what) { switch (p_what) {
case NOTIFICATION_READY: { case NOTIFICATION_READY: {
_initialize_controls(); _initialize_controls();
line_edit_search->connect("text_changed", callable_mp(this, &TreeSearchPanel::_emit_update_requested).unbind(1)); line_edit_search->connect("text_changed", callable_mp(this, &TreeSearchPanel::_emit_text_changed));
_initialize_close_callbacks(); _initialize_close_callbacks();
line_edit_search->connect("text_submitted", callable_mp(this, &TreeSearchPanel::_emit_text_submitted)); line_edit_search->connect("text_submitted", callable_mp(this, &TreeSearchPanel::_emit_text_submitted));
check_button_filter_highlight->connect("pressed", callable_mp(this, &TreeSearchPanel::_emit_update_requested)); check_button_filter_highlight->connect("pressed", callable_mp(this, &TreeSearchPanel::_emit_filter_toggled));
break; break;
} }
} }
} }
void TreeSearchPanel::_bind_methods() { void TreeSearchPanel::_bind_methods() {
ADD_SIGNAL(MethodInfo("update_requested")); ADD_SIGNAL(MethodInfo("text_changed"));
ADD_SIGNAL(MethodInfo("text_submitted")); ADD_SIGNAL(MethodInfo("text_submitted"));
ADD_SIGNAL(MethodInfo("filter_toggled"));
} }
TreeSearchPanel::TreeSearchPanel() { TreeSearchPanel::TreeSearchPanel() {
@ -168,6 +173,7 @@ void TreeSearch::_highlight_tree(const String &p_search_mask) {
int num_m = number_matches.has(entry) ? number_matches.get(entry) : 0; int num_m = number_matches.has(entry) ? number_matches.get(entry) : 0;
if (num_m == 0) { if (num_m == 0) {
continue; continue;
;
} }
// make sure to also call any draw method already defined. // make sure to also call any draw method already defined.
@ -211,7 +217,7 @@ void TreeSearch::_draw_highlight_item(TreeItem *p_tree_item, Rect2 p_rect, Strin
font = p_tree_item->get_tree()->get_theme_font(LW_NAME(font)); font = p_tree_item->get_tree()->get_theme_font(LW_NAME(font));
} }
ERR_FAIL_NULL(font); ERR_FAIL_NULL(font);
float font_size = p_tree_item->get_custom_font_size(0); double font_size = p_tree_item->get_custom_font_size(0);
if (font_size == -1) { if (font_size == -1) {
font_size = p_tree_item->get_tree()->get_theme_font_size(LW_NAME(font)); font_size = p_tree_item->get_tree()->get_theme_font_size(LW_NAME(font));
} }
@ -267,9 +273,9 @@ void TreeSearch::_draw_highlight_item(TreeItem *p_tree_item, Rect2 p_rect, Strin
} }
} }
void TreeSearch::_update_matching_entries(const String &p_search_mask) { void TreeSearch::_update_matching_entries(const String &search_mask) {
Vector<TreeItem *> accum; Vector<TreeItem *> accum;
matching_entries = _find_matching_entries(tree_reference->get_root(), p_search_mask, accum); matching_entries = _find_matching_entries(tree_reference->get_root(), search_mask, accum);
} }
/* this linearizes the tree into [ordered_tree_items] like so: /* this linearizes the tree into [ordered_tree_items] like so:
@ -361,21 +367,16 @@ TreeSearch::StringSearchIndices TreeSearch::_substring_bounds(const String &p_se
return result; return result;
} }
void TreeSearch::_select_item(TreeItem *p_item) { void TreeSearch::_select_item(TreeItem *item) {
if (!p_item) if (!item)
return; return;
tree_reference->set_selected(p_item, 0); tree_reference->set_selected(item, 0);
tree_reference->scroll_to_item(item);
// first unfold ancestors item = item->get_parent();
TreeItem * ancestor = p_item->get_parent(); while (item) {
ancestor = ancestor->get_parent(); item->set_collapsed(false);
while (ancestor) { item = item->get_parent();
ancestor->set_collapsed(false);
ancestor = ancestor->get_parent();
} }
// then scroll to [item]
tree_reference->scroll_to_item(p_item);
} }
void TreeSearch::_select_first_match() { void TreeSearch::_select_first_match() {
@ -476,6 +477,9 @@ TreeSearch::TreeSearch() {
search_panel = memnew(TreeSearchPanel); search_panel = memnew(TreeSearchPanel);
} }
TreeSearch::~TreeSearch() {
}
/* !TreeSearch */ /* !TreeSearch */
#endif // TOOLS_ENABLED #endif // TOOLS_ENABLED

View File

@ -52,9 +52,10 @@ private:
void _initialize_close_callbacks(); void _initialize_close_callbacks();
void _add_spacer(float width_multiplier = 1.f); void _add_spacer(float width_multiplier = 1.f);
void _on_draw_highlight(TreeItem *p_item, Rect2 p_rect); void _on_draw_highlight(TreeItem *item, Rect2 rect);
void _emit_text_changed(const String &text);
void _emit_text_submitted(const String &p_text); void _emit_text_submitted(const String &p_text);
void _emit_update_requested(); void _emit_filter_toggled();
void _notification(int p_what); void _notification(int p_what);
protected: protected:
@ -90,16 +91,16 @@ private:
void _filter_tree(const String &p_search_mask); void _filter_tree(const String &p_search_mask);
void _highlight_tree(const String &p_search_mask); void _highlight_tree(const String &p_search_mask);
void _draw_highlight_item(TreeItem *p_tree_item, Rect2 p_rect, String p_search_mask, Callable p_parent_draw_method); void _draw_highlight_item(TreeItem *tree_item, Rect2 rect, String search_mask, Callable parent_draw_method);
void _update_matching_entries(const String &p_search_mask); void _update_matching_entries(const String &search_mask);
void _update_ordered_tree_items(TreeItem *p_tree_item); void _update_ordered_tree_items(TreeItem *tree_item);
void _update_number_matches(); void _update_number_matches();
Vector<TreeItem *> _find_matching_entries(TreeItem *p_tree_item, const String &p_search_mask, Vector<TreeItem *> &p_buffer); Vector<TreeItem *> _find_matching_entries(TreeItem *tree_item, const String &search_mask, Vector<TreeItem *> &buffer);
StringSearchIndices _substring_bounds(const String &p_searchable, const String &p_search_mask) const; StringSearchIndices _substring_bounds(const String &searchable, const String &search_mask) const;
void _select_item(TreeItem *p_item); void _select_item(TreeItem *item);
void _select_first_match(); void _select_first_match();
void _select_next_match(); void _select_next_match();
@ -110,11 +111,12 @@ protected:
public: public:
// we will add everything from TaskTree.h // we will add everything from TaskTree.h
void update_search(Tree *p_tree); void update_search(Tree *tree);
void on_item_edited(TreeItem *p_item); void on_item_edited(TreeItem *item);
TreeSearchPanel *search_panel; TreeSearchPanel *search_panel;
TreeSearch(); TreeSearch();
~TreeSearch();
}; };
#endif // TREE_SEARCH_H #endif // TREE_SEARCH_H