MainWindow skeleton
This commit is contained in:
@@ -2,6 +2,7 @@ namespace FileTime.Core.Models
|
||||
{
|
||||
public interface IContainer : IItem
|
||||
{
|
||||
IReadOnlyList<IAbsolutePath> Items { get; }
|
||||
IObservable<IReadOnlyList<IAbsolutePath>> Items { get; }
|
||||
IObservable<bool> IsLoading { get; }
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
using System.Reactive.Linq;
|
||||
using System.Reactive.Subjects;
|
||||
using FileTime.Core.Enums;
|
||||
using FileTime.Core.Services;
|
||||
|
||||
@@ -16,5 +18,9 @@ namespace FileTime.Core.Models
|
||||
bool CanRename,
|
||||
string? Attributes,
|
||||
IContentProvider Provider,
|
||||
IReadOnlyList<IAbsolutePath> Items) : IContainer;
|
||||
IObservable<IReadOnlyList<IAbsolutePath>> Items) : IContainer
|
||||
{
|
||||
BehaviorSubject<bool> IsLoading { get; } = new BehaviorSubject<bool>(false);
|
||||
IObservable<bool> IContainer.IsLoading => IsLoading.AsObservable();
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
using System.Reactive.Linq;
|
||||
using System.Reactive.Subjects;
|
||||
using FileTime.Core.Enums;
|
||||
using FileTime.Core.Models;
|
||||
|
||||
@@ -5,9 +7,9 @@ namespace FileTime.Core.Services
|
||||
{
|
||||
public abstract class ContentProviderBase : IContentProvider
|
||||
{
|
||||
protected List<IAbsolutePath> Items { get; set; } = new List<IAbsolutePath>();
|
||||
protected BehaviorSubject<IReadOnlyList<IAbsolutePath>> Items { get; } = new BehaviorSubject<IReadOnlyList<IAbsolutePath>>(new List<IAbsolutePath>());
|
||||
|
||||
IReadOnlyList<IAbsolutePath> IContainer.Items => Items;
|
||||
IObservable<IReadOnlyList<IAbsolutePath>> IContainer.Items => Items;
|
||||
|
||||
public string Name { get; }
|
||||
|
||||
@@ -33,6 +35,10 @@ namespace FileTime.Core.Services
|
||||
|
||||
public string? Attributes => null;
|
||||
|
||||
protected BehaviorSubject<bool> IsLoading { get; } = new(false);
|
||||
|
||||
IObservable<bool> IContainer.IsLoading => IsLoading.AsObservable();
|
||||
|
||||
protected ContentProviderBase(string name)
|
||||
{
|
||||
DisplayName = Name = name;
|
||||
|
||||
@@ -15,31 +15,38 @@ namespace FileTime.Core.Services
|
||||
public Tab()
|
||||
{
|
||||
CurrentLocation = _currentLocation.AsObservable();
|
||||
CurrentItems = _currentLocation
|
||||
.Select(c =>
|
||||
Observable.FromAsync(async () =>
|
||||
c == null
|
||||
? Enumerable.Empty<IItem>()
|
||||
: await c.Items
|
||||
.ToAsyncEnumerable()
|
||||
.SelectAwait(
|
||||
async i =>
|
||||
{
|
||||
try
|
||||
CurrentItems =
|
||||
Observable.Merge(
|
||||
_currentLocation
|
||||
.Where(c => c is not null)
|
||||
.Select(c => c!.Items)
|
||||
.Switch()
|
||||
.Select(
|
||||
i => Observable.FromAsync(async () =>
|
||||
await i
|
||||
.ToAsyncEnumerable()
|
||||
.SelectAwait(
|
||||
async i =>
|
||||
{
|
||||
//TODO: force create by AbsolutePath name
|
||||
return await i.ContentProvider.GetItemByFullNameAsync(i.Path);
|
||||
try
|
||||
{
|
||||
//TODO: force create by AbsolutePath name
|
||||
return await i.ContentProvider.GetItemByFullNameAsync(i.Path);
|
||||
}
|
||||
catch { return null!; }
|
||||
}
|
||||
catch { return null!; }
|
||||
}
|
||||
|
||||
)
|
||||
.Where(i => i != null)
|
||||
.ToListAsync()
|
||||
)
|
||||
.Where(i => i != null)
|
||||
.ToListAsync()
|
||||
)
|
||||
)
|
||||
.Merge(Constants.MaximumObservableMergeOperations);
|
||||
CurrentSelectedItem = CurrentLocation.Select(GetSelectedItemByLocation).Merge(_currentSelectedItem).Throttle(TimeSpan.FromMilliseconds(500));
|
||||
)
|
||||
.Merge(Constants.MaximumObservableMergeOperations),
|
||||
_currentLocation
|
||||
.Where(c => c is null)
|
||||
.Select(c => Enumerable.Empty<IItem>())
|
||||
);
|
||||
|
||||
CurrentSelectedItem = CurrentLocation.Select(GetSelectedItemByLocation).Switch().Merge(_currentSelectedItem).Throttle(TimeSpan.FromMilliseconds(500));
|
||||
}
|
||||
|
||||
public void Init(IContainer currentLocation)
|
||||
@@ -47,9 +54,9 @@ namespace FileTime.Core.Services
|
||||
_currentLocation.OnNext(currentLocation);
|
||||
}
|
||||
|
||||
private IAbsolutePath? GetSelectedItemByLocation(IContainer? currentLocation)
|
||||
private IObservable<IAbsolutePath?> GetSelectedItemByLocation(IContainer? currentLocation)
|
||||
{
|
||||
return currentLocation?.Items[0];
|
||||
return currentLocation?.Items?.Select(i => i.FirstOrDefault()) ?? Observable.Never((IAbsolutePath?)null);
|
||||
}
|
||||
|
||||
public void ChangeLocation(IContainer newLocation)
|
||||
|
||||
Reference in New Issue
Block a user