The vs grid settings editor code had already been ported over, but never actually worked
85 lines
2.7 KiB
C#
85 lines
2.7 KiB
C#
namespace mbts.spark {
|
|
using mbts.ui;
|
|
using mbts.ui.shell;
|
|
|
|
using System;
|
|
using System.Reactive.Linq;
|
|
using System.Windows.Input;
|
|
|
|
class VolGridCellVM : DisposableViewModelBase {
|
|
readonly Property<object> _candidate_value;
|
|
readonly Property<object> _committed_value;
|
|
readonly Property<bool> _is_dirty;
|
|
|
|
public VolGridCellVM(string column_id) {
|
|
this.column_id = column_id ?? throw new ArgumentNullException(nameof(column_id));
|
|
_committed_value = backing<object>(nameof(committed_value));
|
|
_candidate_value = backing<object>(nameof(candidate_value));
|
|
_is_dirty = backing(nameof(is_dirty),
|
|
_committed_value.observe_current(true)
|
|
.CombineLatest(_candidate_value.observe_current(true))
|
|
.Select(tup => !Equals(tup.First, tup.Second))
|
|
.OnDispatcher());
|
|
}
|
|
|
|
public string column_id { get; }
|
|
|
|
public object committed_value {
|
|
get => _committed_value.Value;
|
|
set => _committed_value.set(value);
|
|
}
|
|
|
|
public object candidate_value {
|
|
get => _candidate_value.Value;
|
|
set => _candidate_value.set(value);
|
|
}
|
|
|
|
public bool is_dirty => _is_dirty.Value;
|
|
|
|
public IObservable<object> observe_candidate(bool start_immediately = false) =>
|
|
_candidate_value.observe_current(start_immediately);
|
|
|
|
public void revert() =>
|
|
candidate_value = committed_value;
|
|
|
|
public override string ToString() =>
|
|
$"column_id: {column_id}, committed: {committed_value}, candidate: {candidate_value}";
|
|
}
|
|
|
|
class VolGridCellVM<T> : VolGridCellVM {
|
|
public VolGridCellVM(string column_id) : base(column_id) { }
|
|
|
|
public VolGridCellVM(string column_id, T committed_value, T candidate_value) : base(column_id) {
|
|
this.committed_value = committed_value;
|
|
this.candidate_value = candidate_value;
|
|
}
|
|
|
|
public new T committed_value {
|
|
get => base.committed_value is T v ? v : default;
|
|
set => base.committed_value = value;
|
|
}
|
|
|
|
public new T candidate_value {
|
|
get => base.candidate_value is T v ? v : default;
|
|
set => base.candidate_value = value;
|
|
}
|
|
}
|
|
|
|
class VolGridTickCellVM : VolGridCellVM {
|
|
ICommand _tick_up_cmd;
|
|
ICommand _tick_down_cmd;
|
|
|
|
public VolGridTickCellVM(string column_id) : base(column_id) { }
|
|
|
|
public event Action<bool> request_tick;
|
|
|
|
public ICommand tick_up_cmd =>
|
|
_tick_up_cmd ??= new DelegateCommand(() =>
|
|
request_tick?.Invoke(true));
|
|
|
|
public ICommand tick_down_cmd =>
|
|
_tick_down_cmd ??= new DelegateCommand(() =>
|
|
request_tick?.Invoke(false));
|
|
}
|
|
}
|