File scoped namespace
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
namespace FileTime.Core.Behaviors
|
||||
namespace FileTime.Core.Behaviors;
|
||||
|
||||
public interface IOnContainerEnter
|
||||
{
|
||||
public interface IOnContainerEnter
|
||||
{
|
||||
Task OnEnter();
|
||||
}
|
||||
Task OnEnter();
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
namespace FileTime.Core.Command
|
||||
namespace FileTime.Core.Command;
|
||||
|
||||
public interface ICommand
|
||||
{
|
||||
public interface ICommand
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
namespace FileTime.Core.Command
|
||||
namespace FileTime.Core.Command;
|
||||
|
||||
public interface ITransportationCommand : ICommand
|
||||
{
|
||||
public interface ITransportationCommand : ICommand
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,8 @@
|
||||
namespace FileTime.Core.Enums
|
||||
namespace FileTime.Core.Enums;
|
||||
|
||||
public enum AbsolutePathType
|
||||
{
|
||||
public enum AbsolutePathType
|
||||
{
|
||||
Unknown,
|
||||
Container,
|
||||
Element
|
||||
}
|
||||
Unknown,
|
||||
Container,
|
||||
Element
|
||||
}
|
||||
@@ -1,9 +1,8 @@
|
||||
namespace FileTime.Core.Enums
|
||||
namespace FileTime.Core.Enums;
|
||||
|
||||
public enum SupportsDelete
|
||||
{
|
||||
public enum SupportsDelete
|
||||
{
|
||||
False,
|
||||
True,
|
||||
HardDeleteOnly,
|
||||
}
|
||||
False,
|
||||
True,
|
||||
HardDeleteOnly,
|
||||
}
|
||||
@@ -6,6 +6,10 @@
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="DynamicData" Version="7.6.7" />
|
||||
<PackageReference Include="System.Reactive" Version="5.0.0" />
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
namespace FileTime.Core.Models
|
||||
namespace FileTime.Core.Models;
|
||||
|
||||
public static class Constants
|
||||
{
|
||||
public static class Constants
|
||||
{
|
||||
public const char SeparatorChar = '/';
|
||||
}
|
||||
public const char SeparatorChar = '/';
|
||||
}
|
||||
@@ -1,17 +1,16 @@
|
||||
namespace FileTime.Core.Models
|
||||
{
|
||||
public record FullName(string Path)
|
||||
{
|
||||
public FullName? GetParent()
|
||||
{
|
||||
if (Path is null) return null;
|
||||
namespace FileTime.Core.Models;
|
||||
|
||||
var pathParts = Path.TrimEnd(Constants.SeparatorChar).Split(Constants.SeparatorChar);
|
||||
return pathParts.Length switch
|
||||
{
|
||||
> 1 => new(string.Join(Constants.SeparatorChar, pathParts.SkipLast(1))),
|
||||
_ => null
|
||||
};
|
||||
}
|
||||
public record FullName(string Path)
|
||||
{
|
||||
public FullName? GetParent()
|
||||
{
|
||||
if (Path is null) return null;
|
||||
|
||||
var pathParts = Path.TrimEnd(Constants.SeparatorChar).Split(Constants.SeparatorChar);
|
||||
return pathParts.Length switch
|
||||
{
|
||||
> 1 => new(string.Join(Constants.SeparatorChar, pathParts.SkipLast(1))),
|
||||
_ => null
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,15 @@
|
||||
using FileTime.Core.Enums;
|
||||
using FileTime.Core.Services;
|
||||
|
||||
namespace FileTime.Core.Models
|
||||
{
|
||||
public interface IAbsolutePath
|
||||
{
|
||||
IContentProvider ContentProvider { get; }
|
||||
IContentProvider? VirtualContentProvider { get; }
|
||||
FullName Path { get; }
|
||||
AbsolutePathType Type { get; }
|
||||
namespace FileTime.Core.Models;
|
||||
|
||||
Task<IItem> ResolveAsync(bool forceResolve = false, ItemInitializationSettings itemInitializationSettings = default);
|
||||
Task<IItem?> ResolveAsyncSafe(bool forceResolve = false, ItemInitializationSettings itemInitializationSettings = default);
|
||||
}
|
||||
public interface IAbsolutePath
|
||||
{
|
||||
IContentProvider ContentProvider { get; }
|
||||
IContentProvider? VirtualContentProvider { get; }
|
||||
FullName Path { get; }
|
||||
AbsolutePathType Type { get; }
|
||||
|
||||
Task<IItem> ResolveAsync(bool forceResolve = false, ItemInitializationSettings itemInitializationSettings = default);
|
||||
Task<IItem?> ResolveAsyncSafe(bool forceResolve = false, ItemInitializationSettings itemInitializationSettings = default);
|
||||
}
|
||||
@@ -1,10 +1,9 @@
|
||||
using DynamicData;
|
||||
|
||||
namespace FileTime.Core.Models
|
||||
namespace FileTime.Core.Models;
|
||||
|
||||
public interface IContainer : IItem
|
||||
{
|
||||
public interface IContainer : IItem
|
||||
{
|
||||
IObservable<IObservable<IChangeSet<IAbsolutePath>>?> Items { get; }
|
||||
IObservable<bool> IsLoading { get; }
|
||||
}
|
||||
IObservable<IObservable<IChangeSet<IAbsolutePath>>?> Items { get; }
|
||||
IObservable<bool> IsLoading { get; }
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
namespace FileTime.Core.Models
|
||||
namespace FileTime.Core.Models;
|
||||
|
||||
public interface IElement : IItem
|
||||
{
|
||||
public interface IElement : IItem
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
namespace FileTime.Core.Models
|
||||
namespace FileTime.Core.Models;
|
||||
|
||||
public interface IFileElement : IElement
|
||||
{
|
||||
public interface IFileElement : IElement
|
||||
{
|
||||
long Size { get; }
|
||||
}
|
||||
long Size { get; }
|
||||
}
|
||||
@@ -1,23 +1,22 @@
|
||||
using FileTime.Core.Enums;
|
||||
using FileTime.Core.Services;
|
||||
|
||||
namespace FileTime.Core.Models
|
||||
namespace FileTime.Core.Models;
|
||||
|
||||
public interface IItem
|
||||
{
|
||||
public interface IItem
|
||||
{
|
||||
string Name { get; }
|
||||
string DisplayName { get; }
|
||||
FullName? FullName { get; }
|
||||
NativePath? NativePath { get; }
|
||||
IAbsolutePath? Parent { get; }
|
||||
bool IsHidden { get; }
|
||||
bool IsExists { get; }
|
||||
DateTime? CreatedAt { get; }
|
||||
SupportsDelete CanDelete { get; }
|
||||
bool CanRename { get; }
|
||||
IContentProvider Provider { get; }
|
||||
string? Attributes { get; }
|
||||
AbsolutePathType Type { get; }
|
||||
IObservable<IEnumerable<Exception>> Exceptions { get; }
|
||||
}
|
||||
string Name { get; }
|
||||
string DisplayName { get; }
|
||||
FullName? FullName { get; }
|
||||
NativePath? NativePath { get; }
|
||||
IAbsolutePath? Parent { get; }
|
||||
bool IsHidden { get; }
|
||||
bool IsExists { get; }
|
||||
DateTime? CreatedAt { get; }
|
||||
SupportsDelete CanDelete { get; }
|
||||
bool CanRename { get; }
|
||||
IContentProvider Provider { get; }
|
||||
string? Attributes { get; }
|
||||
AbsolutePathType Type { get; }
|
||||
IObservable<IEnumerable<Exception>> Exceptions { get; }
|
||||
}
|
||||
@@ -1,12 +1,11 @@
|
||||
namespace FileTime.Core.Models
|
||||
{
|
||||
public readonly struct ItemInitializationSettings
|
||||
{
|
||||
public readonly bool SkipChildInitialization;
|
||||
namespace FileTime.Core.Models;
|
||||
|
||||
public ItemInitializationSettings(bool skipChildInitialization)
|
||||
{
|
||||
SkipChildInitialization = skipChildInitialization;
|
||||
}
|
||||
public readonly struct ItemInitializationSettings
|
||||
{
|
||||
public readonly bool SkipChildInitialization;
|
||||
|
||||
public ItemInitializationSettings(bool skipChildInitialization)
|
||||
{
|
||||
SkipChildInitialization = skipChildInitialization;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
namespace FileTime.Core.Models
|
||||
{
|
||||
public record ItemsTransformator(
|
||||
string Name,
|
||||
Func<IEnumerable<IItem>, Task<IEnumerable<IItem>>> Transformator
|
||||
);
|
||||
}
|
||||
namespace FileTime.Core.Models;
|
||||
|
||||
public record ItemsTransformator(
|
||||
string Name,
|
||||
Func<IEnumerable<IItem>, Task<IEnumerable<IItem>>> Transformator
|
||||
);
|
||||
@@ -1,4 +1,3 @@
|
||||
namespace FileTime.Core.Models
|
||||
{
|
||||
public record NativePath(string Path);
|
||||
}
|
||||
namespace FileTime.Core.Models;
|
||||
|
||||
public record NativePath(string Path);
|
||||
@@ -2,22 +2,21 @@ using FileTime.Core.Behaviors;
|
||||
using FileTime.Core.Enums;
|
||||
using FileTime.Core.Models;
|
||||
|
||||
namespace FileTime.Core.Services
|
||||
namespace FileTime.Core.Services;
|
||||
|
||||
public interface IContentProvider : IContainer, IOnContainerEnter
|
||||
{
|
||||
public interface IContentProvider : IContainer, IOnContainerEnter
|
||||
{
|
||||
Task<IItem> GetItemByFullNameAsync(
|
||||
FullName fullName,
|
||||
bool forceResolve = false,
|
||||
AbsolutePathType forceResolvePathType = AbsolutePathType.Unknown,
|
||||
ItemInitializationSettings itemInitializationSettings = default);
|
||||
Task<IItem> GetItemByFullNameAsync(
|
||||
FullName fullName,
|
||||
bool forceResolve = false,
|
||||
AbsolutePathType forceResolvePathType = AbsolutePathType.Unknown,
|
||||
ItemInitializationSettings itemInitializationSettings = default);
|
||||
|
||||
Task<IItem> GetItemByNativePathAsync(
|
||||
NativePath nativePath,
|
||||
bool forceResolve = false,
|
||||
AbsolutePathType forceResolvePathType = AbsolutePathType.Unknown,
|
||||
ItemInitializationSettings itemInitializationSettings = default);
|
||||
Task<IItem> GetItemByNativePathAsync(
|
||||
NativePath nativePath,
|
||||
bool forceResolve = false,
|
||||
AbsolutePathType forceResolvePathType = AbsolutePathType.Unknown,
|
||||
ItemInitializationSettings itemInitializationSettings = default);
|
||||
|
||||
Task<List<IAbsolutePath>> GetItemsByContainerAsync(FullName fullName);
|
||||
}
|
||||
Task<List<IAbsolutePath>> GetItemsByContainerAsync(FullName fullName);
|
||||
}
|
||||
@@ -2,18 +2,17 @@ using DynamicData;
|
||||
using FileTime.Core.Models;
|
||||
using InitableService;
|
||||
|
||||
namespace FileTime.Core.Services
|
||||
{
|
||||
public interface ITab : IInitable<IContainer>
|
||||
{
|
||||
IObservable<IContainer?> CurrentLocation { get; }
|
||||
IObservable<IAbsolutePath?> CurrentSelectedItem { get; }
|
||||
IObservable<IObservable<IChangeSet<IItem>>?> CurrentItems { get; }
|
||||
namespace FileTime.Core.Services;
|
||||
|
||||
void SetCurrentLocation(IContainer newLocation);
|
||||
void AddSelectedItemsTransformator(ItemsTransformator transformator);
|
||||
void RemoveSelectedItemsTransformator(ItemsTransformator transformator);
|
||||
void RemoveSelectedItemsTransformatorByName(string name);
|
||||
void SetSelectedItem(IAbsolutePath newSelectedItem);
|
||||
}
|
||||
public interface ITab : IInitable<IContainer>
|
||||
{
|
||||
IObservable<IContainer?> CurrentLocation { get; }
|
||||
IObservable<IAbsolutePath?> CurrentSelectedItem { get; }
|
||||
IObservable<IObservable<IChangeSet<IItem>>?> CurrentItems { get; }
|
||||
|
||||
void SetCurrentLocation(IContainer newLocation);
|
||||
void AddSelectedItemsTransformator(ItemsTransformator transformator);
|
||||
void RemoveSelectedItemsTransformator(ItemsTransformator transformator);
|
||||
void RemoveSelectedItemsTransformatorByName(string name);
|
||||
void SetSelectedItem(IAbsolutePath newSelectedItem);
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
namespace FileTime.Core.Command.Copy
|
||||
{
|
||||
public class CopyCommand : ITransportationCommand
|
||||
{
|
||||
namespace FileTime.Core.Command.Copy;
|
||||
|
||||
public class CopyCommand : ITransportationCommand
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\FileTime.Core.Abstraction\FileTime.Core.Abstraction.csproj" />
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\FileTime.Core.Abstraction\FileTime.Core.Abstraction.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
namespace FileTime.Core.Command
|
||||
namespace FileTime.Core.Command;
|
||||
|
||||
public enum TransportMode
|
||||
{
|
||||
public enum TransportMode
|
||||
{
|
||||
Merge,
|
||||
Overwrite,
|
||||
Skip
|
||||
}
|
||||
Merge,
|
||||
Overwrite,
|
||||
Skip
|
||||
}
|
||||
@@ -1,45 +1,44 @@
|
||||
using FileTime.Core.Enums;
|
||||
using FileTime.Core.Services;
|
||||
|
||||
namespace FileTime.Core.Models
|
||||
namespace FileTime.Core.Models;
|
||||
|
||||
public class AbsolutePath : IAbsolutePath
|
||||
{
|
||||
public class AbsolutePath : IAbsolutePath
|
||||
public IContentProvider ContentProvider { get; }
|
||||
public IContentProvider? VirtualContentProvider { get; }
|
||||
|
||||
public FullName Path { get; }
|
||||
public AbsolutePathType Type { get; }
|
||||
|
||||
public AbsolutePath(IContentProvider contentProvider, FullName path, AbsolutePathType type, IContentProvider? virtualContentProvider = null)
|
||||
{
|
||||
public IContentProvider ContentProvider { get; }
|
||||
public IContentProvider? VirtualContentProvider { get; }
|
||||
ContentProvider = contentProvider;
|
||||
Path = path;
|
||||
VirtualContentProvider = virtualContentProvider;
|
||||
Type = type;
|
||||
}
|
||||
|
||||
public FullName Path { get; }
|
||||
public AbsolutePathType Type { get; }
|
||||
public AbsolutePath(IItem item, IContentProvider? virtualContentProvider = null)
|
||||
{
|
||||
ContentProvider = item.Provider;
|
||||
Path = item.FullName ?? throw new ArgumentException($"{nameof(item.FullName)} can not be null.", nameof(item));
|
||||
VirtualContentProvider = virtualContentProvider;
|
||||
Type = item.Type;
|
||||
}
|
||||
|
||||
public AbsolutePath(IContentProvider contentProvider, FullName path, AbsolutePathType type, IContentProvider? virtualContentProvider = null)
|
||||
public async Task<IItem> ResolveAsync(bool forceResolve = false, ItemInitializationSettings itemInitializationSettings = default)
|
||||
{
|
||||
var provider = VirtualContentProvider ?? ContentProvider;
|
||||
return await provider.GetItemByFullNameAsync(Path, forceResolve, Type, itemInitializationSettings);
|
||||
}
|
||||
|
||||
public async Task<IItem?> ResolveAsyncSafe(bool forceResolve = false, ItemInitializationSettings itemInitializationSettings = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
ContentProvider = contentProvider;
|
||||
Path = path;
|
||||
VirtualContentProvider = virtualContentProvider;
|
||||
Type = type;
|
||||
}
|
||||
|
||||
public AbsolutePath(IItem item, IContentProvider? virtualContentProvider = null)
|
||||
{
|
||||
ContentProvider = item.Provider;
|
||||
Path = item.FullName ?? throw new ArgumentException($"{nameof(item.FullName)} can not be null.", nameof(item));
|
||||
VirtualContentProvider = virtualContentProvider;
|
||||
Type = item.Type;
|
||||
}
|
||||
|
||||
public async Task<IItem> ResolveAsync(bool forceResolve = false, ItemInitializationSettings itemInitializationSettings = default)
|
||||
{
|
||||
var provider = VirtualContentProvider ?? ContentProvider;
|
||||
return await provider.GetItemByFullNameAsync(Path, forceResolve, Type, itemInitializationSettings);
|
||||
}
|
||||
|
||||
public async Task<IItem?> ResolveAsyncSafe(bool forceResolve = false, ItemInitializationSettings itemInitializationSettings = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
return await ResolveAsync(forceResolve, itemInitializationSettings);
|
||||
}
|
||||
catch { return null; }
|
||||
return await ResolveAsync(forceResolve, itemInitializationSettings);
|
||||
}
|
||||
catch { return null; }
|
||||
}
|
||||
}
|
||||
@@ -4,26 +4,25 @@ using DynamicData;
|
||||
using FileTime.Core.Enums;
|
||||
using FileTime.Core.Services;
|
||||
|
||||
namespace FileTime.Core.Models
|
||||
namespace FileTime.Core.Models;
|
||||
|
||||
public record Container(
|
||||
string Name,
|
||||
string DisplayName,
|
||||
FullName FullName,
|
||||
NativePath NativePath,
|
||||
IAbsolutePath? Parent,
|
||||
bool IsHidden,
|
||||
bool IsExists,
|
||||
DateTime? CreatedAt,
|
||||
SupportsDelete CanDelete,
|
||||
bool CanRename,
|
||||
string? Attributes,
|
||||
IContentProvider Provider,
|
||||
IObservable<IEnumerable<Exception>> Exceptions,
|
||||
IObservable<IObservable<IChangeSet<IAbsolutePath>>?> Items) : IContainer
|
||||
{
|
||||
public record Container(
|
||||
string Name,
|
||||
string DisplayName,
|
||||
FullName FullName,
|
||||
NativePath NativePath,
|
||||
IAbsolutePath? Parent,
|
||||
bool IsHidden,
|
||||
bool IsExists,
|
||||
DateTime? CreatedAt,
|
||||
SupportsDelete CanDelete,
|
||||
bool CanRename,
|
||||
string? Attributes,
|
||||
IContentProvider Provider,
|
||||
IObservable<IEnumerable<Exception>> Exceptions,
|
||||
IObservable<IObservable<IChangeSet<IAbsolutePath>>?> Items) : IContainer
|
||||
{
|
||||
BehaviorSubject<bool> IsLoading { get; } = new BehaviorSubject<bool>(false);
|
||||
IObservable<bool> IContainer.IsLoading => IsLoading.AsObservable();
|
||||
public AbsolutePathType Type => AbsolutePathType.Container;
|
||||
}
|
||||
BehaviorSubject<bool> IsLoading { get; } = new BehaviorSubject<bool>(false);
|
||||
IObservable<bool> IContainer.IsLoading => IsLoading.AsObservable();
|
||||
public AbsolutePathType Type => AbsolutePathType.Container;
|
||||
}
|
||||
@@ -1,23 +1,22 @@
|
||||
using FileTime.Core.Enums;
|
||||
using FileTime.Core.Services;
|
||||
|
||||
namespace FileTime.Core.Models
|
||||
namespace FileTime.Core.Models;
|
||||
|
||||
public record Element(
|
||||
string Name,
|
||||
string DisplayName,
|
||||
FullName FullName,
|
||||
NativePath NativePath,
|
||||
IAbsolutePath? Parent,
|
||||
bool IsHidden,
|
||||
bool IsExists,
|
||||
DateTime? CreatedAt,
|
||||
SupportsDelete CanDelete,
|
||||
bool CanRename,
|
||||
string? Attributes,
|
||||
IContentProvider Provider,
|
||||
IObservable<IEnumerable<Exception>> Exceptions) : IElement
|
||||
{
|
||||
public record Element(
|
||||
string Name,
|
||||
string DisplayName,
|
||||
FullName FullName,
|
||||
NativePath NativePath,
|
||||
IAbsolutePath? Parent,
|
||||
bool IsHidden,
|
||||
bool IsExists,
|
||||
DateTime? CreatedAt,
|
||||
SupportsDelete CanDelete,
|
||||
bool CanRename,
|
||||
string? Attributes,
|
||||
IContentProvider Provider,
|
||||
IObservable<IEnumerable<Exception>> Exceptions) : IElement
|
||||
{
|
||||
public AbsolutePathType Type => AbsolutePathType.Element;
|
||||
}
|
||||
public AbsolutePathType Type => AbsolutePathType.Element;
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
using FileTime.Core.Enums;
|
||||
using FileTime.Core.Services;
|
||||
|
||||
namespace FileTime.Core.Models
|
||||
{
|
||||
public record FileElement(
|
||||
namespace FileTime.Core.Models;
|
||||
|
||||
public record FileElement(
|
||||
string Name,
|
||||
string DisplayName,
|
||||
FullName FullName,
|
||||
@@ -32,5 +32,4 @@ namespace FileTime.Core.Models
|
||||
Attributes,
|
||||
Provider,
|
||||
Exceptions
|
||||
), IFileElement;
|
||||
}
|
||||
), IFileElement;
|
||||
@@ -6,6 +6,10 @@
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\FileTime.Core.Abstraction\FileTime.Core.Abstraction.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -4,64 +4,63 @@ using DynamicData;
|
||||
using FileTime.Core.Enums;
|
||||
using FileTime.Core.Models;
|
||||
|
||||
namespace FileTime.Core.Services
|
||||
namespace FileTime.Core.Services;
|
||||
|
||||
public abstract class ContentProviderBase : IContentProvider
|
||||
{
|
||||
public abstract class ContentProviderBase : IContentProvider
|
||||
protected BehaviorSubject<IObservable<IChangeSet<IAbsolutePath>>?> Items { get; } = new (null);
|
||||
|
||||
IObservable<IObservable<IChangeSet<IAbsolutePath>>?> IContainer.Items => Items;
|
||||
|
||||
public string Name { get; }
|
||||
|
||||
public string DisplayName { get; }
|
||||
|
||||
public FullName? FullName => null;
|
||||
|
||||
public NativePath? NativePath => null;
|
||||
|
||||
public bool IsHidden => false;
|
||||
|
||||
public bool IsExists => true;
|
||||
|
||||
public SupportsDelete CanDelete => SupportsDelete.False;
|
||||
|
||||
public bool CanRename => false;
|
||||
|
||||
public IContentProvider Provider => this;
|
||||
|
||||
public IAbsolutePath? Parent => null;
|
||||
|
||||
public DateTime? CreatedAt => null;
|
||||
|
||||
public string? Attributes => null;
|
||||
|
||||
protected BehaviorSubject<bool> IsLoading { get; } = new(false);
|
||||
|
||||
IObservable<bool> IContainer.IsLoading => IsLoading.AsObservable();
|
||||
|
||||
public AbsolutePathType Type => AbsolutePathType.Container;
|
||||
|
||||
public IObservable<IEnumerable<Exception>> Exceptions => Observable.Return(Enumerable.Empty<Exception>());
|
||||
|
||||
protected ContentProviderBase(string name)
|
||||
{
|
||||
protected BehaviorSubject<IObservable<IChangeSet<IAbsolutePath>>?> Items { get; } = new (null);
|
||||
|
||||
IObservable<IObservable<IChangeSet<IAbsolutePath>>?> IContainer.Items => Items;
|
||||
|
||||
public string Name { get; }
|
||||
|
||||
public string DisplayName { get; }
|
||||
|
||||
public FullName? FullName => null;
|
||||
|
||||
public NativePath? NativePath => null;
|
||||
|
||||
public bool IsHidden => false;
|
||||
|
||||
public bool IsExists => true;
|
||||
|
||||
public SupportsDelete CanDelete => SupportsDelete.False;
|
||||
|
||||
public bool CanRename => false;
|
||||
|
||||
public IContentProvider Provider => this;
|
||||
|
||||
public IAbsolutePath? Parent => null;
|
||||
|
||||
public DateTime? CreatedAt => null;
|
||||
|
||||
public string? Attributes => null;
|
||||
|
||||
protected BehaviorSubject<bool> IsLoading { get; } = new(false);
|
||||
|
||||
IObservable<bool> IContainer.IsLoading => IsLoading.AsObservable();
|
||||
|
||||
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,
|
||||
bool forceResolve = false,
|
||||
AbsolutePathType forceResolvePathType = AbsolutePathType.Unknown,
|
||||
ItemInitializationSettings itemInitializationSettings = default)
|
||||
=> await GetItemByNativePathAsync(GetNativePath(fullName), forceResolve, forceResolvePathType, itemInitializationSettings);
|
||||
public abstract Task<IItem> GetItemByNativePathAsync(
|
||||
NativePath nativePath,
|
||||
bool forceResolve = false,
|
||||
AbsolutePathType forceResolvePathType = AbsolutePathType.Unknown,
|
||||
ItemInitializationSettings itemInitializationSettings = default);
|
||||
public abstract Task<List<IAbsolutePath>> GetItemsByContainerAsync(FullName fullName);
|
||||
public abstract NativePath GetNativePath(FullName fullName);
|
||||
DisplayName = Name = name;
|
||||
}
|
||||
|
||||
public virtual Task OnEnter() => Task.CompletedTask;
|
||||
public virtual async Task<IItem> GetItemByFullNameAsync(
|
||||
FullName fullName,
|
||||
bool forceResolve = false,
|
||||
AbsolutePathType forceResolvePathType = AbsolutePathType.Unknown,
|
||||
ItemInitializationSettings itemInitializationSettings = default)
|
||||
=> await GetItemByNativePathAsync(GetNativePath(fullName), forceResolve, forceResolvePathType, itemInitializationSettings);
|
||||
public abstract Task<IItem> GetItemByNativePathAsync(
|
||||
NativePath nativePath,
|
||||
bool forceResolve = false,
|
||||
AbsolutePathType forceResolvePathType = AbsolutePathType.Unknown,
|
||||
ItemInitializationSettings itemInitializationSettings = default);
|
||||
public abstract Task<List<IAbsolutePath>> GetItemsByContainerAsync(FullName fullName);
|
||||
public abstract NativePath GetNativePath(FullName fullName);
|
||||
}
|
||||
@@ -6,6 +6,10 @@
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="System.Interactive.Async" Version="6.0.1" />
|
||||
<PackageReference Include="System.Linq.Async" Version="6.0.1" />
|
||||
|
||||
@@ -3,24 +3,24 @@ using System.Reactive.Subjects;
|
||||
using DynamicData;
|
||||
using FileTime.Core.Models;
|
||||
|
||||
namespace FileTime.Core.Services
|
||||
namespace FileTime.Core.Services;
|
||||
|
||||
public class Tab : ITab
|
||||
{
|
||||
public class Tab : ITab
|
||||
private readonly BehaviorSubject<IContainer?> _currentLocation = new(null);
|
||||
private readonly BehaviorSubject<IAbsolutePath?> _currentSelectedItem = new(null);
|
||||
private readonly List<ItemsTransformator> _transformators = new();
|
||||
private IAbsolutePath? _currentSelectedItemCached;
|
||||
|
||||
public IObservable<IContainer?> CurrentLocation { get; }
|
||||
public IObservable<IObservable<IChangeSet<IItem>>?> CurrentItems { get; }
|
||||
public IObservable<IAbsolutePath?> CurrentSelectedItem { get; }
|
||||
|
||||
public Tab()
|
||||
{
|
||||
private readonly BehaviorSubject<IContainer?> _currentLocation = new(null);
|
||||
private readonly BehaviorSubject<IAbsolutePath?> _currentSelectedItem = new(null);
|
||||
private readonly List<ItemsTransformator> _transformators = new();
|
||||
private IAbsolutePath? _currentSelectedItemCached;
|
||||
|
||||
public IObservable<IContainer?> CurrentLocation { get; }
|
||||
public IObservable<IObservable<IChangeSet<IItem>>?> CurrentItems { get; }
|
||||
public IObservable<IAbsolutePath?> CurrentSelectedItem { get; }
|
||||
|
||||
public Tab()
|
||||
{
|
||||
CurrentLocation = _currentLocation.DistinctUntilChanged().Publish(null).RefCount();
|
||||
CurrentItems =
|
||||
Observable.Merge(
|
||||
CurrentLocation = _currentLocation.DistinctUntilChanged().Publish(null).RefCount();
|
||||
CurrentItems =
|
||||
Observable.Merge(
|
||||
CurrentLocation
|
||||
.Where(c => c is not null)
|
||||
.Select(c => c!.Items)
|
||||
@@ -33,13 +33,13 @@ namespace FileTime.Core.Services
|
||||
.Publish((IObservable<IChangeSet<IItem>>?)null)
|
||||
.RefCount();
|
||||
|
||||
CurrentSelectedItem =
|
||||
Observable.CombineLatest(
|
||||
CurrentSelectedItem =
|
||||
Observable.CombineLatest(
|
||||
CurrentItems
|
||||
.Select(c =>
|
||||
c == null
|
||||
? Observable.Return<IReadOnlyCollection<IItem>?>(null)
|
||||
: c.ToCollection()
|
||||
? Observable.Return<IReadOnlyCollection<IItem>?>(null)
|
||||
: c.ToCollection()
|
||||
)
|
||||
.Switch(),
|
||||
_currentSelectedItem,
|
||||
@@ -55,41 +55,40 @@ namespace FileTime.Core.Services
|
||||
.Publish(null)
|
||||
.RefCount();
|
||||
|
||||
CurrentSelectedItem.Subscribe(s =>
|
||||
{
|
||||
_currentSelectedItemCached = s;
|
||||
_currentSelectedItem.OnNext(s);
|
||||
});
|
||||
}
|
||||
|
||||
private async Task<IItem> MapItem(IAbsolutePath item) => await item.ResolveAsync(true);
|
||||
|
||||
public void Init(IContainer currentLocation)
|
||||
CurrentSelectedItem.Subscribe(s =>
|
||||
{
|
||||
_currentLocation.OnNext(currentLocation);
|
||||
}
|
||||
_currentSelectedItemCached = s;
|
||||
_currentSelectedItem.OnNext(s);
|
||||
});
|
||||
}
|
||||
|
||||
private static IAbsolutePath? GetSelectedItemByItems(IEnumerable<IItem> items)
|
||||
{
|
||||
//TODO:
|
||||
return new AbsolutePath(items.First());
|
||||
}
|
||||
private async Task<IItem> MapItem(IAbsolutePath item) => await item.ResolveAsync(true);
|
||||
|
||||
public void SetCurrentLocation(IContainer newLocation) => _currentLocation.OnNext(newLocation);
|
||||
public void Init(IContainer currentLocation)
|
||||
{
|
||||
_currentLocation.OnNext(currentLocation);
|
||||
}
|
||||
|
||||
public void SetSelectedItem(IAbsolutePath newSelectedItem) => _currentSelectedItem.OnNext(newSelectedItem);
|
||||
private static IAbsolutePath? GetSelectedItemByItems(IEnumerable<IItem> items)
|
||||
{
|
||||
//TODO:
|
||||
return new AbsolutePath(items.First());
|
||||
}
|
||||
|
||||
public void AddSelectedItemsTransformator(ItemsTransformator transformator) => _transformators.Add(transformator);
|
||||
public void RemoveSelectedItemsTransformator(ItemsTransformator transformator) => _transformators.Remove(transformator);
|
||||
public void RemoveSelectedItemsTransformatorByName(string name) => _transformators.RemoveAll(t => t.Name == name);
|
||||
public void SetCurrentLocation(IContainer newLocation) => _currentLocation.OnNext(newLocation);
|
||||
|
||||
public async Task OpenSelected()
|
||||
{
|
||||
if (_currentSelectedItemCached == null) return;
|
||||
var resolvedSelectedItem = await _currentSelectedItemCached.ContentProvider.GetItemByFullNameAsync(_currentSelectedItemCached.Path);
|
||||
public void SetSelectedItem(IAbsolutePath newSelectedItem) => _currentSelectedItem.OnNext(newSelectedItem);
|
||||
|
||||
if (resolvedSelectedItem is not IContainer resolvedContainer) return;
|
||||
SetCurrentLocation(resolvedContainer);
|
||||
}
|
||||
public void AddSelectedItemsTransformator(ItemsTransformator transformator) => _transformators.Add(transformator);
|
||||
public void RemoveSelectedItemsTransformator(ItemsTransformator transformator) => _transformators.Remove(transformator);
|
||||
public void RemoveSelectedItemsTransformatorByName(string name) => _transformators.RemoveAll(t => t.Name == name);
|
||||
|
||||
public async Task OpenSelected()
|
||||
{
|
||||
if (_currentSelectedItemCached == null) return;
|
||||
var resolvedSelectedItem = await _currentSelectedItemCached.ContentProvider.GetItemByFullNameAsync(_currentSelectedItemCached.Path);
|
||||
|
||||
if (resolvedSelectedItem is not IContainer resolvedContainer) return;
|
||||
SetCurrentLocation(resolvedContainer);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user