/// <summary> /// Initializes a new instance of the <see cref="Conductor<T>.Collection.AllActive"/> class. /// </summary> public AllActive() { _items.CollectionChanged += (s, e) => { switch (e.Action) { case NotifyCollectionChangedAction.Add: e.NewItems.OfType <IChild>().ForEach(x => x.Parent = this); break; case NotifyCollectionChangedAction.Remove: e.OldItems.OfType <IChild>().ForEach(x => x.Parent = null); break; case NotifyCollectionChangedAction.Replace: e.NewItems.OfType <IChild>().ForEach(x => x.Parent = this); e.OldItems.OfType <IChild>().ForEach(x => x.Parent = null); break; case NotifyCollectionChangedAction.Reset: _items.OfType <IChild>().ForEach(x => x.Parent = this); break; } }; CloseStrategy = new AllOrNoneCloseStrategy <T>(); }
public AllActive() { items.CollectionChanged += (s, e) => { switch (e.Action) { case NotifyCollectionChangedAction.Add: e.NewItems.OfType <IChild>().Apply(x => x.Parent = this); break; case NotifyCollectionChangedAction.Remove: e.OldItems.OfType <IChild>().Apply(x => x.Parent = null); break; case NotifyCollectionChangedAction.Replace: e.NewItems.OfType <IChild>().Apply(x => x.Parent = this); e.OldItems.OfType <IChild>().Apply(x => x.Parent = null); break; case NotifyCollectionChangedAction.Reset: items.OfType <IChild>().Apply(x => x.Parent = this); break; } }; }
private void OnBlockSymbolsRemoveAtEventHandler(int indexAt, BlockSymbol blockSymbol) { var toBeRemoved = _symbolVms.OfType <BlockViewModel>().FirstOrDefault(b => b.Id == blockSymbol.Id); if (toBeRemoved != null) { SymbolVms.Remove(toBeRemoved); } }
/// <summary> /// Initializes a new instance of the <see cref="Conductor<T>.Collection.AllActive"/> class. /// </summary> public AllActive() { items.CollectionChanged += (s, e) => { switch (e.Action) { case NotifyCollectionChangedAction.Add: e.NewItems.OfType <IChild>().Apply(x => x.Parent = this); break; case NotifyCollectionChangedAction.Remove: e.OldItems.OfType <IChild>().Apply(x => x.Parent = null); break; case NotifyCollectionChangedAction.Replace: e.NewItems.OfType <IChild>().Apply(x => x.Parent = this); e.OldItems.OfType <IChild>().Apply(x => x.Parent = null); break; case NotifyCollectionChangedAction.Reset: items.OfType <IChild>().Apply(x => x.Parent = this); break; } }; CloseGuard = () => { var tcs = new TaskCompletionSource <bool>(); CloseStrategy.Execute(items.ToList(), (canClose, closable) => { if (!canClose && closable.Any()) { closable.OfType <IDeactivate>().Apply(x => x.Deactivate(true)); items.RemoveRange(closable); } tcs.SetResult(canClose); }); return(tcs.Task); }; }
/// <summary> /// Initializes a new instance of the <see cref="Conductor<T>.Collection.OneActive"/> class. /// </summary> public OneActive() { items.CollectionChanged += (s, e) => { switch (e.Action) { case NotifyCollectionChangedAction.Add: e.NewItems.OfType <IChild>().Apply(x => x.Parent = this); break; case NotifyCollectionChangedAction.Remove: e.OldItems.OfType <IChild>().Apply(x => x.Parent = null); break; case NotifyCollectionChangedAction.Replace: e.NewItems.OfType <IChild>().Apply(x => x.Parent = this); e.OldItems.OfType <IChild>().Apply(x => x.Parent = null); break; case NotifyCollectionChangedAction.Reset: items.OfType <IChild>().Apply(x => x.Parent = this); break; } }; CloseGuard = () => { var tcs = new TaskCompletionSource <bool>(); CloseStrategy.Execute(items.ToList(), (canClose, closable) => { if (!canClose && closable.Any()) { if (closable.Contains(ActiveItem)) { var list = items.ToList(); var next = ActiveItem; do { var previous = next; next = DetermineNextItemToActivate(list, list.IndexOf(previous)); list.Remove(previous); } while (closable.Contains(next)); var previousActive = ActiveItem; ChangeActiveItem(next, true); items.Remove(previousActive); var stillToClose = closable.ToList(); stillToClose.Remove(previousActive); closable = stillToClose; } closable.OfType <IDeactivate>().Apply(x => x.Deactivate(true)); items.RemoveRange(closable); } tcs.SetResult(canClose); }); return(tcs.Task); }; }