static void UnloadChildrenOf(SubjectVM.RowVM parent) { if (parent.Status == SubjectVM.ChildrenStatus.YesLoaded) { parent.Status = SubjectVM.ChildrenStatus.YesPlaceholder; } }
void RefreshRoot() { //collect items from cache var cachedRoots = Globals.BoxCache.GetTopNotes().ToArray(); //hold on to old row VMs for reuse var oldRowVMs = VM.RootRows.ToArray(); VM.RootRows.Clear(); var newRows = new List <SubjectVM.RowVM>(); //quit if empty if (cachedRoots.Length == 0) { return; } //rebuild list in current order using old row VMs foreach (var cachedBox in cachedRoots) { var rootVM = oldRowVMs.FirstOrDefault(r => r.Persistent.RowId == cachedBox.RowId); if (rootVM == null || rootVM.Persistent != cachedBox) { rootVM = new SubjectVM.RowVM(cachedBox, null); } newRows.Add(rootVM); rootVM.Touch(); } VM.RootRows.AddRange(newRows); //handle placeholders under those nodes that have actual children var rootIds = cachedRoots.Select(r => r.RowId).ToArray(); var withChildren = Globals.UI.BoxesWithChildren(rootIds, true); foreach (var vm in VM.RootRows) { bool hasChildren = withChildren.Contains(vm.Persistent.RowId); if (vm.Status == SubjectVM.ChildrenStatus.No && hasChildren) { vm.Status = SubjectVM.ChildrenStatus.YesPlaceholder; } else if (!hasChildren) { vm.Status = SubjectVM.ChildrenStatus.No; } } }
/// <summary> /// Load children and return true if any found /// </summary> static bool LoadChildrenOf(SubjectVM.RowVM parent) { var children = Globals.UI.LoadBoxesByParent(parent.Persistent.RowId, true); parent.Status = children.Any() ? SubjectVM.ChildrenStatus.YesLoaded : SubjectVM.ChildrenStatus.No; parent.Children.AddRange(children.Select(r => new SubjectVM.RowVM(r, parent))); var ids = children.Select(r => r.RowId).ToArray(); var withChildren = Globals.UI.BoxesWithChildren(ids, true); foreach (var id in withChildren) { var child = parent.Children.FirstOrDefault(r => r.Persistent.RowId == id); if (child != null) { child.Status = SubjectVM.ChildrenStatus.YesPlaceholder; } } return(parent.Status == SubjectVM.ChildrenStatus.YesLoaded); }
/// <summary> /// Recursively refresh rowVM's children if it contains the given box; return true if this or any descendant level /// found the box /// </summary> /// <returns></returns> bool RefreshChildrenOf(SubjectVM.RowVM rowVM, BoxEditingPool.Item changes) { long thisId = rowVM.Persistent.RowId; bool reloadNeeded = false; if (rowVM.Status == SubjectVM.ChildrenStatus.No) { reloadNeeded = changes.NewParentId == thisId; } else if (rowVM.Status == SubjectVM.ChildrenStatus.YesLoaded) { reloadNeeded = (changes.IsParentageChanged || changes.IsTitleChanged || changes.NewDoneDate != changes.OldDoneDate) && (changes.OldParentId == thisId || changes.NewParentId == thisId); } else if (rowVM.Status == SubjectVM.ChildrenStatus.YesPlaceholder) { reloadNeeded = false; //was: changes.IsParentageChanged && (changes.OldParentId == thisId || changes.NewParentId == thisId); } //found it, so reload (which collapses children) if (reloadNeeded) { LoadChildrenOf(rowVM); return(true); } //didn't find it, so recurse children and exit when found if (rowVM.Status == SubjectVM.ChildrenStatus.YesLoaded) { foreach (var c in rowVM.Children) { if (RefreshChildrenOf(c, changes)) { return(true); } } } return(false); }