public StandardCollectionViewGroup(StandardCollectionViewGroup parent, object name, int depth, bool isBottomLevel, SortDescriptionCollection sorters) : base(name) { this.isBottomLevel = isBottomLevel; Depth = depth; Parent = parent; Sorters = sorters; }
public StandardCollectionViewGroup (StandardCollectionViewGroup parent, object name, int depth, bool isBottomLevel, SortDescriptionCollection sorters) : base (name) { this.isBottomLevel = isBottomLevel; Depth = depth; Parent = parent; Sorters = sorters; }
void AddInSubtree (StandardCollectionViewGroup group, object item, CultureInfo culture, IList<GroupDescription> descriptions, bool allowSorting) { int depth = group.Depth; if (group.IsBottomLevel) { group.AddItem (item, allowSorting); CollectionChanged.Raise (this, new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Add, item, IndexOfSubtree (item))); } else { var desc = descriptions [group.Depth]; var groupNames = desc.GroupNameFromItem (item, group.Depth, culture); if (groupNames is IList) { foreach (var name in (IList) groupNames) AddInSubtree (group, item, culture, descriptions, allowSorting, name); } else { AddInSubtree (group, item, culture, descriptions, allowSorting, groupNames); } } }
void AddInSubtree (StandardCollectionViewGroup group, object item, CultureInfo culture, IList<GroupDescription> descriptions, bool allowSorting, object name) { bool added = false; foreach (StandardCollectionViewGroup g in group.Items) { var desc = descriptions [group.Depth]; if (desc.NamesMatch (g.Name, name)) { AddInSubtree (g, item, culture, descriptions, allowSorting); added = true; } } if (!added) { int depth = group.Depth + 1; var g = new StandardCollectionViewGroup (group, name, depth, depth == descriptions.Count, group.Sorters); group.AddItem (g, allowSorting); AddInSubtree (g, item, culture, descriptions, allowSorting); } }
public override void Refresh () { if (IsAddingNew || IsEditingItem) throw new InvalidOperationException ("Cannot refresh while adding or editing an item"); if (((IDeferRefresh) this).DeferLevel != 0) return; if (RootGroup == null) RootGroup = new StandardCollectionViewGroup (null, null, 0, false, SortDescriptions); Groups = null; RootGroup.ClearItems (); if (ActiveList != SourceCollection) { filteredList.Clear (); foreach (var item in SourceCollection) AddToFiltered (item, false); if (SortDescriptions.Count > 0) filteredList.Sort (new PropertyComparer (SortDescriptions)); if (GroupDescriptions.Count > 0 && filteredList.Count > 0) { foreach (var item in filteredList) RootGroup.AddInSubtree (item, Culture, GroupDescriptions, false); Groups = RootGroup.Items; } } IsEmpty = ActiveList.Count == 0; int index = IndexOf (CurrentItem); if (index < 0 && CurrentPosition != -1 && !IsEmpty) index = 0; RaiseCollectionChanged (new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Reset)); MoveCurrentTo (index, true); }
bool IndexOfSubtree (StandardCollectionViewGroup group, object item, ref int index) { for (int i = 0; i < group.Items.Count; i ++) { var v = group.Items [i]; if (v == item) { return true;; } else if (v is StandardCollectionViewGroup) { if (IndexOfSubtree ((StandardCollectionViewGroup) v, item, ref index)) return true; } else { index ++; } } return false; }
public RootCollectionViewGroup (StandardCollectionViewGroup parent, object name, int depth, bool isBottomLevel, SortDescriptionCollection sorters) : base (parent, name, depth, isBottomLevel, sorters) { }
bool RemoveInSubtree (StandardCollectionViewGroup group, object item, ref int index) { // The same item can exist in multiple groups. We need to remove it from every group // and emit the CollectionChanged event with the correct index. bool removed = false; for (int i = 0; i < group.Items.Count; i++) { var groupItem = group.Items [i]; if (groupItem is StandardCollectionViewGroup) { var subGroup = (StandardCollectionViewGroup) groupItem; removed |= RemoveInSubtree (subGroup, item, ref index); if (subGroup.Items.Count == 0) { i--; group.RemoveItem (subGroup); } } else if (groupItem == item) { // If we remove the item, the next item we check will be at // the same index, so do not increment it here. removed = true; group.RemoveItem (item); i--; CollectionChanged.Raise (this, new NotifyCollectionChangedEventArgs (NotifyCollectionChangedAction.Remove, item, index)); } else { // We only need to increment the index if we do *not* remove the item. index ++; } } return removed; }
internal void AddInSubtree (object item, CultureInfo culture, IList<GroupDescription> descriptions, bool allowSorting, object name) { bool added = false; foreach (StandardCollectionViewGroup group in Items) { var desc = descriptions [Depth]; if (desc.NamesMatch (group.Name, name)) { group.AddInSubtree (item, culture, descriptions, allowSorting); added = true; } } if (!added) { int depth = Depth + 1; var group = new StandardCollectionViewGroup (this, name, depth, depth == descriptions.Count, Sorters); AddItem (group, allowSorting); group.AddInSubtree (item, culture, descriptions, allowSorting); } }