Prelude.Tree <iCS_EditorObject> BuildTreeNode(iCS_EditorObject nodeRoot, List <bool> filterFlags)
 {
     Prelude.Tree <iCS_EditorObject> tree = new Prelude.Tree <iCS_EditorObject>(nodeRoot);
     myIStorage.ForEachChild(nodeRoot,
                             c => {
         Prelude.Tree <iCS_EditorObject> newNode = BuildTreeNode(c, filterFlags);
         if (filterFlags[c.InstanceId])
         {
             tree.AddChild(newNode);
         }
     }
                             );
     tree.Sort(SortComparaison);
     return(tree);
 }
        bool ShowAllFilteredFrom(Prelude.Tree <iCS_EditorObject> tree)
        {
            if (tree == null)
            {
                return(false);
            }
            bool result   = false;
            var  children = tree.Children;

            if (children != null)
            {
                foreach (var child in children)
                {
                    result |= ShowAllFilteredFrom(child);
                }
                if (result)
                {
                    myTreeView.Unfold(tree.Value);
                }
            }
            return(result | FilterIn(tree.Value));
        }
        // =================================================================================
        // Filter & reorder.
        // ---------------------------------------------------------------------------------
        void BuildTree()
        {
            // Build filter list of object...
            var filterFlags = Prelude.map(o => FilterIn(o), myIStorage.EditorObjects);

            // ... make certain the parents are also filtered in !!!
            myTreeSize = 0;
            for (int i = 0; i < filterFlags.Count; ++i)
            {
                if (filterFlags[i])
                {
                    ++myTreeSize;
                    Prelude.until(
                        myIStorage.IsValid,
                        id => {
                        if (myIStorage.IsIdValid(id))
                        {
                            filterFlags[id] = true;
                            return(myIStorage.EditorObjects[id].ParentId);
                        }
                        filterFlags[id] = false;
                        return(-1);
                    },
                        myIStorage.IsIdValid(i) ? myIStorage.EditorObjects[i].ParentId : -1
                        );
                }
            }
            // Build tree and sort it elements.
            if (filterFlags.Count == 0 || !filterFlags[0])
            {
                myTree = null;
                return;
            }
            var rootNode = myIStorage.EditorObjects[0];

            myTree = BuildTreeNode(rootNode, filterFlags);
        }