From ac3ff49ae5e075bbfb1912deb666a1f21e1f9a31 Mon Sep 17 00:00:00 2001 From: Zae Date: Wed, 8 Jul 2020 21:32:42 +0800 Subject: [PATCH] fix item_edited behavior on Asset Installer. (cherry picked from commit b0fbde6abd2d2bd6a8ad226597b1582b62d63607) --- editor/editor_asset_installer.cpp | 25 ++++++++++++++++++++++++- editor/editor_asset_installer.h | 1 + 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/editor/editor_asset_installer.cpp b/editor/editor_asset_installer.cpp index 86611bd20af..43c77431526 100644 --- a/editor/editor_asset_installer.cpp +++ b/editor/editor_asset_installer.cpp @@ -55,6 +55,27 @@ void EditorAssetInstaller::_update_subitems(TreeItem *p_item, bool p_check, bool } } +void EditorAssetInstaller::_uncheck_parent(TreeItem *p_item) { + if (!p_item) { + return; + } + + bool any_checked = false; + TreeItem *item = p_item->get_children(); + while (item) { + if (item->is_checked(0)) { + any_checked = true; + break; + } + item = item->get_next(); + } + + if (!any_checked) { + p_item->set_checked(0, false); + _uncheck_parent(p_item->get_parent()); + } +} + void EditorAssetInstaller::_item_edited() { if (updating) @@ -67,7 +88,7 @@ void EditorAssetInstaller::_item_edited() { String path = item->get_metadata(0); updating = true; - if (path == String()) { //a dir + if (path == String() || item == tree->get_root()) { //a dir or root _update_subitems(item, item->is_checked(0), true); } @@ -76,6 +97,8 @@ void EditorAssetInstaller::_item_edited() { item->set_checked(0, true); item = item->get_parent(); } + } else { + _uncheck_parent(item->get_parent()); } updating = false; } diff --git a/editor/editor_asset_installer.h b/editor/editor_asset_installer.h index 840e7802643..7d6760a86ac 100644 --- a/editor/editor_asset_installer.h +++ b/editor/editor_asset_installer.h @@ -43,6 +43,7 @@ class EditorAssetInstaller : public ConfirmationDialog { Map status_map; bool updating; void _update_subitems(TreeItem *p_item, bool p_check, bool p_first = false); + void _uncheck_parent(TreeItem *p_item); void _item_edited(); virtual void ok_pressed();