Browse Source

Merge pull request #40209 from zaevi/fix-asset-installer-item_edited-behavior

fix tree-item's behavior on Asset Installer.
Rémi Verschelde 5 years ago
parent
commit
7bb1cef5c8
2 changed files with 25 additions and 1 deletions
  1. 24 1
      editor/editor_asset_installer.cpp
  2. 1 0
      editor/editor_asset_installer.h

+ 24 - 1
editor/editor_asset_installer.cpp

@@ -54,6 +54,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() {
 void EditorAssetInstaller::_item_edited() {
 	if (updating) {
 	if (updating) {
 		return;
 		return;
@@ -67,7 +88,7 @@ void EditorAssetInstaller::_item_edited() {
 	String path = item->get_metadata(0);
 	String path = item->get_metadata(0);
 
 
 	updating = true;
 	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);
 		_update_subitems(item, item->is_checked(0), true);
 	}
 	}
 
 
@@ -76,6 +97,8 @@ void EditorAssetInstaller::_item_edited() {
 			item->set_checked(0, true);
 			item->set_checked(0, true);
 			item = item->get_parent();
 			item = item->get_parent();
 		}
 		}
+	} else {
+		_uncheck_parent(item->get_parent());
 	}
 	}
 	updating = false;
 	updating = false;
 }
 }

+ 1 - 0
editor/editor_asset_installer.h

@@ -42,6 +42,7 @@ class EditorAssetInstaller : public ConfirmationDialog {
 	Map<String, TreeItem *> status_map;
 	Map<String, TreeItem *> status_map;
 	bool updating;
 	bool updating;
 	void _update_subitems(TreeItem *p_item, bool p_check, bool p_first = false);
 	void _update_subitems(TreeItem *p_item, bool p_check, bool p_first = false);
+	void _uncheck_parent(TreeItem *p_item);
 	void _item_edited();
 	void _item_edited();
 	virtual void ok_pressed();
 	virtual void ok_pressed();