diff --git a/WDE.HistoryWindow/ViewModels/HistoryViewModel.cs b/WDE.HistoryWindow/ViewModels/HistoryViewModel.cs index e89ed3591..dc5e2143a 100644 --- a/WDE.HistoryWindow/ViewModels/HistoryViewModel.cs +++ b/WDE.HistoryWindow/ViewModels/HistoryViewModel.cs @@ -11,18 +11,21 @@ using WDE.Common.Events; using WDE.Common.History; using Prism.Ioc; +using WDE.Common.Managers; namespace WDE.HistoryWindow.ViewModels { - internal class Valuea + internal class HistoryEvent { public string Name { get; set; } - public bool Aaaa { get; set; } + public bool IsFromFuture { get; set; } } internal class HistoryViewModel : BindableBase { - public ObservableCollection Items { get; set; } = new ObservableCollection(); + public ObservableCollection Items { get; set; } = new ObservableCollection(); + + private IDocument previousDocument; private string _title; public string Title @@ -31,56 +34,43 @@ public string Title set { SetProperty(ref _title, value); } } - ~HistoryViewModel() - { - - } - public HistoryViewModel(IEventAggregator eventAggregator) { eventAggregator.GetEvent().Subscribe(doc => { - if (doc.History == null) - return; + Items.Clear(); - doc.History.Past.CollectionChanged += (sender, e) => + if (previousDocument != null) { - Items.Clear(); - foreach (var past in doc.History.Past) - { - Items.Add(new Valuea() { Name = past.GetDescription(), Aaaa = false }); - } + previousDocument.History.Past.CollectionChanged -= HistoryCollectionChanged; + previousDocument.History.Future.CollectionChanged -= HistoryCollectionChanged; + previousDocument = null; + } - foreach (var past in doc.History.Future) - { - Items.Add(new Valuea() { Name = past.GetDescription(), Aaaa = true }); - } - }; - doc.History.Future.CollectionChanged += (sender, e) => - { - Items.Clear(); - foreach (var past in doc.History.Past) - { - Items.Add(new Valuea() { Name = past.GetDescription(), Aaaa = false }); - } + if (doc == null || doc.History == null) + return; - foreach (var past in doc.History.Future) - { - Items.Add(new Valuea() { Name = past.GetDescription(), Aaaa = true }); - } - }; + previousDocument = doc; - Items.Clear(); - foreach (var past in doc.History.Past) - { - Items.Add(new Valuea() { Name = past.GetDescription(), Aaaa = false }); - } + doc.History.Past.CollectionChanged += HistoryCollectionChanged; + doc.History.Future.CollectionChanged += HistoryCollectionChanged; - foreach (var past in doc.History.Future) - { - Items.Add(new Valuea() { Name = past.GetDescription(), Aaaa = true }); - } + HistoryCollectionChanged(null, null); }); } + + private void HistoryCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) + { + Items.Clear(); + foreach (var past in previousDocument.History.Past) + { + Items.Add(new HistoryEvent() { Name = past.GetDescription(), IsFromFuture = false }); + } + + foreach (var past in previousDocument.History.Future) + { + Items.Add(new HistoryEvent() { Name = past.GetDescription(), IsFromFuture = true }); + } + } } } diff --git a/WDE.HistoryWindow/Views/HistoryView.xaml b/WDE.HistoryWindow/Views/HistoryView.xaml index 157f823e9..1ca3fc0a3 100644 --- a/WDE.HistoryWindow/Views/HistoryView.xaml +++ b/WDE.HistoryWindow/Views/HistoryView.xaml @@ -23,7 +23,7 @@