Show children
This commit is contained in:
@@ -10,6 +10,7 @@ namespace FileTime.Core.Models
|
||||
FullName Path { get; }
|
||||
AbsolutePathType Type { get; }
|
||||
|
||||
Task<IItem> ResolveAsync();
|
||||
Task<IItem> ResolveAsync(bool forceResolve = false);
|
||||
Task<IItem?> ResolveAsyncSafe(bool forceResolve = false);
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@ namespace FileTime.Core.Models
|
||||
{
|
||||
public interface IContainer : IItem
|
||||
{
|
||||
IObservable<IReadOnlyList<IAbsolutePath>> Items { get; }
|
||||
IObservable<IEnumerable<IAbsolutePath>?> Items { get; }
|
||||
IObservable<bool> IsLoading { get; }
|
||||
}
|
||||
}
|
||||
@@ -18,5 +18,6 @@ namespace FileTime.Core.Models
|
||||
IContentProvider Provider { get; }
|
||||
string? Attributes { get; }
|
||||
AbsolutePathType Type { get; }
|
||||
IObservable<IEnumerable<Exception>> Exceptions { get; }
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,13 @@
|
||||
using FileTime.Core.Behaviors;
|
||||
using FileTime.Core.Enums;
|
||||
using FileTime.Core.Models;
|
||||
|
||||
namespace FileTime.Core.Services
|
||||
{
|
||||
public interface IContentProvider : IContainer, IOnContainerEnter
|
||||
{
|
||||
Task<IItem> GetItemByFullNameAsync(FullName fullName);
|
||||
Task<IItem> GetItemByNativePathAsync(NativePath nativePath);
|
||||
Task<IItem> GetItemByFullNameAsync(FullName fullName, bool forceResolve = false, AbsolutePathType forceResolvePathType = AbsolutePathType.Unknown);
|
||||
Task<IItem> GetItemByNativePathAsync(NativePath nativePath, bool forceResolve = false, AbsolutePathType forceResolvePathType = AbsolutePathType.Unknown);
|
||||
Task<List<IAbsolutePath>> GetItemsByContainerAsync(FullName fullName);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
using FileTime.Core.Models;
|
||||
using InitableService;
|
||||
using System.Reactive.Subjects;
|
||||
|
||||
namespace FileTime.Core.Services
|
||||
{
|
||||
@@ -8,7 +7,7 @@ namespace FileTime.Core.Services
|
||||
{
|
||||
IObservable<IContainer?> CurrentLocation { get; }
|
||||
IObservable<IAbsolutePath?> CurrentSelectedItem { get; }
|
||||
IObservable<IEnumerable<IItem>> CurrentItems { get; }
|
||||
IObservable<IEnumerable<IItem>?> CurrentItems { get; }
|
||||
|
||||
void SetCurrentLocation(IContainer newLocation);
|
||||
void AddSelectedItemsTransformator(ItemsTransformator transformator);
|
||||
|
||||
@@ -19,10 +19,19 @@ namespace FileTime.Core.Models
|
||||
Type = type;
|
||||
}
|
||||
|
||||
public async Task<IItem> ResolveAsync()
|
||||
public async Task<IItem> ResolveAsync(bool forceResolve = false)
|
||||
{
|
||||
var provider = VirtualContentProvider ?? ContentProvider;
|
||||
return await provider.GetItemByFullNameAsync(Path);
|
||||
return await provider.GetItemByFullNameAsync(Path, forceResolve, Type);
|
||||
}
|
||||
|
||||
public async Task<IItem?> ResolveAsyncSafe(bool forceResolve = false)
|
||||
{
|
||||
try
|
||||
{
|
||||
return await ResolveAsync(forceResolve);
|
||||
}
|
||||
catch { return null; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,8 @@ namespace FileTime.Core.Models
|
||||
bool CanRename,
|
||||
string? Attributes,
|
||||
IContentProvider Provider,
|
||||
IObservable<IReadOnlyList<IAbsolutePath>> Items) : IContainer
|
||||
IObservable<IEnumerable<Exception>> Exceptions,
|
||||
IObservable<IEnumerable<IAbsolutePath>?> Items) : IContainer
|
||||
{
|
||||
BehaviorSubject<bool> IsLoading { get; } = new BehaviorSubject<bool>(false);
|
||||
IObservable<bool> IContainer.IsLoading => IsLoading.AsObservable();
|
||||
|
||||
@@ -15,7 +15,8 @@ namespace FileTime.Core.Models
|
||||
SupportsDelete CanDelete,
|
||||
bool CanRename,
|
||||
string? Attributes,
|
||||
IContentProvider Provider) : IElement
|
||||
IContentProvider Provider,
|
||||
IObservable<IEnumerable<Exception>> Exceptions) : IElement
|
||||
{
|
||||
public AbsolutePathType Type => AbsolutePathType.Element;
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ namespace FileTime.Core.Models
|
||||
bool CanRename,
|
||||
string? Attributes,
|
||||
IContentProvider Provider,
|
||||
IObservable<IEnumerable<Exception>> Exceptions,
|
||||
long Size)
|
||||
: Element(
|
||||
Name,
|
||||
@@ -29,6 +30,7 @@ namespace FileTime.Core.Models
|
||||
CanDelete,
|
||||
CanRename,
|
||||
Attributes,
|
||||
Provider
|
||||
Provider,
|
||||
Exceptions
|
||||
), IFileElement;
|
||||
}
|
||||
@@ -9,7 +9,7 @@ namespace FileTime.Core.Services
|
||||
{
|
||||
protected BehaviorSubject<IReadOnlyList<IAbsolutePath>> Items { get; } = new BehaviorSubject<IReadOnlyList<IAbsolutePath>>(new List<IAbsolutePath>());
|
||||
|
||||
IObservable<IReadOnlyList<IAbsolutePath>> IContainer.Items => Items;
|
||||
IObservable<IEnumerable<IAbsolutePath>> IContainer.Items => Items;
|
||||
|
||||
public string Name { get; }
|
||||
|
||||
@@ -41,14 +41,17 @@ namespace FileTime.Core.Services
|
||||
|
||||
public AbsolutePathType Type => AbsolutePathType.Container;
|
||||
|
||||
public IObservable<IEnumerable<Exception>> Exceptions => Observable.Return(Enumerable.Empty<Exception>());
|
||||
|
||||
protected ContentProviderBase(string name)
|
||||
{
|
||||
DisplayName = Name = name;
|
||||
}
|
||||
|
||||
public virtual Task OnEnter() => Task.CompletedTask;
|
||||
public virtual async Task<IItem> GetItemByFullNameAsync(FullName fullName) => await GetItemByNativePathAsync(GetNativePath(fullName));
|
||||
public abstract Task<IItem> GetItemByNativePathAsync(NativePath nativePath);
|
||||
public virtual async Task<IItem> GetItemByFullNameAsync(FullName fullName, bool forceResolve = false, AbsolutePathType forceResolvePathType = AbsolutePathType.Unknown)
|
||||
=> await GetItemByNativePathAsync(GetNativePath(fullName), forceResolve, forceResolvePathType);
|
||||
public abstract Task<IItem> GetItemByNativePathAsync(NativePath nativePath, bool forceResolve = false, AbsolutePathType forceResolvePathType = AbsolutePathType.Unknown);
|
||||
public abstract Task<List<IAbsolutePath>> GetItemsByContainerAsync(FullName fullName);
|
||||
public abstract NativePath GetNativePath(FullName fullName);
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace FileTime.Core.Services
|
||||
private readonly List<ItemsTransformator> _transformators = new();
|
||||
private IAbsolutePath? _currentSelectedItemCached;
|
||||
public IObservable<IContainer?> CurrentLocation { get; }
|
||||
public IObservable<IEnumerable<IItem>> CurrentItems { get; }
|
||||
public IObservable<IEnumerable<IItem>?> CurrentItems { get; }
|
||||
public IObservable<IAbsolutePath?> CurrentSelectedItem { get; }
|
||||
|
||||
public Tab()
|
||||
@@ -23,7 +23,7 @@ namespace FileTime.Core.Services
|
||||
.Where(c => c is not null)
|
||||
.Select(c => c!.Items)
|
||||
.Switch()
|
||||
.Select(i => Observable.FromAsync(async () => await MapItems(i)))
|
||||
.Select(i => i == null ? Observable.Return<IEnumerable<IItem>?>(null) : Observable.FromAsync(async () => await MapItems(i)))
|
||||
.Switch(),
|
||||
CurrentLocation
|
||||
.Where(c => c is null)
|
||||
@@ -43,21 +43,11 @@ namespace FileTime.Core.Services
|
||||
CurrentSelectedItem.Subscribe(s => _currentSelectedItemCached = s);
|
||||
}
|
||||
|
||||
private async Task<IEnumerable<IItem>> MapItems(IReadOnlyList<IAbsolutePath> items)
|
||||
private async Task<IEnumerable<IItem>> MapItems(IEnumerable<IAbsolutePath> items)
|
||||
{
|
||||
IEnumerable<IItem> resolvedItems = await items
|
||||
.ToAsyncEnumerable()
|
||||
.SelectAwait(
|
||||
async i =>
|
||||
{
|
||||
try
|
||||
{
|
||||
//TODO: force create by AbsolutePath name
|
||||
return await i.ContentProvider.GetItemByFullNameAsync(i.Path);
|
||||
}
|
||||
catch { return null!; }
|
||||
}
|
||||
)
|
||||
.SelectAwait(async i => await i.ResolveAsync(true))
|
||||
.Where(i => i != null)
|
||||
.ToListAsync();
|
||||
|
||||
@@ -79,7 +69,7 @@ namespace FileTime.Core.Services
|
||||
private IObservable<IAbsolutePath?> GetSelectedItemByLocation(IContainer? currentLocation)
|
||||
{
|
||||
//TODO:
|
||||
return currentLocation?.Items?.Select(i => i.Count == 0 ? null : i[0]) ?? Observable.Return((IAbsolutePath?)null);
|
||||
return currentLocation?.Items?.Select(i => i.FirstOrDefault()) ?? Observable.Return((IAbsolutePath?)null);
|
||||
}
|
||||
|
||||
public void SetCurrentLocation(IContainer newLocation) => _currentLocation.OnNext(newLocation);
|
||||
|
||||
Reference in New Issue
Block a user