From ea7cf9711a5a7315522f048166958f441e58489c Mon Sep 17 00:00:00 2001 From: Chris Cranford Date: Sat, 29 Jun 2024 16:09:53 -0400 Subject: [PATCH] GH-455 Fix collapse/expand fault in all actions menu --- src/editor/graph/actions/action_menu.cpp | 20 +++++++++++++++++++- src/editor/graph/actions/action_menu.h | 7 +++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/editor/graph/actions/action_menu.cpp b/src/editor/graph/actions/action_menu.cpp index bb7a3090..29575402 100644 --- a/src/editor/graph/actions/action_menu.cpp +++ b/src/editor/graph/actions/action_menu.cpp @@ -95,8 +95,9 @@ void OrchestratorGraphActionMenu::_notification(int p_what) _tree_view->set_select_mode(Tree::SELECT_ROW); _tree_view->connect("item_activated", callable_mp(this, &OrchestratorGraphActionMenu::_on_tree_item_activated)); _tree_view->connect("item_selected", callable_mp(this, &OrchestratorGraphActionMenu::_on_tree_item_selected)); - _tree_view->connect("nothing_selected", callable_mp(this, &OrchestratorGraphActionMenu::_on_tree_item_activated)); + _tree_view->connect("nothing_selected", callable_mp(this, &OrchestratorGraphActionMenu::_on_tree_nothing_selected)); _tree_view->connect("button_clicked", callable_mp(this, &OrchestratorGraphActionMenu::_on_tree_button_clicked)); + _tree_view->connect("item_collapsed", callable_mp(this, &OrchestratorGraphActionMenu::_on_tree_item_collapsed)); vbox->add_child(_tree_view); set_ok_button_text("Add"); @@ -392,6 +393,23 @@ void OrchestratorGraphActionMenu::_on_tree_item_activated() _notify_and_close(_tree_view->get_selected()); } +void OrchestratorGraphActionMenu::_on_tree_nothing_selected() +{ + // Although Godot Tree dispatches nothing_selected, it does have a selected item, + // so this needs to be cleared and the Add button needs to be disabled. + _tree_view->deselect_all(); + get_ok_button()->set_disabled(true); +} + +void OrchestratorGraphActionMenu::_on_tree_item_collapsed(TreeItem* p_item) +{ + if (!p_item || p_item->get_child_count() > 0) + { + _tree_view->deselect_all(); + get_ok_button()->set_disabled(true); + } +} + void OrchestratorGraphActionMenu::_on_tree_button_clicked(TreeItem* p_item, int p_column, int p_id, int p_button_index) { // There is currently only 1 button for marking favorites diff --git a/src/editor/graph/actions/action_menu.h b/src/editor/graph/actions/action_menu.h index b45839d8..78cc92a3 100644 --- a/src/editor/graph/actions/action_menu.h +++ b/src/editor/graph/actions/action_menu.h @@ -116,6 +116,13 @@ class OrchestratorGraphActionMenu : public ConfirmationDialog /// Dispatched when a tree element is double-clicked void _on_tree_item_activated(); + /// Dispatched when clicking anywhere in the tree with no selection + void _on_tree_nothing_selected(); + + /// Dispached when a tree item is collapsed or expanded + /// @param p_item the item collapsed or expanded + void _on_tree_item_collapsed(TreeItem* p_item); + /// Dispatched when the user clicks a button in the tree /// @param p_item the current tree item who's button was clicked /// @param p_column the column the button is within