domain filter undoes selection changes on close (if not applied first)

This commit is contained in:
John Colvin committed 2018-03-18 19:48:16 -04:00
1 parent 69e337bcd2
commit 81941cba4e
2 files changed
+48 -13

No files matched your search

@@ -1,11 +1,13 @@
using bts.api.core;
using mbts.collections;
using mbts.ui.shell;
using mbts.ui.utilities;
using mbts.ui.utility;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Linq;
using System.Reactive.Linq;
@@ -87,17 +89,19 @@ namespace mbts.spark.filters {
public void Dispose() =>
Disposable.dispose(_resources);
protected override void _apply() =>
_raise_filter_changed();
protected override void _clear() {
_destroy_snapshot();
_selected_items.Clear();
_close();
_raise_filter_changed();
}
protected override bool _get_active() =>
_selected_items.Count > 0;
protected override IObjSnapshot _get_snapshot() =>
new SelectedItemsSnapshot<TValue>(_selected_items, _items);
public override TState get_state() =>
_get_state(_selected_items);
@@ -141,11 +145,10 @@ namespace mbts.spark.filters {
public void Dispose() =>
Disposable.dispose(ref _dispose);
protected override void _apply() =>
_raise_filter_changed();
protected override void _clear() {
_destroy_snapshot();
_selected_items.Clear();
_close();
_raise_filter_changed();
}
@@ -159,7 +162,7 @@ namespace mbts.spark.filters {
_get_state(_selected_items);
protected override void _load_state_internal(TState state) =>
_on_state_loaded?.Invoke(_load_state(state));
_on_state_loaded?.Invoke(_load_state(state));
}
class DiscreteValuesOneofFilterVM<TRow, TValue, TState> : FilterVMBase<TRow, IEnumerable<TValue>, TState> {
@@ -198,9 +201,19 @@ namespace mbts.spark.filters {
public void Dispose() =>
Disposable.dispose(_resources);
protected override void _clear() {
_destroy_snapshot();
_selected_items.Clear();
_close();
_raise_filter_changed();
}
protected override bool _get_active() =>
_selected_items.Count > 0;
protected override IObjSnapshot _get_snapshot() =>
new SelectedItemsSnapshot<TValue>(_selected_items, _items);
public override TState get_state() =>
_get_state(_selected_items);
@@ -214,6 +227,28 @@ namespace mbts.spark.filters {
_raise_filter_changed();
}
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
class SelectedItemsSnapshot<TValue> : ViewModelBase.IObjSnapshot {
readonly IList<TValue> _selected_items;
readonly IReadOnlyList<TValue> _selected_items_snapshot;
readonly IList<TValue> _items;
public SelectedItemsSnapshot(IList<TValue> selected_items, IList<TValue> items) {
_selected_items = selected_items;
_selected_items_snapshot = selected_items.ToReadOnlyList();
_items = items;
}
public bool revert { get; set; }
public void Dispose() {
if (revert)
_selected_items.sync_with(_selected_items_snapshot.Intersect(_items));
}
}
static class DiscreteValuesFilterHandlers {
public static NotifyCollectionChangedEventHandler items<TValue, TItemCollection>(
TItemCollection items, ObservableCollectionEx<TValue> selected_items, ICollection<TValue> desired_selected_items)
@@ -15,7 +15,7 @@ namespace mbts.spark.filters {
_get_row_val = get_row_val;
this.prop_name = prop_name;
_active = backing(nameof(active), () => HasErrors ? new bool?() : _get_active());
_snapshot = detect_property_changes();
_snapshot = _get_snapshot();
apply = new DelegateCommand(_apply);
cancel = new DelegateCommand(_cancel);
clear = new DelegateCommand(_clear);
@@ -31,7 +31,7 @@ namespace mbts.spark.filters {
set {
_open = value;
if (_open)
_snapshot = detect_property_changes();
_snapshot = _get_snapshot();
else if (_snapshot != null) {
RequestUpdate?.Invoke();
_snapshot.revert = true;
@@ -48,7 +48,7 @@ namespace mbts.spark.filters {
public void load_state(TState state) {
_load_state_internal(state);
_snapshot = detect_property_changes();
_snapshot = _get_snapshot();
_validate();
_raise_filter_changed();
}
@@ -72,7 +72,7 @@ namespace mbts.spark.filters {
if (_snapshot != null)
_snapshot.revert = true;
Disposable.dispose(ref _snapshot);
_snapshot = detect_property_changes();
_snapshot = _get_snapshot();
open = false;
RaisePropertyChanged(nameof(open));
}
@@ -81,12 +81,12 @@ namespace mbts.spark.filters {
protected IDisposable _clear_properties(bool close=true) {
_snapshot = null;
var dpc = detect_property_changes();
var dpc = _get_snapshot();
return Disposable.Create(() => {
dpc.Dispose();
_validate();
_raise_filter_changed();
_snapshot = detect_property_changes();
_snapshot = _get_snapshot();
});
}