diff --git a/src/DynamicTreeDataGrid/DynamicFlatTreeDataGridSource.cs b/src/DynamicTreeDataGrid/DynamicFlatTreeDataGridSource.cs index cf7c01d..47f4dbf 100644 --- a/src/DynamicTreeDataGrid/DynamicFlatTreeDataGridSource.cs +++ b/src/DynamicTreeDataGrid/DynamicFlatTreeDataGridSource.cs @@ -13,98 +13,94 @@ namespace DynamicTreeDataGrid; public class DynamicFlatTreeDataGridSource : ITreeDataGridSource - where TModel : class where TModelKey : notnull { - private readonly FlatTreeDataGridSource treeDataGridSourceImplementation; - private readonly IObservable> _changeSet; - private readonly IObservable> _comparer; - private readonly ISubject> _comparerSource = new Subject>(); + where TModel : class where TModelKey : notnull { + private readonly FlatTreeDataGridSource treeDataGridSourceImplementation; + private readonly IObservable> _changeSet; + private readonly IObservable> _sort; + private readonly ISubject> _sortSource = new Subject>(); - private readonly ISubject> _filterSource = new BehaviorSubject>(_ => true); - private readonly IObservable> _itemsFilter; + private readonly ISubject> _filterSource = new BehaviorSubject>(_ => true); + private readonly IObservable> _itemsFilter; - public DynamicFlatTreeDataGridSource(IObservable> changes) { - _itemsFilter = _filterSource; - // Use RefCount to avoid duplicate work - _changeSet = changes.RefCount(); - _comparer = _comparerSource; - TotalCount = _changeSet.Count(); - var filteredChanges = _changeSet - // .Filter(model => model) // Consider using DynamicData.PLinq for filtering. - .Do(_ => Console.WriteLine("FILTERINGGGGGGGGG")); + public DynamicFlatTreeDataGridSource(IObservable> changes) { + _itemsFilter = _filterSource; - FilteredCount = filteredChanges.Count(); + // Use RefCount to avoid duplicate work + _changeSet = changes.RefCount(); + _sort = _sortSource; + TotalCount = _changeSet.Count(); - var myOperation = filteredChanges - .Filter(_itemsFilter) + var filteredChanges = _changeSet.Filter(_itemsFilter); + FilteredCount = filteredChanges.Count(); - // .Filter(trade=>trade.Status == TradeStatus.Live) - .Sort(_comparer) - .Bind(out var list) - .DisposeMany() - .Subscribe(set => Console.WriteLine("Changeset changed.")); + var myOperation = filteredChanges.Sort(_sort) + .Bind(out var list) + .DisposeMany() + .Subscribe(set => Console.WriteLine("Changeset changed.")); - treeDataGridSourceImplementation = new FlatTreeDataGridSource(list); - // TODO: Setup Sorted event for treeDataGridSourceImplementation? - } + treeDataGridSourceImplementation = new FlatTreeDataGridSource(list); - public IObservable FilteredCount { get; set; } + // TODO: Setup Sorted event for treeDataGridSourceImplementation? + } - public IObservable TotalCount { get; set; } + public IObservable FilteredCount { get; set; } - public event PropertyChangedEventHandler? PropertyChanged { - add => treeDataGridSourceImplementation.PropertyChanged += value; - remove => treeDataGridSourceImplementation.PropertyChanged -= value; - } + public IObservable TotalCount { get; set; } - public void DragDropRows(ITreeDataGridSource source, - IEnumerable indexes, - IndexPath targetIndex, - TreeDataGridRowDropPosition position, - DragDropEffects effects) { - ((ITreeDataGridSource)treeDataGridSourceImplementation).DragDropRows(source, indexes, targetIndex, position, effects); - } + public event PropertyChangedEventHandler? PropertyChanged { + add => treeDataGridSourceImplementation.PropertyChanged += value; + remove => treeDataGridSourceImplementation.PropertyChanged -= value; + } - public IEnumerable? GetModelChildren(object model) => ( - (ITreeDataGridSource)treeDataGridSourceImplementation).GetModelChildren(model); + public void DragDropRows(ITreeDataGridSource source, + IEnumerable indexes, + IndexPath targetIndex, + TreeDataGridRowDropPosition position, + DragDropEffects effects) { + ((ITreeDataGridSource)treeDataGridSourceImplementation).DragDropRows(source, indexes, targetIndex, position, + effects); + } - public bool SortBy(IColumn? column, ListSortDirection direction) - { - if (column is IColumn typedColumn) - { - if (!Columns.Contains(typedColumn)) - return true; + public IEnumerable? GetModelChildren(object model) => + ((ITreeDataGridSource)treeDataGridSourceImplementation).GetModelChildren(model); - var comparer = typedColumn.GetComparison(direction); + public bool SortBy(IColumn? column, ListSortDirection direction) { + if (column is IColumn typedColumn) { + if (!Columns.Contains(typedColumn)) + return true; - if (comparer is not null) - { - var comparerInstance = new FuncComparer(comparer); - // Trigger a new sort notification. - _comparerSource.OnNext(comparerInstance); - Sorted?.Invoke(); - foreach (var c in Columns) - c.SortDirection = c == column ? direction : null; - } - return true; - } + var comparer = typedColumn.GetComparison(direction); - return false; - } + if (comparer is not null) { + var comparerInstance = new FuncComparer(comparer); - public ColumnList Columns => treeDataGridSourceImplementation.Columns; - IColumns ITreeDataGridSource.Columns => Columns; + // Trigger a new sort notification. + _sortSource.OnNext(comparerInstance); + Sorted?.Invoke(); + foreach (var c in Columns) + c.SortDirection = c == column ? direction : null; + } - public IRows Rows => treeDataGridSourceImplementation.Rows; + return true; + } - public ITreeDataGridSelection? Selection => treeDataGridSourceImplementation.Selection; + return false; + } - public bool IsHierarchical => treeDataGridSourceImplementation.IsHierarchical; + public ColumnList Columns => treeDataGridSourceImplementation.Columns; + IColumns ITreeDataGridSource.Columns => Columns; - public bool IsSorted => treeDataGridSourceImplementation.IsSorted; + public IRows Rows => treeDataGridSourceImplementation.Rows; - IEnumerable ITreeDataGridSource.Items => treeDataGridSourceImplementation.Items; + public ITreeDataGridSelection? Selection => treeDataGridSourceImplementation.Selection; - IEnumerable ITreeDataGridSource.Items => ((ITreeDataGridSource)treeDataGridSourceImplementation).Items; + public bool IsHierarchical => treeDataGridSourceImplementation.IsHierarchical; - public event Action? Sorted; + public bool IsSorted => treeDataGridSourceImplementation.IsSorted; + + IEnumerable ITreeDataGridSource.Items => treeDataGridSourceImplementation.Items; + + IEnumerable ITreeDataGridSource.Items => ((ITreeDataGridSource)treeDataGridSourceImplementation).Items; + + public event Action? Sorted; } diff --git a/src/DynamicTreeDataGrid/State/ColumnState.cs b/src/DynamicTreeDataGrid/State/ColumnState.cs new file mode 100644 index 0000000..cd3ad98 --- /dev/null +++ b/src/DynamicTreeDataGrid/State/ColumnState.cs @@ -0,0 +1,3 @@ +namespace DynamicTreeDataGrid.State; + +public class ColumnState { } diff --git a/src/DynamicTreeDataGrid/State/GridState.cs b/src/DynamicTreeDataGrid/State/GridState.cs new file mode 100644 index 0000000..592e9b3 --- /dev/null +++ b/src/DynamicTreeDataGrid/State/GridState.cs @@ -0,0 +1,5 @@ +namespace DynamicTreeDataGrid.State; + +public class GridState { + public IList ColumnStates { get; set; } +} \ No newline at end of file