diff --git a/src/client/spark/mspark/Ladder/LadderVM.cs b/src/client/spark/mspark/Ladder/LadderVM.cs index bd2c2cfd9..6740e1f00 100644 --- a/src/client/spark/mspark/Ladder/LadderVM.cs +++ b/src/client/spark/mspark/Ladder/LadderVM.cs @@ -235,8 +235,8 @@ namespace mbts.spark { ProtoBuf.Serializer.SerializeWithLengthPrefix(output, header, ProtoBuf.PrefixStyle.Fixed32); } - public override void Dispose() { - base.Dispose(); + protected override void Dispose(bool disposing) { + base.Dispose(disposing); _timer.Stop(); } } diff --git a/src/client/spark/mspark/MarketView/MarketViewView.xaml b/src/client/spark/mspark/MarketView/MarketViewView.xaml index f896374ae..2533ea67c 100644 --- a/src/client/spark/mspark/MarketView/MarketViewView.xaml +++ b/src/client/spark/mspark/MarketView/MarketViewView.xaml @@ -9,8 +9,8 @@ - - + + + + + diff --git a/src/client/spark/view/Resources/Converters.xaml b/src/client/spark/view/Resources/Converters.xaml index 295c08793..9738c1447 100644 --- a/src/client/spark/view/Resources/Converters.xaml +++ b/src/client/spark/view/Resources/Converters.xaml @@ -2,7 +2,10 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:uc="clr-namespace:mbts.ui" xmlns:u="clr-namespace:mbts.ui" - xmlns:cv="clr-namespace:mbts.ui.converters"> + xmlns:cv="clr-namespace:mbts.ui.converters" + xmlns:usp="clr-namespace:mbts.ui.spark" + xmlns:uspcv="clr-namespace:mbts.ui.spark.converters" + xmlns:sys="clr-namespace:System;assembly=mscorlib"> @@ -47,4 +50,10 @@ + + + + + 0 + 0 diff --git a/src/client/spark/view/Utility/ColdObseravbleProperty.cs b/src/client/spark/view/Utility/ColdObseravbleProperty.cs new file mode 100644 index 000000000..80ce79213 --- /dev/null +++ b/src/client/spark/view/Utility/ColdObseravbleProperty.cs @@ -0,0 +1,17 @@ +using System; +using System.Reactive.Linq; +using System.Reactive.Subjects; + +namespace mbts.ui.utilities +{ + public class ColdObseravbleProperty : IObservable, IDisposable { + private readonly Subject _subject = new Subject(); + private T _value; + public T Value { get => _value; set => set(value); } + public void set(T value) { _subject.OnNext(_value = value); } + public IDisposable Subscribe(IObserver observer) { + return (_value != null ? _subject.StartWith(_value) : _subject.AsObservable()).Subscribe(observer); + } + public void Dispose() { _subject.Dispose(); } + } +} \ No newline at end of file diff --git a/src/client/spark/view/Utility/Command.cs b/src/client/spark/view/Utility/Command.cs index a1d0adb5c..3c4ac450d 100644 --- a/src/client/spark/view/Utility/Command.cs +++ b/src/client/spark/view/Utility/Command.cs @@ -9,6 +9,8 @@ namespace mbts.ui.utility { public static readonly ICommand Empty = new DelegateCommand(() => { }); + public static readonly ICommand Disabled = new DelegateCommand(() => { }, () => false); + public static ICommand AddShellWindow(IWindowManager wm, Func factory) { return new DelegateCommand(() => wm.Windows.Add(factory())); } public static ICommand ExportToCSV(Func> csv_rows) { return ExportToCSV(_ => csv_rows()); } diff --git a/src/client/spark/view/Utility/RXObservableCollection.cs b/src/client/spark/view/Utility/RXObservableCollection.cs index c75cd4c7c..6dc2c8705 100644 --- a/src/client/spark/view/Utility/RXObservableCollection.cs +++ b/src/client/spark/view/Utility/RXObservableCollection.cs @@ -8,9 +8,9 @@ namespace mbts.ui.utility { public class RXObservableCollection : ObservableCollection, IObserver>, IDisposable { - public RXObservableCollection(IObservable> data_stream) : this(data_stream, SynchronizationContext.Current) { } - public RXObservableCollection(IObservable> data_stream, SynchronizationContext context) { - _sub = data_stream.ObserveOn(context).Subscribe(this); + public RXObservableCollection(IObservable> data) : this(data, SynchronizationContext.Current) { } + public RXObservableCollection(IObservable> data, SynchronizationContext context) { + _sub = (context != null ? data.ObserveOn(context) : data).Subscribe(this); } private IDisposable _sub; diff --git a/src/client/spark/view/Utility/SelectableViewModelBase.cs b/src/client/spark/view/Utility/SelectableViewModelBase.cs new file mode 100644 index 000000000..68ff68575 --- /dev/null +++ b/src/client/spark/view/Utility/SelectableViewModelBase.cs @@ -0,0 +1,36 @@ +using mbts.utils; +using System; +using System.Collections; +using System.Collections.Generic; +using System.Reactive.Linq; + +namespace mbts.ui.shell +{ + public abstract class SelectableViewModelBase : ViewModelBaseWithValidation, ISelectable + { + protected SelectableViewModelBase() { + _is_selected = backing(nameof(is_selected), false); + } + private readonly Property _is_selected; + public bool is_selected { get => _is_selected.Value; set => _is_selected.set(value); } + public IObservable observe_is_selected() { return _is_selected.Select(vals => vals.newval); } + } + + public class SelectableViewModelBase : SelectableViewModelBase, IComparable>, IComparable + { + public SelectableViewModelBase(T initial_value = default(T)) { + _value = backing(nameof(value), initial_value); + } + private readonly Property _value; + public T value { get => _value.Value; set => _value.set(value); } + + public int CompareTo(SelectableViewModelBase other) { + if (other == null) return -1; + if (other.value == null) return value == null ? 0 : -1; + var comp = Comparer.Default; + return comp == null ? 0 : comp.Compare(value, other.value); + } + + public int CompareTo(object obj) { return CompareTo(obj as SelectableViewModelBase); } + } +} \ No newline at end of file