void OperationsAdded(Progress.Item[] items) { //using (new EditorPerformanceTracker("ProgressWindow.OperationsAdded")) { foreach (var item in items) { var treeViewItemData = new TreeViewItemData <Progress.Item>(item.id, item); AddTreeViewItemToTree(treeViewItemData); // When setting autoExpand to true, there is a possible race condition // that can happen if the item is added and removed quickly. // AutoExpand triggers a callback to be executed at a later point when makeItem is called. // By the time the callback is called, the item might have been removed. // Therefore, we expand all new items here manually. m_TreeView.viewController.ExpandItem(item.id, true); // Also, if the item has no child, then the expanded state is not set. // Therefore, we need to keep track of this item to expand it when we add a child to it. if (!m_TreeView.viewController.HasChildren(item.id)) { m_ItemsNeedingExpansion.Add(item.id); } } m_TreeView.RefreshItems(); } }