Timeless refactor
This commit is contained in:
@@ -3,22 +3,30 @@ using System.Reactive.Subjects;
|
||||
using DynamicData;
|
||||
using DynamicData.Alias;
|
||||
using FileTime.Core.Models;
|
||||
using FileTime.Core.Timeline;
|
||||
|
||||
namespace FileTime.Core.Services;
|
||||
|
||||
public class Tab : ITab
|
||||
{
|
||||
private readonly ITimelessContentProvider _timelessContentProvider;
|
||||
private readonly BehaviorSubject<IContainer?> _currentLocation = new(null);
|
||||
private readonly BehaviorSubject<IAbsolutePath?> _currentSelectedItem = new(null);
|
||||
private readonly BehaviorSubject<AbsolutePath?> _currentSelectedItem = new(null);
|
||||
private readonly SourceList<ItemFilter> _itemFilters = new();
|
||||
private IAbsolutePath? _currentSelectedItemCached;
|
||||
private AbsolutePath? _currentSelectedItemCached;
|
||||
private PointInTime _currentPointInTime;
|
||||
|
||||
public IObservable<IContainer?> CurrentLocation { get; }
|
||||
public IObservable<IObservable<IChangeSet<IItem>>?> CurrentItems { get; }
|
||||
public IObservable<IAbsolutePath?> CurrentSelectedItem { get; }
|
||||
public IObservable<AbsolutePath?> CurrentSelectedItem { get; }
|
||||
|
||||
public Tab()
|
||||
public Tab(ITimelessContentProvider timelessContentProvider)
|
||||
{
|
||||
_timelessContentProvider = timelessContentProvider;
|
||||
_currentPointInTime = null!;
|
||||
|
||||
_timelessContentProvider.CurrentPointInTime.Subscribe(p => _currentPointInTime = p);
|
||||
|
||||
CurrentLocation = _currentLocation.DistinctUntilChanged().Publish(null).RefCount();
|
||||
CurrentItems =
|
||||
Observable.Merge(
|
||||
@@ -32,9 +40,9 @@ public class Tab : ITab
|
||||
(items, filters) => items?.Where(i => filters.All(f => f.Filter(i)))),
|
||||
CurrentLocation
|
||||
.Where(c => c is null)
|
||||
.Select(_ => (IObservable<IChangeSet<IItem>>?) null)
|
||||
.Select(_ => (IObservable<IChangeSet<IItem>>?)null)
|
||||
)
|
||||
.Publish((IObservable<IChangeSet<IItem>>?) null)
|
||||
.Publish((IObservable<IChangeSet<IItem>>?)null)
|
||||
.RefCount();
|
||||
|
||||
CurrentSelectedItem =
|
||||
@@ -66,22 +74,22 @@ public class Tab : ITab
|
||||
});
|
||||
}
|
||||
|
||||
private async Task<IItem> MapItem(IAbsolutePath item) => await item.ResolveAsync(true);
|
||||
private async Task<IItem> MapItem(AbsolutePath item) => await item.ResolveAsync(true);
|
||||
|
||||
public void Init(IContainer currentLocation)
|
||||
{
|
||||
_currentLocation.OnNext(currentLocation);
|
||||
}
|
||||
|
||||
private static IAbsolutePath? GetSelectedItemByItems(IEnumerable<IItem> items)
|
||||
private AbsolutePath? GetSelectedItemByItems(IEnumerable<IItem> items)
|
||||
{
|
||||
//TODO:
|
||||
return new AbsolutePath(items.First());
|
||||
return new AbsolutePath(_timelessContentProvider, items.First());
|
||||
}
|
||||
|
||||
public void SetCurrentLocation(IContainer newLocation) => _currentLocation.OnNext(newLocation);
|
||||
|
||||
public void SetSelectedItem(IAbsolutePath newSelectedItem) => _currentSelectedItem.OnNext(newSelectedItem);
|
||||
public void SetSelectedItem(AbsolutePath newSelectedItem) => _currentSelectedItem.OnNext(newSelectedItem);
|
||||
|
||||
public void AddItemFilter(ItemFilter filter) => _itemFilters.Add(filter);
|
||||
public void RemoveItemFilter(ItemFilter filter) => _itemFilters.Remove(filter);
|
||||
@@ -95,7 +103,8 @@ public class Tab : ITab
|
||||
public async Task OpenSelected()
|
||||
{
|
||||
if (_currentSelectedItemCached == null) return;
|
||||
var resolvedSelectedItem = await _currentSelectedItemCached.ContentProvider.GetItemByFullNameAsync(_currentSelectedItemCached.Path);
|
||||
var resolvedSelectedItem =
|
||||
await _currentSelectedItemCached.TimelessProvider.GetItemByFullNameAsync(_currentSelectedItemCached.Path, _currentPointInTime);
|
||||
|
||||
if (resolvedSelectedItem is not IContainer resolvedContainer) return;
|
||||
SetCurrentLocation(resolvedContainer);
|
||||
|
||||
Reference in New Issue
Block a user