protected virtual void NotifyBatch() { var changes = this.batch; this.batch = null; if (changes == null) { return; } var args = GetCollectionChangedEventArgs(changes); if (args != null) { switch (args.Action) { case NotifyCollectionChangedAction.Add: case NotifyCollectionChangedAction.Remove: case NotifyCollectionChangedAction.Reset: this.OnPropertyChanged(CountPropertyChangedEventArgs); this.OnPropertyChanged(IndexerPropertyChangedEventArgs); break; case NotifyCollectionChangedAction.Replace: case NotifyCollectionChangedAction.Move: this.OnPropertyChanged(IndexerPropertyChangedEventArgs); break; default: throw new ArgumentOutOfRangeException(); } this.OnCollectionChanged(args); } }
public void EndBatch() { var tempBatch = batch; batch = null; if (tempBatch.Changes.Count > 0) //if batch is empty, ignore it { RecordChange(tempBatch); } }
private static string GetBatchDescription(SILayout layout, BatchChange batchChange) { switch (batchChange.Name) { case "NumberOfFrets": { var propChange = batchChange.ChangedProperties .FirstOrDefault(x => x.Property == nameof(SIString.NumberOfFrets)); if (propChange != null && propChange.NewValue is int fretCount) { return($"{Localizations.LayoutProperty_NumberOfFrets}: {fretCount}"); } return(Localizations.LayoutProperty_NumberOfFrets); } case "AddStrings": case "RemoveStrings": { var lastChange = batchChange.LayoutChanges .OfType <CollectionChange>() .Where(x => x.ElementType == typeof(SIString)) .LastOrDefault(); if (lastChange != null) { return($"{Localizations.LayoutProperty_NumberOfStrings}: {lastChange.CollectionCount}"); } break; } } if (batchChange.Component != null) { var marginChange = batchChange.ChangedProperties.FirstOrDefault(x => x.Component is FingerboardMargin); if (marginChange != null) { return(GetFingerboardMarginDescription(layout, batchChange.Name, marginChange)); } } return(null); }
public IDisposable StartBatch(string changeDescription) { batch = new BatchChange(changeDescription, this); return batch; }