Make TreeSearch::search_panel private and fix nulltpr

This commit is contained in:
Alexander Montag 2024-09-27 15:02:21 +00:00
parent 0fc11bf05b
commit 47706e9480
4 changed files with 19 additions and 13 deletions

View File

@ -533,14 +533,15 @@ 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)); tree_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_panel->connect("visibility_changed", 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();
_update_tree(); _update_tree();
} break; } break;
} }
} }
void TaskTree::_bind_methods() { void TaskTree::_bind_methods() {
@ -568,7 +569,8 @@ void TaskTree::_bind_methods() {
} }
void TaskTree::tree_search_show_and_focus() { void TaskTree::tree_search_show_and_focus() {
tree_search->search_panel->show_and_focus(); ERR_FAIL_NULL(tree_search);
tree_search_panel->show_and_focus();
} }
TaskTree::TaskTree() { TaskTree::TaskTree() {
@ -595,8 +597,9 @@ TaskTree::TaskTree() {
tree->set_drag_forwarding(callable_mp(this, &TaskTree::_get_drag_data_fw), callable_mp(this, &TaskTree::_can_drop_data_fw), callable_mp(this, &TaskTree::_drop_data_fw)); tree->set_drag_forwarding(callable_mp(this, &TaskTree::_get_drag_data_fw), callable_mp(this, &TaskTree::_can_drop_data_fw), callable_mp(this, &TaskTree::_drop_data_fw));
tree_search.instantiate(); tree_search_panel = memnew(TreeSearchPanel);
vbox_container->add_child(tree_search->search_panel); tree_search = Ref(memnew(TreeSearch(tree_search_panel)));
vbox_container->add_child(tree_search_panel);
} }
TaskTree::~TaskTree() { TaskTree::~TaskTree() {

View File

@ -46,7 +46,9 @@ private:
bool editable; bool editable;
bool updating_tree; bool updating_tree;
HashMap<RECT_CACHE_KEY, Rect2> probability_rect_cache; HashMap<RECT_CACHE_KEY, Rect2> probability_rect_cache;
Ref<TreeSearch> tree_search; Ref<TreeSearch> tree_search;
TreeSearchPanel *tree_search_panel;
struct ThemeCache { struct ThemeCache {
Ref<Font> comment_font; Ref<Font> comment_font;
@ -109,7 +111,6 @@ public:
bool selected_has_probability() const; bool selected_has_probability() const;
virtual bool editor_can_reload_from_file() { return false; } virtual bool editor_can_reload_from_file() { return false; }
TaskTree(); TaskTree();
~TaskTree(); ~TaskTree();

View File

@ -367,15 +367,14 @@ TreeSearch::StringSearchIndices TreeSearch::_substring_bounds(const String &p_se
void TreeSearch::_select_item(TreeItem *p_item) { void TreeSearch::_select_item(TreeItem *p_item) {
if (!p_item) if (!p_item)
return; return;
ERR_FAIL_COND(!tree_reference || p_item->get_tree() != tree_reference);
// first unfold ancestors // first unfold ancestors
TreeItem *ancestor = p_item->get_parent(); TreeItem *ancestor = p_item->get_parent();
ancestor = ancestor->get_parent();
while (ancestor) { while (ancestor) {
ancestor->set_collapsed(false); ancestor->set_collapsed(false);
ancestor = ancestor->get_parent(); ancestor = ancestor->get_parent();
} }
//then scroll to [item] //then scroll to [item]
tree_reference->scroll_to_item(p_item); tree_reference->scroll_to_item(p_item);
@ -476,10 +475,11 @@ void TreeSearch::update_search(Tree *p_tree) {
if (search_mode == TreeSearchMode::FILTER) { if (search_mode == TreeSearchMode::FILTER) {
_filter_tree(search_mask); _filter_tree(search_mask);
} }
} }
TreeSearch::TreeSearch() { TreeSearch::TreeSearch(TreeSearchPanel *p_search_panel) {
search_panel = memnew(TreeSearchPanel); search_panel = p_search_panel;
} }
/* !TreeSearch */ /* !TreeSearch */

View File

@ -81,8 +81,10 @@ private:
} }
}; };
Tree *tree_reference; TreeSearchPanel *search_panel;
// These variables are updated every time the update_search method is called.
Tree *tree_reference;
Vector<TreeItem *> ordered_tree_items; Vector<TreeItem *> ordered_tree_items;
Vector<TreeItem *> matching_entries; Vector<TreeItem *> matching_entries;
HashMap<TreeItem *, int> number_matches; HashMap<TreeItem *, int> number_matches;
@ -112,9 +114,9 @@ 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 *p_tree);
void on_item_edited(TreeItem *p_item); void on_item_edited(TreeItem *p_item);
TreeSearchPanel *search_panel;
TreeSearch(); TreeSearch(){ERR_FAIL_MSG("TreeSearch needs a TreeSearchPanel to work properly");}
TreeSearch(TreeSearchPanel * p_search_panel);
}; };
#endif // TREE_SEARCH_H #endif // TREE_SEARCH_H