Search by name/regex
This commit is contained in:
@@ -16,6 +16,8 @@ namespace FileTime.App.Core.Command
|
|||||||
Cut,
|
Cut,
|
||||||
Edit,
|
Edit,
|
||||||
EnterRapidTravel,
|
EnterRapidTravel,
|
||||||
|
FindByName,
|
||||||
|
FindByNameRegex,
|
||||||
GoToHome,
|
GoToHome,
|
||||||
GoToPath,
|
GoToPath,
|
||||||
GoToProvider,
|
GoToProvider,
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ using FileTime.App.Core.Clipboard;
|
|||||||
using FileTime.Core.Command;
|
using FileTime.Core.Command;
|
||||||
using FileTime.Core.CommandHandlers;
|
using FileTime.Core.CommandHandlers;
|
||||||
using FileTime.Core.Providers;
|
using FileTime.Core.Providers;
|
||||||
|
using FileTime.Core.Services;
|
||||||
using FileTime.Core.Timeline;
|
using FileTime.Core.Timeline;
|
||||||
using FileTime.Providers.Local;
|
using FileTime.Providers.Local;
|
||||||
using FileTime.Providers.Sftp;
|
using FileTime.Providers.Sftp;
|
||||||
@@ -21,6 +22,7 @@ namespace FileTime.App.Core
|
|||||||
.AddSingleton<TopContainer>()
|
.AddSingleton<TopContainer>()
|
||||||
.AddSingleton<CommandExecutor>()
|
.AddSingleton<CommandExecutor>()
|
||||||
.AddSingleton<TimeRunner>()
|
.AddSingleton<TimeRunner>()
|
||||||
|
.AddSingleton<ItemNameConverterService>()
|
||||||
.AddLocalServices()
|
.AddLocalServices()
|
||||||
.AddSmbServices()
|
.AddSmbServices()
|
||||||
.AddSftpServices()
|
.AddSftpServices()
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ namespace FileTime.Core.Command.Copy
|
|||||||
}
|
}
|
||||||
|
|
||||||
var resolvedFrom = await from.ResolveAsync();
|
var resolvedFrom = await from.ResolveAsync();
|
||||||
operationsByFolder.Add(new OperationProgress(from.Path, resolvedFrom is IElement element ? await element.GetElementSize() : 0L));
|
operationsByFolder.Add(new OperationProgress(from.Path, resolvedFrom is IElement element ? await element.GetElementSize() ?? 0L : 0L));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task CreateContainerAsync(IContainer target, string name)
|
public Task CreateContainerAsync(IContainer target, string name)
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
using AsyncEvent;
|
using AsyncEvent;
|
||||||
|
using FileTime.Core.Helper;
|
||||||
using FileTime.Core.Models;
|
using FileTime.Core.Models;
|
||||||
|
using FileTime.Core.Search;
|
||||||
|
|
||||||
namespace FileTime.Core.Components
|
namespace FileTime.Core.Components
|
||||||
{
|
{
|
||||||
@@ -97,7 +99,7 @@ namespace FileTime.Core.Components
|
|||||||
}
|
}
|
||||||
|
|
||||||
_currentSelectedItem = itemToSelect;
|
_currentSelectedItem = itemToSelect;
|
||||||
_lastPath = GetCommonPath(_lastPath, itemToSelect?.FullName);
|
_lastPath = PathHelper.GetLongerPath(_lastPath, itemToSelect?.FullName);
|
||||||
|
|
||||||
CurrentSelectedIndex = await GetItemIndex(itemToSelect, CancellationToken.None);
|
CurrentSelectedIndex = await GetItemIndex(itemToSelect, CancellationToken.None);
|
||||||
|
|
||||||
@@ -122,7 +124,6 @@ namespace FileTime.Core.Components
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var itemNameToSelect = _lastPath
|
var itemNameToSelect = _lastPath
|
||||||
.Split(Constants.SeparatorChar)
|
.Split(Constants.SeparatorChar)
|
||||||
.Skip((containerFullName?.Split(Constants.SeparatorChar).Length) ?? 0)
|
.Skip((containerFullName?.Split(Constants.SeparatorChar).Length) ?? 0)
|
||||||
@@ -131,36 +132,6 @@ namespace FileTime.Core.Components
|
|||||||
return (await container.GetItems())?.FirstOrDefault(i => i.Name == itemNameToSelect);
|
return (await container.GetItems())?.FirstOrDefault(i => i.Name == itemNameToSelect);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string GetCommonPath(string? oldPath, string? newPath)
|
|
||||||
{
|
|
||||||
var oldPathParts = oldPath?.Split(Constants.SeparatorChar) ?? Array.Empty<string>();
|
|
||||||
var newPathParts = newPath?.Split(Constants.SeparatorChar) ?? Array.Empty<string>();
|
|
||||||
|
|
||||||
var commonPathParts = new List<string>();
|
|
||||||
|
|
||||||
var max = oldPathParts.Length > newPathParts.Length ? oldPathParts.Length : newPathParts.Length;
|
|
||||||
|
|
||||||
for (var i = 0; i < max; i++)
|
|
||||||
{
|
|
||||||
if (newPathParts.Length <= i)
|
|
||||||
{
|
|
||||||
commonPathParts.AddRange(oldPathParts.Skip(i));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
else if (oldPathParts.Length <= i || oldPathParts[i] != newPathParts[i])
|
|
||||||
{
|
|
||||||
commonPathParts.AddRange(newPathParts.Skip(i));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
else if (oldPathParts[i] == newPathParts[i])
|
|
||||||
{
|
|
||||||
commonPathParts.Add(oldPathParts[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return string.Join(Constants.SeparatorChar, commonPathParts);
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task HandleCurrentLocationRefresh(object? sender, AsyncEventArgs e, CancellationToken token = default)
|
private async Task HandleCurrentLocationRefresh(object? sender, AsyncEventArgs e, CancellationToken token = default)
|
||||||
{
|
{
|
||||||
var currentSelectedName = (await GetCurrentSelectedItem())?.FullName ?? (await GetItemByLastPath())?.FullName;
|
var currentSelectedName = (await GetCurrentSelectedItem())?.FullName ?? (await GetItemByLastPath())?.FullName;
|
||||||
@@ -311,12 +282,24 @@ namespace FileTime.Core.Components
|
|||||||
|
|
||||||
public async Task Open()
|
public async Task Open()
|
||||||
{
|
{
|
||||||
var currentLocationItems = (await (await GetCurrentLocation()).GetItems())!;
|
if (_currentSelectedItem is ChildSearchElement searchElement && searchElement.GetParent() is IContainer parentContainer)
|
||||||
if (_currentSelectedItem is IContainer childContainer)
|
|
||||||
{
|
{
|
||||||
if (await GetCurrentLocation() is VirtualContainer currentVirtuakContainer)
|
await OpenContainer(parentContainer);
|
||||||
|
var elementToSelect = await (await GetCurrentLocation()).GetByPath(searchElement.DisplayName);
|
||||||
|
if (elementToSelect != null)
|
||||||
{
|
{
|
||||||
await SetCurrentLocation(currentVirtuakContainer.CloneVirtualChainFor(childContainer, v => v.IsPermanent));
|
await SetCurrentSelectedItem(elementToSelect);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (_currentSelectedItem is ChildSearchContainer searchContainer)
|
||||||
|
{
|
||||||
|
await OpenContainer(searchContainer.BaseContainer);
|
||||||
|
}
|
||||||
|
else if (_currentSelectedItem is IContainer childContainer)
|
||||||
|
{
|
||||||
|
if (await GetCurrentLocation() is VirtualContainer currentVirtualContainer)
|
||||||
|
{
|
||||||
|
await SetCurrentLocation(currentVirtualContainer.CloneVirtualChainFor(childContainer, v => v.IsPermanent));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.0" />
|
||||||
|
<PackageReference Include="System.Linq.Async" Version="6.0.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
55
src/Core/FileTime.Core/Helper/PathHelper.cs
Normal file
55
src/Core/FileTime.Core/Helper/PathHelper.cs
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
using FileTime.Core.Models;
|
||||||
|
|
||||||
|
namespace FileTime.Core.Helper
|
||||||
|
{
|
||||||
|
public static class PathHelper
|
||||||
|
{
|
||||||
|
public static string GetLongerPath(string? oldPath, string? newPath)
|
||||||
|
{
|
||||||
|
var oldPathParts = oldPath?.Split(Constants.SeparatorChar) ?? Array.Empty<string>();
|
||||||
|
var newPathParts = newPath?.Split(Constants.SeparatorChar) ?? Array.Empty<string>();
|
||||||
|
|
||||||
|
var commonPathParts = new List<string>();
|
||||||
|
|
||||||
|
var max = oldPathParts.Length > newPathParts.Length ? oldPathParts.Length : newPathParts.Length;
|
||||||
|
|
||||||
|
for (var i = 0; i < max; i++)
|
||||||
|
{
|
||||||
|
if (newPathParts.Length <= i)
|
||||||
|
{
|
||||||
|
commonPathParts.AddRange(oldPathParts.Skip(i));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if (oldPathParts.Length <= i || oldPathParts[i] != newPathParts[i])
|
||||||
|
{
|
||||||
|
commonPathParts.AddRange(newPathParts.Skip(i));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if (oldPathParts[i] == newPathParts[i])
|
||||||
|
{
|
||||||
|
commonPathParts.Add(oldPathParts[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return string.Join(Constants.SeparatorChar, commonPathParts);
|
||||||
|
}
|
||||||
|
public static string GetCommonPath(string? path1, string? path2)
|
||||||
|
{
|
||||||
|
var path1Parts = path1?.Split(Constants.SeparatorChar) ?? Array.Empty<string>();
|
||||||
|
var path2Parts = path2?.Split(Constants.SeparatorChar) ?? Array.Empty<string>();
|
||||||
|
|
||||||
|
var commonPathParts = new List<string>();
|
||||||
|
|
||||||
|
var max = path1Parts.Length > path2Parts.Length ? path2Parts.Length : path1Parts.Length;
|
||||||
|
|
||||||
|
for (var i = 0; i < max; i++)
|
||||||
|
{
|
||||||
|
if (path1Parts[i] != path2Parts[i]) break;
|
||||||
|
|
||||||
|
commonPathParts.Add(path1Parts[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return string.Join(Constants.SeparatorChar, commonPathParts);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
18
src/Core/FileTime.Core/Models/ContainerEscapeResult.cs
Normal file
18
src/Core/FileTime.Core/Models/ContainerEscapeResult.cs
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
namespace FileTime.Core.Models
|
||||||
|
{
|
||||||
|
public class ContainerEscapeResult
|
||||||
|
{
|
||||||
|
public bool Handled { get; }
|
||||||
|
public IContainer? NavigateTo { get; }
|
||||||
|
|
||||||
|
public ContainerEscapeResult(bool handled)
|
||||||
|
{
|
||||||
|
Handled = handled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ContainerEscapeResult(IContainer navigateTo)
|
||||||
|
{
|
||||||
|
NavigateTo = navigateTo;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,6 +9,9 @@ namespace FileTime.Core.Models
|
|||||||
Task<IReadOnlyList<IContainer>?> GetContainers(CancellationToken token = default);
|
Task<IReadOnlyList<IContainer>?> GetContainers(CancellationToken token = default);
|
||||||
Task<IReadOnlyList<IElement>?> GetElements(CancellationToken token = default);
|
Task<IReadOnlyList<IElement>?> GetElements(CancellationToken token = default);
|
||||||
bool AllowRecursiveDeletion { get; }
|
bool AllowRecursiveDeletion { get; }
|
||||||
|
bool UseLazyLoad { get; }
|
||||||
|
bool LazyLoading { get; }
|
||||||
|
bool CanHandleEscape { get; }
|
||||||
|
|
||||||
Task RefreshAsync(CancellationToken token = default);
|
Task RefreshAsync(CancellationToken token = default);
|
||||||
public async Task<IItem?> GetByPath(string path, bool acceptDeepestMatch = false)
|
public async Task<IItem?> GetByPath(string path, bool acceptDeepestMatch = false)
|
||||||
@@ -46,9 +49,12 @@ namespace FileTime.Core.Models
|
|||||||
Task<bool> CanOpenAsync();
|
Task<bool> CanOpenAsync();
|
||||||
void Unload();
|
void Unload();
|
||||||
|
|
||||||
|
Task<ContainerEscapeResult> HandleEscape();
|
||||||
|
|
||||||
bool IsLoaded { get; }
|
bool IsLoaded { get; }
|
||||||
bool SupportsDirectoryLevelSoftDelete { get; }
|
bool SupportsDirectoryLevelSoftDelete { get; }
|
||||||
|
|
||||||
AsyncEventHandler Refreshed { get; }
|
AsyncEventHandler Refreshed { get; }
|
||||||
|
AsyncEventHandler<bool> LazyLoadingChanged { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7,7 +7,7 @@ namespace FileTime.Core.Models
|
|||||||
bool IsSpecial { get; }
|
bool IsSpecial { get; }
|
||||||
string GetPrimaryAttributeText();
|
string GetPrimaryAttributeText();
|
||||||
Task<string> GetContent(CancellationToken token = default);
|
Task<string> GetContent(CancellationToken token = default);
|
||||||
Task<long> GetElementSize(CancellationToken token = default);
|
Task<long?> GetElementSize(CancellationToken token = default);
|
||||||
|
|
||||||
Task<IContentReader> GetContentReaderAsync();
|
Task<IContentReader> GetContentReaderAsync();
|
||||||
Task<IContentWriter> GetContentWriterAsync();
|
Task<IContentWriter> GetContentWriterAsync();
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ namespace FileTime.Core.Models
|
|||||||
public interface IItem
|
public interface IItem
|
||||||
{
|
{
|
||||||
string Name { get; }
|
string Name { get; }
|
||||||
|
string DisplayName { get; }
|
||||||
string? FullName { get; }
|
string? FullName { get; }
|
||||||
string? NativePath { get; }
|
string? NativePath { get; }
|
||||||
bool IsHidden { get; }
|
bool IsHidden { get; }
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace FileTime.Avalonia.Models
|
namespace FileTime.Core.Models
|
||||||
{
|
{
|
||||||
public class ItemNamePart
|
public class ItemNamePart
|
||||||
{
|
{
|
||||||
@@ -20,6 +20,7 @@ namespace FileTime.Core.Models
|
|||||||
public IReadOnlyList<IElement>? Elements { get; private set; }
|
public IReadOnlyList<IElement>? Elements { get; private set; }
|
||||||
|
|
||||||
public string Name => BaseContainer.Name;
|
public string Name => BaseContainer.Name;
|
||||||
|
public string DisplayName => BaseContainer.DisplayName;
|
||||||
|
|
||||||
public string? FullName => BaseContainer.FullName;
|
public string? FullName => BaseContainer.FullName;
|
||||||
public string? NativePath => BaseContainer.NativePath;
|
public string? NativePath => BaseContainer.NativePath;
|
||||||
@@ -40,6 +41,13 @@ namespace FileTime.Core.Models
|
|||||||
public bool IsExists => BaseContainer.IsExists;
|
public bool IsExists => BaseContainer.IsExists;
|
||||||
public bool AllowRecursiveDeletion => BaseContainer.AllowRecursiveDeletion;
|
public bool AllowRecursiveDeletion => BaseContainer.AllowRecursiveDeletion;
|
||||||
|
|
||||||
|
public bool UseLazyLoad => BaseContainer.UseLazyLoad;
|
||||||
|
|
||||||
|
public bool LazyLoading => BaseContainer.LazyLoading;
|
||||||
|
public AsyncEventHandler<bool> LazyLoadingChanged { get; protected set; } = new();
|
||||||
|
|
||||||
|
public bool CanHandleEscape => BaseContainer.CanHandleEscape;
|
||||||
|
|
||||||
private void RefreshAddBase(Func<object?, AsyncEventArgs, CancellationToken, Task> handler)
|
private void RefreshAddBase(Func<object?, AsyncEventArgs, CancellationToken, Task> handler)
|
||||||
{
|
{
|
||||||
BaseContainer.Refreshed.Add(handler);
|
BaseContainer.Refreshed.Add(handler);
|
||||||
@@ -183,5 +191,6 @@ namespace FileTime.Core.Models
|
|||||||
{
|
{
|
||||||
BaseContainer.Unload();
|
BaseContainer.Unload();
|
||||||
}
|
}
|
||||||
|
public async Task<ContainerEscapeResult> HandleEscape() => await BaseContainer.HandleEscape();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
using System.Threading.Tasks;
|
||||||
using AsyncEvent;
|
using AsyncEvent;
|
||||||
using FileTime.Core.Models;
|
using FileTime.Core.Models;
|
||||||
|
|
||||||
@@ -18,8 +19,10 @@ namespace FileTime.Core.Providers
|
|||||||
public bool SupportsDirectoryLevelSoftDelete { get; protected set; }
|
public bool SupportsDirectoryLevelSoftDelete { get; protected set; }
|
||||||
|
|
||||||
public AsyncEventHandler Refreshed { get; protected set; } = new();
|
public AsyncEventHandler Refreshed { get; protected set; } = new();
|
||||||
|
public AsyncEventHandler<bool> LazyLoadingChanged { get; protected set; } = new();
|
||||||
|
|
||||||
public string Name { get; protected set; }
|
public string Name { get; protected set; }
|
||||||
|
public virtual string DisplayName { get; protected set; }
|
||||||
|
|
||||||
public string? FullName { get; protected set; }
|
public string? FullName { get; protected set; }
|
||||||
|
|
||||||
@@ -41,6 +44,12 @@ namespace FileTime.Core.Providers
|
|||||||
|
|
||||||
public virtual bool AllowRecursiveDeletion { get; protected set; }
|
public virtual bool AllowRecursiveDeletion { get; protected set; }
|
||||||
|
|
||||||
|
public bool UseLazyLoad { get; protected set; }
|
||||||
|
|
||||||
|
public bool LazyLoading { get; protected set; }
|
||||||
|
|
||||||
|
public bool CanHandleEscape { get; protected set; }
|
||||||
|
|
||||||
protected AbstractContainer(TProvider provider, IContainer parent, string name) : this(name)
|
protected AbstractContainer(TProvider provider, IContainer parent, string name) : this(name)
|
||||||
{
|
{
|
||||||
_parent = parent;
|
_parent = parent;
|
||||||
@@ -56,7 +65,7 @@ namespace FileTime.Core.Providers
|
|||||||
|
|
||||||
private AbstractContainer(string name)
|
private AbstractContainer(string name)
|
||||||
{
|
{
|
||||||
Name = name;
|
DisplayName = Name = name;
|
||||||
Exceptions = _exceptions.AsReadOnly();
|
Exceptions = _exceptions.AsReadOnly();
|
||||||
Provider = null!;
|
Provider = null!;
|
||||||
}
|
}
|
||||||
@@ -152,5 +161,7 @@ namespace FileTime.Core.Providers
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void AddException(Exception e) => _exceptions.Add(e);
|
protected void AddException(Exception e) => _exceptions.Add(e);
|
||||||
|
|
||||||
|
public virtual Task<ContainerEscapeResult> HandleEscape() => Task.FromResult(new ContainerEscapeResult(false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
58
src/Core/FileTime.Core/Providers/AbstractElement.cs
Normal file
58
src/Core/FileTime.Core/Providers/AbstractElement.cs
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
using FileTime.Core.Models;
|
||||||
|
|
||||||
|
namespace FileTime.Core.Providers
|
||||||
|
{
|
||||||
|
public abstract class AbstractElement<TProvider> : IElement where TProvider : class, IContentProvider
|
||||||
|
{
|
||||||
|
private readonly IContainer _parent;
|
||||||
|
public bool IsSpecial { get; protected set; }
|
||||||
|
|
||||||
|
public string Name { get; protected set; }
|
||||||
|
|
||||||
|
public string DisplayName { get; protected set; }
|
||||||
|
|
||||||
|
public string? FullName { get; protected set; }
|
||||||
|
|
||||||
|
public string? NativePath { get; protected set; }
|
||||||
|
|
||||||
|
public bool IsHidden { get; protected set; }
|
||||||
|
|
||||||
|
public bool IsDestroyed { get; protected set; }
|
||||||
|
|
||||||
|
public virtual bool IsExists { get; protected set; }
|
||||||
|
|
||||||
|
public virtual SupportsDelete CanDelete { get; protected set; }
|
||||||
|
|
||||||
|
public virtual bool CanRename { get; protected set; }
|
||||||
|
|
||||||
|
public TProvider Provider { get; }
|
||||||
|
|
||||||
|
IContentProvider IItem.Provider => Provider;
|
||||||
|
|
||||||
|
protected AbstractElement(TProvider provider, IContainer parent, string name)
|
||||||
|
{
|
||||||
|
_parent = parent;
|
||||||
|
Provider = provider;
|
||||||
|
DisplayName = Name = name;
|
||||||
|
FullName = parent.FullName + Constants.SeparatorChar + name;
|
||||||
|
IsExists = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract Task Delete(bool hardDelete = false);
|
||||||
|
|
||||||
|
public virtual void Destroy() { }
|
||||||
|
|
||||||
|
public abstract Task<string> GetContent(CancellationToken token = default);
|
||||||
|
|
||||||
|
public abstract Task<IContentReader> GetContentReaderAsync();
|
||||||
|
|
||||||
|
public abstract Task<IContentWriter> GetContentWriterAsync();
|
||||||
|
|
||||||
|
public abstract Task<long?> GetElementSize(CancellationToken token = default);
|
||||||
|
|
||||||
|
public IContainer? GetParent() => _parent;
|
||||||
|
public abstract string GetPrimaryAttributeText();
|
||||||
|
|
||||||
|
public abstract Task Rename(string newName);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -12,6 +12,7 @@ namespace FileTime.Core.Providers
|
|||||||
|
|
||||||
#pragma warning disable CS8603 // Possible null reference return.
|
#pragma warning disable CS8603 // Possible null reference return.
|
||||||
public string Name => null;
|
public string Name => null;
|
||||||
|
public string DisplayName => null;
|
||||||
#pragma warning restore CS8603 // Possible null reference return.
|
#pragma warning restore CS8603 // Possible null reference return.
|
||||||
|
|
||||||
public string? FullName => null;
|
public string? FullName => null;
|
||||||
@@ -36,6 +37,12 @@ namespace FileTime.Core.Providers
|
|||||||
public bool IsExists => true;
|
public bool IsExists => true;
|
||||||
public bool AllowRecursiveDeletion => false;
|
public bool AllowRecursiveDeletion => false;
|
||||||
|
|
||||||
|
public bool UseLazyLoad => false;
|
||||||
|
|
||||||
|
public bool LazyLoading => false;
|
||||||
|
public bool CanHandleEscape => false;
|
||||||
|
public AsyncEventHandler<bool> LazyLoadingChanged { get; protected set; } = new();
|
||||||
|
|
||||||
public TopContainer(IEnumerable<IContentProvider> contentProviders)
|
public TopContainer(IEnumerable<IContentProvider> contentProviders)
|
||||||
{
|
{
|
||||||
_contentProviders = new List<IContentProvider>(contentProviders);
|
_contentProviders = new List<IContentProvider>(contentProviders);
|
||||||
@@ -75,5 +82,6 @@ namespace FileTime.Core.Providers
|
|||||||
public void Destroy() { }
|
public void Destroy() { }
|
||||||
|
|
||||||
public void Unload() { }
|
public void Unload() { }
|
||||||
|
public Task<ContainerEscapeResult> HandleEscape() => Task.FromResult(new ContainerEscapeResult(false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
40
src/Core/FileTime.Core/Search/ChildSearchContainer.cs
Normal file
40
src/Core/FileTime.Core/Search/ChildSearchContainer.cs
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
using AsyncEvent;
|
||||||
|
using FileTime.Core.Models;
|
||||||
|
using FileTime.Core.Providers;
|
||||||
|
|
||||||
|
namespace FileTime.Core.Search
|
||||||
|
{
|
||||||
|
public class ChildSearchContainer : AbstractContainer<IContentProvider>
|
||||||
|
{
|
||||||
|
public ChildSearchContainer(SearchContainer searchContainer, IContentProvider provider, IContainer baseContainer, string name, string displayName, List<ItemNamePart> searchDisplayName) : base(provider, baseContainer.GetParent()!, name)
|
||||||
|
{
|
||||||
|
DisplayName = displayName;
|
||||||
|
SearchContainer = searchContainer;
|
||||||
|
SearchDisplayName = searchDisplayName;
|
||||||
|
BaseContainer = baseContainer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool IsExists => true;
|
||||||
|
|
||||||
|
public SearchContainer SearchContainer { get; }
|
||||||
|
public List<ItemNamePart> SearchDisplayName { get; }
|
||||||
|
public IContainer BaseContainer { get; }
|
||||||
|
|
||||||
|
public override async Task RefreshAsync(CancellationToken token = default)
|
||||||
|
{
|
||||||
|
if (Refreshed != null) await Refreshed.InvokeAsync(this, AsyncEventArgs.Empty, token);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override Task<IContainer> CloneAsync() => throw new NotImplementedException();
|
||||||
|
|
||||||
|
public override Task<IContainer> CreateContainerAsync(string name) => throw new NotSupportedException();
|
||||||
|
|
||||||
|
public override Task<IElement> CreateElementAsync(string name) => throw new NotSupportedException();
|
||||||
|
|
||||||
|
public override Task Delete(bool hardDelete = false) => throw new NotSupportedException();
|
||||||
|
|
||||||
|
public override Task<IEnumerable<IItem>> RefreshItems(CancellationToken token = default) => throw new NotImplementedException();
|
||||||
|
|
||||||
|
public override Task Rename(string newName) => throw new NotSupportedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
33
src/Core/FileTime.Core/Search/ChildSearchElement.cs
Normal file
33
src/Core/FileTime.Core/Search/ChildSearchElement.cs
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
using FileTime.Core.Models;
|
||||||
|
using FileTime.Core.Providers;
|
||||||
|
|
||||||
|
namespace FileTime.Core.Search
|
||||||
|
{
|
||||||
|
public class ChildSearchElement : AbstractElement<IContentProvider>
|
||||||
|
{
|
||||||
|
public ChildSearchElement(SearchContainer searchContainer, IContentProvider provider, IContainer parent, string name, string displayName, List<ItemNamePart> searchDisplayName) : base(provider, parent, name)
|
||||||
|
{
|
||||||
|
DisplayName = displayName;
|
||||||
|
NativePath = FullName;
|
||||||
|
SearchContainer = searchContainer;
|
||||||
|
SearchDisplayName = searchDisplayName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SearchContainer SearchContainer { get; }
|
||||||
|
public List<ItemNamePart> SearchDisplayName { get; }
|
||||||
|
|
||||||
|
public override Task Delete(bool hardDelete = false) => throw new NotSupportedException();
|
||||||
|
|
||||||
|
public override Task<string> GetContent(CancellationToken token = default) => throw new NotSupportedException();
|
||||||
|
|
||||||
|
public override Task<IContentReader> GetContentReaderAsync() => throw new NotSupportedException();
|
||||||
|
|
||||||
|
public override Task<IContentWriter> GetContentWriterAsync() => throw new NotSupportedException();
|
||||||
|
|
||||||
|
public override Task<long?> GetElementSize(CancellationToken token = default) => Task.FromResult((long?)null);
|
||||||
|
|
||||||
|
public override string GetPrimaryAttributeText() => "";
|
||||||
|
|
||||||
|
public override Task Rename(string newName) => throw new NotSupportedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
17
src/Core/FileTime.Core/Search/NameRegexSearchTask.cs
Normal file
17
src/Core/FileTime.Core/Search/NameRegexSearchTask.cs
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using FileTime.Core.Models;
|
||||||
|
|
||||||
|
namespace FileTime.Core.Search
|
||||||
|
{
|
||||||
|
public class NameRegexSearchTask : SearchTaskBase
|
||||||
|
{
|
||||||
|
private readonly Regex _nameRegex;
|
||||||
|
|
||||||
|
public NameRegexSearchTask(string namePattern, IContainer searchBaseContainer) : base(searchBaseContainer)
|
||||||
|
{
|
||||||
|
_nameRegex = new Regex(namePattern);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override Task<bool> IsItemMatch(IItem item) => Task.FromResult(_nameRegex.IsMatch(item.Name));
|
||||||
|
}
|
||||||
|
}
|
||||||
21
src/Core/FileTime.Core/Search/NameSearchTask.cs
Normal file
21
src/Core/FileTime.Core/Search/NameSearchTask.cs
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
using FileTime.Core.Models;
|
||||||
|
using FileTime.Core.Services;
|
||||||
|
|
||||||
|
namespace FileTime.Core.Search
|
||||||
|
{
|
||||||
|
public class NameSearchTask : SearchTaskBase
|
||||||
|
{
|
||||||
|
private readonly string _name;
|
||||||
|
private readonly ItemNameConverterService _itemNameConverterService;
|
||||||
|
|
||||||
|
public NameSearchTask(string name, IContainer searchBaseContainer, ItemNameConverterService itemNameConverterService) : base(searchBaseContainer)
|
||||||
|
{
|
||||||
|
_name = name;
|
||||||
|
_itemNameConverterService = itemNameConverterService;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override Task<bool> IsItemMatch(IItem item) => Task.FromResult(item.Name.Contains(_name));
|
||||||
|
|
||||||
|
public override List<ItemNamePart> GetDisplayName(IItem item) => _itemNameConverterService.GetDisplayName(item, _name);
|
||||||
|
}
|
||||||
|
}
|
||||||
103
src/Core/FileTime.Core/Search/SearchContainer.cs
Normal file
103
src/Core/FileTime.Core/Search/SearchContainer.cs
Normal file
@@ -0,0 +1,103 @@
|
|||||||
|
using System.Threading.Tasks;
|
||||||
|
using AsyncEvent;
|
||||||
|
using FileTime.Core.Models;
|
||||||
|
using FileTime.Core.Providers;
|
||||||
|
|
||||||
|
namespace FileTime.Core.Search
|
||||||
|
{
|
||||||
|
public class SearchContainer : AbstractContainer<IContentProvider>
|
||||||
|
{
|
||||||
|
private int _childContainerCounter;
|
||||||
|
private int _childElementCounter;
|
||||||
|
private readonly List<IContainer> _containers;
|
||||||
|
private IReadOnlyList<IItem> _items;
|
||||||
|
private readonly List<IElement> _elements;
|
||||||
|
|
||||||
|
private readonly IReadOnlyList<IContainer> _containersReadOnly;
|
||||||
|
private readonly IReadOnlyList<IElement> _elementsReadOnly;
|
||||||
|
private readonly SearchTaskBase _searchTaskBase;
|
||||||
|
|
||||||
|
public IContainer SearchBaseContainer { get; }
|
||||||
|
public override bool IsExists => throw new NotImplementedException();
|
||||||
|
|
||||||
|
public SearchContainer(IContainer searchBaseContainer, SearchTaskBase searchTaskBase) : base(searchBaseContainer.Provider, searchBaseContainer.GetParent()!, searchBaseContainer.Name)
|
||||||
|
{
|
||||||
|
SearchBaseContainer = searchBaseContainer;
|
||||||
|
_containers = new List<IContainer>();
|
||||||
|
_elements = new List<IElement>();
|
||||||
|
_searchTaskBase = searchTaskBase;
|
||||||
|
|
||||||
|
_containersReadOnly = _containers.AsReadOnly();
|
||||||
|
_elementsReadOnly = _elements.AsReadOnly();
|
||||||
|
_items = _containers.Cast<IItem>().Concat(_elements).ToList().AsReadOnly();
|
||||||
|
|
||||||
|
UseLazyLoad = true;
|
||||||
|
CanHandleEscape = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task RunWithLazyLoading(Func<CancellationToken, Task> func, CancellationToken token = default)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
LazyLoading = true;
|
||||||
|
await LazyLoadingChanged.InvokeAsync(this, LazyLoading, token);
|
||||||
|
await func(token);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
LazyLoading = false;
|
||||||
|
await LazyLoadingChanged.InvokeAsync(this, LazyLoading, token);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task AddContainer(IContainer container)
|
||||||
|
{
|
||||||
|
var childContainer = new ChildSearchContainer(this, Provider, container, "container" + _childContainerCounter++, container.DisplayName, _searchTaskBase.GetDisplayName(container));
|
||||||
|
_containers.Add(childContainer);
|
||||||
|
await UpdateChildren();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task AddElement(IElement element)
|
||||||
|
{
|
||||||
|
var childElement = new ChildSearchElement(this, Provider, element.GetParent()!, "element" + _childElementCounter++, element.DisplayName, _searchTaskBase.GetDisplayName(element));
|
||||||
|
_elements.Add(childElement);
|
||||||
|
await UpdateChildren();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task UpdateChildren()
|
||||||
|
{
|
||||||
|
_items = _containers.Cast<IItem>().Concat(_elements).ToList().AsReadOnly();
|
||||||
|
await RefreshAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task RefreshAsync(CancellationToken token = default)
|
||||||
|
{
|
||||||
|
if (Refreshed != null) await Refreshed.InvokeAsync(this, AsyncEventArgs.Empty, token);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override Task<IReadOnlyList<IContainer>?> GetContainers(CancellationToken token = default) => Task.FromResult((IReadOnlyList<IContainer>?)_containersReadOnly);
|
||||||
|
|
||||||
|
public override Task<IReadOnlyList<IElement>?> GetElements(CancellationToken token = default) => Task.FromResult((IReadOnlyList<IElement>?)_elementsReadOnly);
|
||||||
|
|
||||||
|
public override Task<IReadOnlyList<IItem>?> GetItems(CancellationToken token = default) => Task.FromResult((IReadOnlyList<IItem>?)_items);
|
||||||
|
|
||||||
|
public override Task<IContainer> CloneAsync() => Task.FromResult((IContainer)this);
|
||||||
|
|
||||||
|
public override Task<IContainer> CreateContainerAsync(string name) => throw new NotSupportedException();
|
||||||
|
|
||||||
|
public override Task<IElement> CreateElementAsync(string name) => throw new NotSupportedException();
|
||||||
|
|
||||||
|
public override Task Delete(bool hardDelete = false) => throw new NotSupportedException();
|
||||||
|
|
||||||
|
public override Task<IEnumerable<IItem>> RefreshItems(CancellationToken token = default) => throw new NotImplementedException();
|
||||||
|
|
||||||
|
public override Task Rename(string newName) => throw new NotSupportedException();
|
||||||
|
|
||||||
|
public override Task<ContainerEscapeResult> HandleEscape()
|
||||||
|
{
|
||||||
|
if (_searchTaskBase.Cancel()) return Task.FromResult(new ContainerEscapeResult(true));
|
||||||
|
|
||||||
|
return Task.FromResult(new ContainerEscapeResult(SearchBaseContainer));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
127
src/Core/FileTime.Core/Search/SearchTaskBase.cs
Normal file
127
src/Core/FileTime.Core/Search/SearchTaskBase.cs
Normal file
@@ -0,0 +1,127 @@
|
|||||||
|
using FileTime.Core.Models;
|
||||||
|
|
||||||
|
namespace FileTime.Core.Search
|
||||||
|
{
|
||||||
|
public abstract class SearchTaskBase
|
||||||
|
{
|
||||||
|
private readonly object _searchGuard = new();
|
||||||
|
private readonly IContainer _baseContainer;
|
||||||
|
private CancellationTokenSource? _cancellationTokenSource;
|
||||||
|
|
||||||
|
public SearchContainer TargetContainer { get; }
|
||||||
|
public bool Searching { get; private set; }
|
||||||
|
|
||||||
|
protected SearchTaskBase(IContainer searchBaseContainer)
|
||||||
|
{
|
||||||
|
TargetContainer = new SearchContainer(searchBaseContainer, this);
|
||||||
|
_baseContainer = searchBaseContainer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Start()
|
||||||
|
{
|
||||||
|
lock (_searchGuard)
|
||||||
|
{
|
||||||
|
if (Searching) return;
|
||||||
|
Searching = true;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_cancellationTokenSource?.Cancel();
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
}
|
||||||
|
|
||||||
|
new Thread(BootstrapSearch).Start();
|
||||||
|
|
||||||
|
void BootstrapSearch()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Task.Run(Search).Wait();
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
lock (_searchGuard)
|
||||||
|
{
|
||||||
|
Searching = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task Search()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (_cancellationTokenSource = new CancellationTokenSource())
|
||||||
|
{
|
||||||
|
await TargetContainer.RunWithLazyLoading(async (token) => await TraverseTree(_baseContainer, token), _cancellationTokenSource.Token);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
_cancellationTokenSource = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task TraverseTree(IContainer container, CancellationToken token = default)
|
||||||
|
{
|
||||||
|
if (token.IsCancellationRequested) return;
|
||||||
|
|
||||||
|
await container.RefreshAsync(token);
|
||||||
|
if (await IsItemMatch(container))
|
||||||
|
{
|
||||||
|
await AddContainer(container);
|
||||||
|
}
|
||||||
|
var childElements = await container.GetElements(token);
|
||||||
|
var childContainers = await container.GetContainers(token);
|
||||||
|
|
||||||
|
if (childElements != null)
|
||||||
|
{
|
||||||
|
await foreach (var childElement in
|
||||||
|
childElements
|
||||||
|
.ToAsyncEnumerable()
|
||||||
|
.WhereAwait(async e => await IsItemMatch(e))
|
||||||
|
)
|
||||||
|
{
|
||||||
|
if (token.IsCancellationRequested) return;
|
||||||
|
await AddElement(childElement);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (childContainers != null)
|
||||||
|
{
|
||||||
|
foreach (var childContainer in childContainers)
|
||||||
|
{
|
||||||
|
await TraverseTree(childContainer, token);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task AddContainer(IContainer container)
|
||||||
|
{
|
||||||
|
await TargetContainer.AddContainer(container);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task AddElement(IElement element)
|
||||||
|
{
|
||||||
|
await TargetContainer.AddElement(element);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract Task<bool> IsItemMatch(IItem item);
|
||||||
|
|
||||||
|
public virtual List<ItemNamePart> GetDisplayName(IItem item)
|
||||||
|
{
|
||||||
|
return new List<ItemNamePart>()
|
||||||
|
{
|
||||||
|
new ItemNamePart(item.Name)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Cancel()
|
||||||
|
{
|
||||||
|
if (!Searching || _cancellationTokenSource == null) return false;
|
||||||
|
_cancellationTokenSource?.Cancel();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,34 +1,25 @@
|
|||||||
using Avalonia.Media;
|
using FileTime.Core.Models;
|
||||||
using FileTime.Avalonia.Application;
|
|
||||||
using FileTime.Avalonia.Models;
|
|
||||||
using FileTime.Avalonia.ViewModels;
|
|
||||||
using FileTime.Core.Models;
|
|
||||||
using MvvmGen;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
namespace FileTime.Avalonia.Services
|
namespace FileTime.Core.Services
|
||||||
{
|
{
|
||||||
[ViewModel]
|
public class ItemNameConverterService
|
||||||
[Inject(typeof(AppState))]
|
|
||||||
public partial class ItemNameConverterService
|
|
||||||
{
|
{
|
||||||
public List<ItemNamePart> GetDisplayName(IItemViewModel itemViewModel)
|
public List<ItemNamePart> GetDisplayName(IItem item, string? searchText)
|
||||||
{
|
{
|
||||||
var nameParts = new List<ItemNamePart>();
|
var nameParts = new List<ItemNamePart>();
|
||||||
var rapidTravelText = AppState.RapidTravelText.ToLower();
|
searchText = searchText?.ToLower();
|
||||||
|
|
||||||
var name = itemViewModel.Item is IElement ? GetFileName(itemViewModel.Item.Name) : itemViewModel.Item.Name;
|
var name = item is IElement ? GetFileName(item.DisplayName) : item.DisplayName;
|
||||||
if (AppState.ViewMode == ViewMode.RapidTravel && rapidTravelText.Length > 0)
|
if (!string.IsNullOrEmpty(searchText))
|
||||||
{
|
{
|
||||||
var nameLeft = name;
|
var nameLeft = name;
|
||||||
|
|
||||||
while (nameLeft.ToLower().IndexOf(rapidTravelText, StringComparison.Ordinal) is int rapidTextStart && rapidTextStart != -1)
|
while (nameLeft.ToLower().IndexOf(searchText, StringComparison.Ordinal) is int rapidTextStart && rapidTextStart != -1)
|
||||||
{
|
{
|
||||||
var before = rapidTextStart > 0 ? nameLeft.Substring(0, rapidTextStart) : null;
|
var before = rapidTextStart > 0 ? nameLeft.Substring(0, rapidTextStart) : null;
|
||||||
var rapidTravel = nameLeft.Substring(rapidTextStart, rapidTravelText.Length);
|
var rapidTravel = nameLeft.Substring(rapidTextStart, searchText.Length);
|
||||||
|
|
||||||
nameLeft = nameLeft.Substring(rapidTextStart + rapidTravelText.Length);
|
nameLeft = nameLeft.Substring(rapidTextStart + searchText.Length);
|
||||||
|
|
||||||
if (before != null)
|
if (before != null)
|
||||||
{
|
{
|
||||||
@@ -14,6 +14,7 @@ namespace FileTime.Core.Timeline
|
|||||||
public AsyncEventHandler Refreshed { get; } = new AsyncEventHandler();
|
public AsyncEventHandler Refreshed { get; } = new AsyncEventHandler();
|
||||||
|
|
||||||
public string Name { get; }
|
public string Name { get; }
|
||||||
|
public string DisplayName { get; }
|
||||||
|
|
||||||
public string? FullName { get; }
|
public string? FullName { get; }
|
||||||
|
|
||||||
@@ -36,12 +37,18 @@ namespace FileTime.Core.Timeline
|
|||||||
public bool IsExists => true;
|
public bool IsExists => true;
|
||||||
public bool AllowRecursiveDeletion => true;
|
public bool AllowRecursiveDeletion => true;
|
||||||
|
|
||||||
|
public bool UseLazyLoad => false;
|
||||||
|
|
||||||
|
public bool LazyLoading => false;
|
||||||
|
public bool CanHandleEscape => false;
|
||||||
|
public AsyncEventHandler<bool> LazyLoadingChanged { get; protected set; } = new();
|
||||||
|
|
||||||
public TimeContainer(string name, IContainer parent, IContentProvider contentProvider, IContentProvider virtualContentProvider, PointInTime pointInTime)
|
public TimeContainer(string name, IContainer parent, IContentProvider contentProvider, IContentProvider virtualContentProvider, PointInTime pointInTime)
|
||||||
{
|
{
|
||||||
_parent = parent;
|
_parent = parent;
|
||||||
_pointInTime = pointInTime;
|
_pointInTime = pointInTime;
|
||||||
|
|
||||||
Name = name;
|
DisplayName = Name = name;
|
||||||
Provider = contentProvider;
|
Provider = contentProvider;
|
||||||
VirtualProvider = virtualContentProvider;
|
VirtualProvider = virtualContentProvider;
|
||||||
FullName = parent?.FullName == null ? Name : parent.FullName + Constants.SeparatorChar + Name;
|
FullName = parent?.FullName == null ? Name : parent.FullName + Constants.SeparatorChar + Name;
|
||||||
@@ -131,5 +138,6 @@ namespace FileTime.Core.Timeline
|
|||||||
|
|
||||||
public void Destroy() => IsDestroyed = true;
|
public void Destroy() => IsDestroyed = true;
|
||||||
public void Unload() { }
|
public void Unload() { }
|
||||||
|
public Task<ContainerEscapeResult> HandleEscape() => Task.FromResult(new ContainerEscapeResult(false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -10,7 +10,7 @@ namespace FileTime.Core.Timeline
|
|||||||
{
|
{
|
||||||
_parent = parent;
|
_parent = parent;
|
||||||
|
|
||||||
Name = name;
|
DisplayName = Name = name;
|
||||||
FullName = parent?.FullName == null ? Name : parent.FullName + Constants.SeparatorChar + Name;
|
FullName = parent?.FullName == null ? Name : parent.FullName + Constants.SeparatorChar + Name;
|
||||||
Provider = contentProvider;
|
Provider = contentProvider;
|
||||||
VirtualProvider = virtualContentProvider;
|
VirtualProvider = virtualContentProvider;
|
||||||
@@ -19,6 +19,7 @@ namespace FileTime.Core.Timeline
|
|||||||
public bool IsSpecial => false;
|
public bool IsSpecial => false;
|
||||||
|
|
||||||
public string Name { get; }
|
public string Name { get; }
|
||||||
|
public string DisplayName { get; }
|
||||||
|
|
||||||
public string? FullName { get; }
|
public string? FullName { get; }
|
||||||
|
|
||||||
@@ -46,7 +47,7 @@ namespace FileTime.Core.Timeline
|
|||||||
public Task Rename(string newName) => Task.CompletedTask;
|
public Task Rename(string newName) => Task.CompletedTask;
|
||||||
|
|
||||||
public Task<string> GetContent(CancellationToken token = default) => Task.FromResult("");
|
public Task<string> GetContent(CancellationToken token = default) => Task.FromResult("");
|
||||||
public Task<long> GetElementSize(CancellationToken token = default) => Task.FromResult(-1L);
|
public Task<long?> GetElementSize(CancellationToken token = default) => Task.FromResult((long?)-1L);
|
||||||
|
|
||||||
public void Destroy() => IsDestroyed = true;
|
public void Destroy() => IsDestroyed = true;
|
||||||
|
|
||||||
|
|||||||
@@ -223,5 +223,18 @@
|
|||||||
</Setter.Value>
|
</Setter.Value>
|
||||||
</Setter>
|
</Setter>
|
||||||
</Style>
|
</Style>
|
||||||
|
|
||||||
|
<Style Selector="Image.LoadingAnimation">
|
||||||
|
<Style.Animations>
|
||||||
|
<Animation Duration="0:0:2" IterationCount="INFINITE" Easing="QuadraticEaseInOut">
|
||||||
|
<KeyFrame Cue="0%">
|
||||||
|
<Setter Property="RotateTransform.Angle" Value="45"/>
|
||||||
|
</KeyFrame>
|
||||||
|
<KeyFrame Cue="100%">
|
||||||
|
<Setter Property="RotateTransform.Angle" Value="405"/>
|
||||||
|
</KeyFrame>
|
||||||
|
</Animation>
|
||||||
|
</Style.Animations>
|
||||||
|
</Style>
|
||||||
</Application.Styles>
|
</Application.Styles>
|
||||||
</Application>
|
</Application>
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
using FileTime.Core.Components;
|
using FileTime.Core.Components;
|
||||||
using FileTime.Core.Models;
|
using FileTime.Core.Models;
|
||||||
using FileTime.Providers.Local;
|
using FileTime.Providers.Local;
|
||||||
using FileTime.Avalonia.Services;
|
|
||||||
using FileTime.Avalonia.ViewModels;
|
using FileTime.Avalonia.ViewModels;
|
||||||
using MvvmGen;
|
using MvvmGen;
|
||||||
using System;
|
using System;
|
||||||
@@ -12,14 +11,20 @@ using System.Threading.Tasks;
|
|||||||
using FileTime.App.Core.Tab;
|
using FileTime.App.Core.Tab;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using FileTime.Core.Timeline;
|
using FileTime.Core.Timeline;
|
||||||
|
using FileTime.Avalonia.ViewModels.ItemPreview;
|
||||||
|
using FileTime.Core.Search;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using FileTime.Core.Services;
|
||||||
|
|
||||||
namespace FileTime.Avalonia.Application
|
namespace FileTime.Avalonia.Application
|
||||||
{
|
{
|
||||||
[ViewModel]
|
[ViewModel]
|
||||||
|
[Inject(typeof(AppState))]
|
||||||
[Inject(typeof(ItemNameConverterService))]
|
[Inject(typeof(ItemNameConverterService))]
|
||||||
[Inject(typeof(LocalContentProvider))]
|
[Inject(typeof(LocalContentProvider))]
|
||||||
[Inject(typeof(Tab))]
|
[Inject(typeof(Tab))]
|
||||||
[Inject(typeof(TimeRunner), propertyName: "_timeRunner")]
|
[Inject(typeof(TimeRunner), propertyName: "_timeRunner")]
|
||||||
|
[Inject(typeof(IServiceProvider), PropertyName = "_serviceProvider")]
|
||||||
public partial class TabContainer : INewItemProcessor
|
public partial class TabContainer : INewItemProcessor
|
||||||
{
|
{
|
||||||
private bool _updateFromCode;
|
private bool _updateFromCode;
|
||||||
@@ -63,7 +68,7 @@ namespace FileTime.Avalonia.Application
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Property]
|
[Property]
|
||||||
private ElementPreviewViewModel? _elementPreview;
|
private IItemPreviewViewModel? _itemPreview;
|
||||||
|
|
||||||
public async Task SetSelectedItemAsync(IItemViewModel? value)
|
public async Task SetSelectedItemAsync(IItemViewModel? value)
|
||||||
{
|
{
|
||||||
@@ -104,7 +109,7 @@ namespace FileTime.Avalonia.Application
|
|||||||
|
|
||||||
var currentLocation = await Tab.GetCurrentLocation();
|
var currentLocation = await Tab.GetCurrentLocation();
|
||||||
var parent = GenerateParent(currentLocation);
|
var parent = GenerateParent(currentLocation);
|
||||||
CurrentLocation = new ContainerViewModel(this, parent, currentLocation, ItemNameConverterService);
|
CurrentLocation = new ContainerViewModel(this, parent, currentLocation, ItemNameConverterService, AppState);
|
||||||
await CurrentLocation.Init();
|
await CurrentLocation.Init();
|
||||||
|
|
||||||
if (parent != null)
|
if (parent != null)
|
||||||
@@ -127,7 +132,7 @@ namespace FileTime.Avalonia.Application
|
|||||||
if (parentContainer == null) return null;
|
if (parentContainer == null) return null;
|
||||||
var parentParent = recursive ? GenerateParent(parentContainer.GetParent(), recursive) : null;
|
var parentParent = recursive ? GenerateParent(parentContainer.GetParent(), recursive) : null;
|
||||||
|
|
||||||
var parent = new ContainerViewModel(this, parentParent, parentContainer, ItemNameConverterService);
|
var parent = new ContainerViewModel(this, parentParent, parentContainer, ItemNameConverterService, AppState);
|
||||||
parentParent?.ChildrenToAdopt.Add(parent);
|
parentParent?.ChildrenToAdopt.Add(parent);
|
||||||
return parent;
|
return parent;
|
||||||
}
|
}
|
||||||
@@ -136,7 +141,7 @@ namespace FileTime.Avalonia.Application
|
|||||||
{
|
{
|
||||||
var currentLocation = await Tab.GetCurrentLocation(token);
|
var currentLocation = await Tab.GetCurrentLocation(token);
|
||||||
var parent = GenerateParent(currentLocation);
|
var parent = GenerateParent(currentLocation);
|
||||||
CurrentLocation = new ContainerViewModel(this, parent, currentLocation, ItemNameConverterService);
|
CurrentLocation = new ContainerViewModel(this, parent, currentLocation, ItemNameConverterService, AppState);
|
||||||
await CurrentLocation.Init(token: token);
|
await CurrentLocation.Init(token: token);
|
||||||
|
|
||||||
if (token.IsCancellationRequested) return;
|
if (token.IsCancellationRequested) return;
|
||||||
@@ -179,7 +184,7 @@ namespace FileTime.Avalonia.Application
|
|||||||
if (currentSelectenItem is ContainerViewModel currentSelectedContainer)
|
if (currentSelectenItem is ContainerViewModel currentSelectedContainer)
|
||||||
{
|
{
|
||||||
await SetSelectedItemAsync(currentSelectedContainer);
|
await SetSelectedItemAsync(currentSelectedContainer);
|
||||||
newChildContainer = currentSelectedContainer;
|
newChildContainer = currentSelectenItem is ChildSearchContainer ? null : currentSelectedContainer;
|
||||||
}
|
}
|
||||||
else if (currentSelectenItem is ElementViewModel element)
|
else if (currentSelectenItem is ElementViewModel element)
|
||||||
{
|
{
|
||||||
@@ -205,16 +210,30 @@ namespace FileTime.Avalonia.Application
|
|||||||
|
|
||||||
ChildContainer = newChildContainer;
|
ChildContainer = newChildContainer;
|
||||||
|
|
||||||
if (currentSelectenItem is ElementViewModel elementViewModel)
|
IItemPreviewViewModel? preview = null;
|
||||||
|
if (currentSelectenItem == null)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
else if (currentSelectenItem.Item is ChildSearchContainer searchContainer)
|
||||||
|
{
|
||||||
|
var searchContainerPreview = _serviceProvider.GetService<SearchContainerPreview>()!;
|
||||||
|
await searchContainerPreview.Init(searchContainer, _currentLocation.Container);
|
||||||
|
preview = searchContainerPreview;
|
||||||
|
}
|
||||||
|
else if (currentSelectenItem.Item is ChildSearchElement searchElement)
|
||||||
|
{
|
||||||
|
var searchElementPreview = _serviceProvider.GetService<SearchElementPreview>()!;
|
||||||
|
await searchElementPreview.Init(searchElement, _currentLocation.Container);
|
||||||
|
preview = searchElementPreview;
|
||||||
|
}
|
||||||
|
else if (currentSelectenItem is ElementViewModel elementViewModel)
|
||||||
{
|
{
|
||||||
var elementPreview = new ElementPreviewViewModel();
|
var elementPreview = new ElementPreviewViewModel();
|
||||||
await elementPreview.Init(elementViewModel.Element);
|
await elementPreview.Init(elementViewModel.Element);
|
||||||
ElementPreview = elementPreview;
|
preview = elementPreview;
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ElementPreview = null;
|
|
||||||
}
|
}
|
||||||
|
ItemPreview = preview;
|
||||||
/*}
|
/*}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
@@ -310,10 +329,7 @@ namespace FileTime.Avalonia.Application
|
|||||||
|
|
||||||
public async Task Open()
|
public async Task Open()
|
||||||
{
|
{
|
||||||
if (ChildContainer != null)
|
await RunFromCode(Tab.Open);
|
||||||
{
|
|
||||||
await RunFromCode(Tab.Open);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task GoUp()
|
public async Task GoUp()
|
||||||
|
|||||||
3
src/GuiApp/FileTime.Avalonia/Assets/loading.svg
Normal file
3
src/GuiApp/FileTime.Avalonia/Assets/loading.svg
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
<svg style="width:24px;height:24px" viewBox="0 0 24 24">
|
||||||
|
<path fill="white" d="M12,4V2A10,10 0 0,0 2,12H4A8,8 0 0,1 12,4Z" />
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 136 B |
@@ -55,6 +55,8 @@ namespace FileTime.Avalonia.Configuration
|
|||||||
new CommandBindingConfiguration(Commands.Cut, new[] { Key.D, Key.D }),
|
new CommandBindingConfiguration(Commands.Cut, new[] { Key.D, Key.D }),
|
||||||
new CommandBindingConfiguration(Commands.Edit, new KeyConfig(Key.F4)),
|
new CommandBindingConfiguration(Commands.Edit, new KeyConfig(Key.F4)),
|
||||||
new CommandBindingConfiguration(Commands.EnterRapidTravel, new KeyConfig(Key.OemComma, shift: true)),
|
new CommandBindingConfiguration(Commands.EnterRapidTravel, new KeyConfig(Key.OemComma, shift: true)),
|
||||||
|
new CommandBindingConfiguration(Commands.FindByName, new[] { Key.F, Key.N }),
|
||||||
|
new CommandBindingConfiguration(Commands.FindByNameRegex, new[] { Key.F, Key.R }),
|
||||||
new CommandBindingConfiguration(Commands.GoToHome, new[] { Key.G, Key.H }),
|
new CommandBindingConfiguration(Commands.GoToHome, new[] { Key.G, Key.H }),
|
||||||
new CommandBindingConfiguration(Commands.GoToPath, new KeyConfig(Key.OemComma, ctrl: true)),
|
new CommandBindingConfiguration(Commands.GoToPath, new KeyConfig(Key.OemComma, ctrl: true)),
|
||||||
new CommandBindingConfiguration(Commands.GoToPath, new[] { Key.G, Key.P }),
|
new CommandBindingConfiguration(Commands.GoToPath, new[] { Key.G, Key.P }),
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using Avalonia.Data.Converters;
|
using Avalonia.Data.Converters;
|
||||||
using FileTime.Avalonia.Services;
|
using FileTime.Core.Services;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
||||||
namespace FileTime.Avalonia.Converters
|
namespace FileTime.Avalonia.Converters
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ using System.Globalization;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Avalonia.Data.Converters;
|
using Avalonia.Data.Converters;
|
||||||
using Avalonia.Media;
|
using Avalonia.Media;
|
||||||
using FileTime.Avalonia.Models;
|
|
||||||
using FileTime.Avalonia.ViewModels;
|
using FileTime.Avalonia.ViewModels;
|
||||||
|
using FileTime.Core.Models;
|
||||||
|
|
||||||
namespace FileTime.Avalonia.Converters
|
namespace FileTime.Avalonia.Converters
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
namespace FileTime.Avalonia.Models
|
|
||||||
{
|
|
||||||
public enum ElementPreviewMode
|
|
||||||
{
|
|
||||||
Unknown,
|
|
||||||
Text,
|
|
||||||
Empty
|
|
||||||
}
|
|
||||||
}
|
|
||||||
11
src/GuiApp/FileTime.Avalonia/Models/ItemPreviewMode.cs
Normal file
11
src/GuiApp/FileTime.Avalonia/Models/ItemPreviewMode.cs
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
namespace FileTime.Avalonia.Models
|
||||||
|
{
|
||||||
|
public enum ItemPreviewMode
|
||||||
|
{
|
||||||
|
Unknown,
|
||||||
|
Text,
|
||||||
|
Empty,
|
||||||
|
SearchContainer,
|
||||||
|
SearchElement
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -22,6 +22,8 @@ using FileTime.Core.Components;
|
|||||||
using FileTime.Core.Interactions;
|
using FileTime.Core.Interactions;
|
||||||
using FileTime.Core.Models;
|
using FileTime.Core.Models;
|
||||||
using FileTime.Core.Providers;
|
using FileTime.Core.Providers;
|
||||||
|
using FileTime.Core.Search;
|
||||||
|
using FileTime.Core.Services;
|
||||||
using FileTime.Core.Timeline;
|
using FileTime.Core.Timeline;
|
||||||
using FileTime.Providers.Local;
|
using FileTime.Providers.Local;
|
||||||
using FileTime.Tools.Compression.Command;
|
using FileTime.Tools.Compression.Command;
|
||||||
@@ -44,6 +46,7 @@ namespace FileTime.Avalonia.Services
|
|||||||
private readonly Dictionary<Commands, Func<Task>> _commandHandlers;
|
private readonly Dictionary<Commands, Func<Task>> _commandHandlers;
|
||||||
private readonly ProgramsService _programsService;
|
private readonly ProgramsService _programsService;
|
||||||
private readonly ILogger<CommandHandlerService> _logger;
|
private readonly ILogger<CommandHandlerService> _logger;
|
||||||
|
private readonly IServiceProvider _serviceProvider;
|
||||||
|
|
||||||
public CommandHandlerService(
|
public CommandHandlerService(
|
||||||
AppState appState,
|
AppState appState,
|
||||||
@@ -55,7 +58,8 @@ namespace FileTime.Avalonia.Services
|
|||||||
IIconProvider iconProvider,
|
IIconProvider iconProvider,
|
||||||
IEnumerable<IContentProvider> contentProviders,
|
IEnumerable<IContentProvider> contentProviders,
|
||||||
ProgramsService programsService,
|
ProgramsService programsService,
|
||||||
ILogger<CommandHandlerService> logger)
|
ILogger<CommandHandlerService> logger,
|
||||||
|
IServiceProvider serviceProvider)
|
||||||
{
|
{
|
||||||
_appState = appState;
|
_appState = appState;
|
||||||
_localContentProvider = localContentProvider;
|
_localContentProvider = localContentProvider;
|
||||||
@@ -67,6 +71,7 @@ namespace FileTime.Avalonia.Services
|
|||||||
_contentProviders = contentProviders;
|
_contentProviders = contentProviders;
|
||||||
_programsService = programsService;
|
_programsService = programsService;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
|
_serviceProvider = serviceProvider;
|
||||||
|
|
||||||
_commandHandlers = new Dictionary<Commands, Func<Task>>
|
_commandHandlers = new Dictionary<Commands, Func<Task>>
|
||||||
{
|
{
|
||||||
@@ -82,6 +87,8 @@ namespace FileTime.Avalonia.Services
|
|||||||
{Commands.Cut, Cut},
|
{Commands.Cut, Cut},
|
||||||
{Commands.Edit, Edit},
|
{Commands.Edit, Edit},
|
||||||
{Commands.EnterRapidTravel, EnterRapidTravelMode},
|
{Commands.EnterRapidTravel, EnterRapidTravelMode},
|
||||||
|
{Commands.FindByName, FindByName},
|
||||||
|
{Commands.FindByNameRegex, FindByNameRegex},
|
||||||
{Commands.GoToHome, GotToHome},
|
{Commands.GoToHome, GotToHome},
|
||||||
{Commands.GoToPath, GoToContainer},
|
{Commands.GoToPath, GoToContainer},
|
||||||
{Commands.GoToProvider, GotToProvider},
|
{Commands.GoToProvider, GotToProvider},
|
||||||
@@ -235,7 +242,7 @@ namespace FileTime.Avalonia.Services
|
|||||||
var newTab = new Tab();
|
var newTab = new Tab();
|
||||||
await newTab.Init(newContainer);
|
await newTab.Init(newContainer);
|
||||||
|
|
||||||
tabContainer = new TabContainer(_timeRunner, newTab, _localContentProvider, _itemNameConverterService);
|
tabContainer = new TabContainer(_serviceProvider, _timeRunner, newTab, _localContentProvider, _itemNameConverterService, _appState);
|
||||||
await tabContainer.Init(number);
|
await tabContainer.Init(number);
|
||||||
|
|
||||||
var i = 0;
|
var i = 0;
|
||||||
@@ -940,5 +947,53 @@ namespace FileTime.Avalonia.Services
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Task FindByName()
|
||||||
|
{
|
||||||
|
var handler = async (List<InputElementWrapper> inputs) =>
|
||||||
|
{
|
||||||
|
var container = _appState.SelectedTab.CurrentLocation.Container;
|
||||||
|
while (container is SearchContainer searchContainer)
|
||||||
|
{
|
||||||
|
container = searchContainer.SearchBaseContainer;
|
||||||
|
}
|
||||||
|
|
||||||
|
var search = new NameSearchTask(inputs[0].Value, container, _itemNameConverterService);
|
||||||
|
search.Start();
|
||||||
|
|
||||||
|
await OpenContainer(search.TargetContainer);
|
||||||
|
};
|
||||||
|
|
||||||
|
_dialogService.ReadInputs(new List<InputElement>()
|
||||||
|
{
|
||||||
|
InputElement.ForText("Item name pattern")
|
||||||
|
}, handler);
|
||||||
|
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Task FindByNameRegex()
|
||||||
|
{
|
||||||
|
var handler = async (List<InputElementWrapper> inputs) =>
|
||||||
|
{
|
||||||
|
var container = _appState.SelectedTab.CurrentLocation.Container;
|
||||||
|
while (container is SearchContainer searchContainer)
|
||||||
|
{
|
||||||
|
container = searchContainer.SearchBaseContainer;
|
||||||
|
}
|
||||||
|
|
||||||
|
var search = new NameRegexSearchTask(inputs[0].Value, container);
|
||||||
|
search.Start();
|
||||||
|
|
||||||
|
await OpenContainer(search.TargetContainer);
|
||||||
|
};
|
||||||
|
|
||||||
|
_dialogService.ReadInputs(new List<InputElement>()
|
||||||
|
{
|
||||||
|
InputElement.ForText("Item name pattern")
|
||||||
|
}, handler);
|
||||||
|
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -69,11 +69,41 @@ namespace FileTime.Avalonia.Services
|
|||||||
|
|
||||||
if (key == Key.Escape)
|
if (key == Key.Escape)
|
||||||
{
|
{
|
||||||
_appState.IsAllShortcutVisible = false;
|
var doGeneralReset = false;
|
||||||
_appState.MessageBoxText = null;
|
if (_appState.PreviousKeys.Count > 1 || _appState.IsAllShortcutVisible || _appState.MessageBoxText != null)
|
||||||
_appState.PreviousKeys.Clear();
|
{
|
||||||
_appState.PossibleCommands = new();
|
doGeneralReset = true;
|
||||||
setHandled(true);
|
}
|
||||||
|
else if (_appState.SelectedTab.CurrentLocation.Container.CanHandleEscape)
|
||||||
|
{
|
||||||
|
var escapeResult = await _appState.SelectedTab.CurrentLocation.Container.HandleEscape();
|
||||||
|
if (escapeResult.NavigateTo != null)
|
||||||
|
{
|
||||||
|
setHandled(true);
|
||||||
|
_appState.PreviousKeys.Clear();
|
||||||
|
await _appState.SelectedTab.OpenContainer(escapeResult.NavigateTo);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(escapeResult.Handled)
|
||||||
|
{
|
||||||
|
_appState.PreviousKeys.Clear();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
doGeneralReset = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (doGeneralReset)
|
||||||
|
{
|
||||||
|
setHandled(true);
|
||||||
|
_appState.IsAllShortcutVisible = false;
|
||||||
|
_appState.MessageBoxText = null;
|
||||||
|
_appState.PreviousKeys.Clear();
|
||||||
|
_appState.PossibleCommands = new();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (key == Key.Enter
|
else if (key == Key.Enter
|
||||||
&& _appState.MessageBoxText != null)
|
&& _appState.MessageBoxText != null)
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ using FileTime.Providers.Local;
|
|||||||
using FileTime.Core.Models;
|
using FileTime.Core.Models;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using FileTime.Core.Timeline;
|
using FileTime.Core.Timeline;
|
||||||
|
using FileTime.Core.Services;
|
||||||
|
|
||||||
namespace FileTime.Avalonia.Services
|
namespace FileTime.Avalonia.Services
|
||||||
{
|
{
|
||||||
@@ -25,6 +26,7 @@ namespace FileTime.Avalonia.Services
|
|||||||
private readonly LocalContentProvider _localContentProvider;
|
private readonly LocalContentProvider _localContentProvider;
|
||||||
private readonly ILogger<StatePersistenceService> _logger;
|
private readonly ILogger<StatePersistenceService> _logger;
|
||||||
private readonly TimeRunner _timeRunner;
|
private readonly TimeRunner _timeRunner;
|
||||||
|
private readonly IServiceProvider _serviceProvider;
|
||||||
|
|
||||||
public StatePersistenceService(
|
public StatePersistenceService(
|
||||||
AppState appState,
|
AppState appState,
|
||||||
@@ -32,7 +34,8 @@ namespace FileTime.Avalonia.Services
|
|||||||
IEnumerable<IContentProvider> contentProviders,
|
IEnumerable<IContentProvider> contentProviders,
|
||||||
LocalContentProvider localContentProvider,
|
LocalContentProvider localContentProvider,
|
||||||
ILogger<StatePersistenceService> logger,
|
ILogger<StatePersistenceService> logger,
|
||||||
TimeRunner timeRunner)
|
TimeRunner timeRunner,
|
||||||
|
IServiceProvider serviceProvider)
|
||||||
{
|
{
|
||||||
_appState = appState;
|
_appState = appState;
|
||||||
_itemNameConverterService = itemNameConverterService;
|
_itemNameConverterService = itemNameConverterService;
|
||||||
@@ -40,13 +43,14 @@ namespace FileTime.Avalonia.Services
|
|||||||
_localContentProvider = localContentProvider;
|
_localContentProvider = localContentProvider;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_settingsPath = Path.Combine(Program.AppDataRoot, "savedState.json");
|
_settingsPath = Path.Combine(Program.AppDataRoot, "savedState.json");
|
||||||
|
_timeRunner = timeRunner;
|
||||||
|
_serviceProvider = serviceProvider;
|
||||||
|
|
||||||
_jsonOptions = new JsonSerializerOptions()
|
_jsonOptions = new JsonSerializerOptions()
|
||||||
{
|
{
|
||||||
PropertyNameCaseInsensitive = true,
|
PropertyNameCaseInsensitive = true,
|
||||||
WriteIndented = true
|
WriteIndented = true
|
||||||
};
|
};
|
||||||
this._timeRunner = timeRunner;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task LoadStatesAsync()
|
public async Task LoadStatesAsync()
|
||||||
@@ -153,7 +157,7 @@ namespace FileTime.Avalonia.Services
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var newTabContainer = new TabContainer(_timeRunner, newTab, _localContentProvider, _itemNameConverterService);
|
var newTabContainer = new TabContainer(_serviceProvider, _timeRunner, newTab, _localContentProvider, _itemNameConverterService, _appState);
|
||||||
await newTabContainer.Init(tab.Number);
|
await newTabContainer.Init(tab.Number);
|
||||||
_appState.Tabs.Add(newTabContainer);
|
_appState.Tabs.Add(newTabContainer);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ using FileTime.Avalonia.IconProviders;
|
|||||||
using FileTime.Avalonia.Logging;
|
using FileTime.Avalonia.Logging;
|
||||||
using FileTime.Avalonia.Services;
|
using FileTime.Avalonia.Services;
|
||||||
using FileTime.Avalonia.ViewModels;
|
using FileTime.Avalonia.ViewModels;
|
||||||
|
using FileTime.Avalonia.ViewModels.ItemPreview;
|
||||||
using FileTime.Core.Command;
|
using FileTime.Core.Command;
|
||||||
using FileTime.Core.Interactions;
|
using FileTime.Core.Interactions;
|
||||||
using FileTime.Core.Persistence;
|
using FileTime.Core.Persistence;
|
||||||
@@ -23,13 +24,14 @@ namespace FileTime.Avalonia
|
|||||||
{
|
{
|
||||||
return serviceCollection
|
return serviceCollection
|
||||||
.AddTransient<MainPageViewModel>()
|
.AddTransient<MainPageViewModel>()
|
||||||
|
.AddTransient<SearchElementPreview>()
|
||||||
|
.AddTransient<SearchContainerPreview>()
|
||||||
.AddSingleton<IInputInterface, BasicInputHandler>();
|
.AddSingleton<IInputInterface, BasicInputHandler>();
|
||||||
}
|
}
|
||||||
internal static IServiceCollection AddServices(this IServiceCollection serviceCollection)
|
internal static IServiceCollection AddServices(this IServiceCollection serviceCollection)
|
||||||
{
|
{
|
||||||
serviceCollection = serviceCollection
|
serviceCollection = serviceCollection
|
||||||
.AddSingleton<AppState>()
|
.AddSingleton<AppState>()
|
||||||
.AddSingleton<ItemNameConverterService>()
|
|
||||||
.AddSingleton<StatePersistenceService>()
|
.AddSingleton<StatePersistenceService>()
|
||||||
.AddSingleton<CommandHandlerService>()
|
.AddSingleton<CommandHandlerService>()
|
||||||
.AddSingleton<KeyboardConfigurationService>()
|
.AddSingleton<KeyboardConfigurationService>()
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using AsyncEvent;
|
using AsyncEvent;
|
||||||
using FileTime.Core.Models;
|
using FileTime.Core.Models;
|
||||||
|
using FileTime.Avalonia.Application;
|
||||||
using FileTime.Avalonia.Models;
|
using FileTime.Avalonia.Models;
|
||||||
using FileTime.Avalonia.Services;
|
using FileTime.Avalonia.Services;
|
||||||
using MvvmGen;
|
using MvvmGen;
|
||||||
@@ -11,10 +12,12 @@ using System.Text;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using FileTime.Avalonia.Application;
|
using FileTime.Avalonia.Application;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
using FileTime.Core.Services;
|
||||||
|
|
||||||
namespace FileTime.Avalonia.ViewModels
|
namespace FileTime.Avalonia.ViewModels
|
||||||
{
|
{
|
||||||
[ViewModel]
|
[ViewModel]
|
||||||
|
[Inject(typeof(AppState))]
|
||||||
[Inject(typeof(ItemNameConverterService))]
|
[Inject(typeof(ItemNameConverterService))]
|
||||||
public partial class ContainerViewModel : IItemViewModel
|
public partial class ContainerViewModel : IItemViewModel
|
||||||
{
|
{
|
||||||
@@ -51,6 +54,8 @@ namespace FileTime.Avalonia.ViewModels
|
|||||||
|
|
||||||
public List<IItemViewModel> ChildrenToAdopt { get; } = new List<IItemViewModel>();
|
public List<IItemViewModel> ChildrenToAdopt { get; } = new List<IItemViewModel>();
|
||||||
|
|
||||||
|
public bool LazyLoading => _container.LazyLoading;
|
||||||
|
|
||||||
[PropertyInvalidate(nameof(IsSelected))]
|
[PropertyInvalidate(nameof(IsSelected))]
|
||||||
[PropertyInvalidate(nameof(IsAlternative))]
|
[PropertyInvalidate(nameof(IsAlternative))]
|
||||||
[PropertyInvalidate(nameof(IsMarked))]
|
[PropertyInvalidate(nameof(IsMarked))]
|
||||||
@@ -65,7 +70,7 @@ namespace FileTime.Avalonia.ViewModels
|
|||||||
_ => ItemViewMode.Default
|
_ => ItemViewMode.Default
|
||||||
};
|
};
|
||||||
|
|
||||||
public List<ItemNamePart> DisplayName => ItemNameConverterService.GetDisplayName(this);
|
public List<ItemNamePart> DisplayName => ItemNameConverterService.GetDisplayName(Item, AppState.ViewMode == Application.ViewMode.RapidTravel ? AppState.RapidTravelText : null);
|
||||||
|
|
||||||
public Task Containers => GetContainers();
|
public Task Containers => GetContainers();
|
||||||
public Task Elements => GetElements();
|
public Task Elements => GetElements();
|
||||||
@@ -116,13 +121,14 @@ namespace FileTime.Avalonia.ViewModels
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ContainerViewModel(INewItemProcessor newItemProcessor, ContainerViewModel? parent, IContainer container, ItemNameConverterService itemNameConverterService) : this(itemNameConverterService)
|
public ContainerViewModel(INewItemProcessor newItemProcessor, ContainerViewModel? parent, IContainer container, ItemNameConverterService itemNameConverterService, AppState appState) : this(itemNameConverterService, appState)
|
||||||
{
|
{
|
||||||
_newItemProcessor = newItemProcessor;
|
_newItemProcessor = newItemProcessor;
|
||||||
Parent = parent;
|
Parent = parent;
|
||||||
|
|
||||||
Container = container;
|
Container = container;
|
||||||
Container.Refreshed.Add(Container_Refreshed);
|
Container.Refreshed.Add(Container_Refreshed);
|
||||||
|
Container.LazyLoadingChanged.Add(Container_LazyLoadingChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void InvalidateDisplayName() => OnPropertyChanged(nameof(DisplayName));
|
public void InvalidateDisplayName() => OnPropertyChanged(nameof(DisplayName));
|
||||||
@@ -138,6 +144,12 @@ namespace FileTime.Avalonia.ViewModels
|
|||||||
await Refresh(false, false, token: token);
|
await Refresh(false, false, token: token);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Task Container_LazyLoadingChanged(object? sender, bool lazyLoading, CancellationToken token = default)
|
||||||
|
{
|
||||||
|
OnPropertyChanged(nameof(LazyLoading));
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
[Obsolete($"Use the parametrizable version of {nameof(Refresh)}.")]
|
[Obsolete($"Use the parametrizable version of {nameof(Refresh)}.")]
|
||||||
private async Task Refresh()
|
private async Task Refresh()
|
||||||
{
|
{
|
||||||
@@ -161,7 +173,7 @@ namespace FileTime.Avalonia.ViewModels
|
|||||||
{
|
{
|
||||||
foreach (var container in containers)
|
foreach (var container in containers)
|
||||||
{
|
{
|
||||||
newContainers.Add(await AdoptOrReuseOrCreateItem(container, alloweReuse, (c2) => new ContainerViewModel(_newItemProcessor, this, c2, ItemNameConverterService)));
|
newContainers.Add(await AdoptOrReuseOrCreateItem(container, alloweReuse, (c2) => new ContainerViewModel(_newItemProcessor, this, c2, ItemNameConverterService, AppState)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -171,7 +183,7 @@ namespace FileTime.Avalonia.ViewModels
|
|||||||
{
|
{
|
||||||
var generator = async (IElement e) =>
|
var generator = async (IElement e) =>
|
||||||
{
|
{
|
||||||
var element = new ElementViewModel(e, this, ItemNameConverterService);
|
var element = new ElementViewModel(e, this, ItemNameConverterService, AppState);
|
||||||
await element.Init();
|
await element.Init();
|
||||||
return element;
|
return element;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -4,10 +4,13 @@ using FileTime.Avalonia.Services;
|
|||||||
using MvvmGen;
|
using MvvmGen;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using FileTime.Avalonia.Application;
|
||||||
|
using FileTime.Core.Services;
|
||||||
|
|
||||||
namespace FileTime.Avalonia.ViewModels
|
namespace FileTime.Avalonia.ViewModels
|
||||||
{
|
{
|
||||||
[ViewModel]
|
[ViewModel]
|
||||||
|
[Inject(typeof(AppState))]
|
||||||
[Inject(typeof(ItemNameConverterService))]
|
[Inject(typeof(ItemNameConverterService))]
|
||||||
public partial class ElementViewModel : IItemViewModel
|
public partial class ElementViewModel : IItemViewModel
|
||||||
{
|
{
|
||||||
@@ -29,7 +32,7 @@ namespace FileTime.Avalonia.ViewModels
|
|||||||
private ContainerViewModel? _parent;
|
private ContainerViewModel? _parent;
|
||||||
|
|
||||||
[Property]
|
[Property]
|
||||||
private long _size;
|
private long? _size;
|
||||||
|
|
||||||
[PropertyInvalidate(nameof(IsSelected))]
|
[PropertyInvalidate(nameof(IsSelected))]
|
||||||
[PropertyInvalidate(nameof(IsAlternative))]
|
[PropertyInvalidate(nameof(IsAlternative))]
|
||||||
@@ -45,9 +48,9 @@ namespace FileTime.Avalonia.ViewModels
|
|||||||
_ => ItemViewMode.Default
|
_ => ItemViewMode.Default
|
||||||
};
|
};
|
||||||
|
|
||||||
public List<ItemNamePart> DisplayName => ItemNameConverterService.GetDisplayName(this);
|
public List<ItemNamePart> DisplayName => ItemNameConverterService.GetDisplayName(Item, AppState.ViewMode == Application.ViewMode.RapidTravel ? AppState.RapidTravelText : null);
|
||||||
|
|
||||||
public ElementViewModel(IElement element, ContainerViewModel parent, ItemNameConverterService itemNameConverterService) : this(itemNameConverterService)
|
public ElementViewModel(IElement element, ContainerViewModel parent, ItemNameConverterService itemNameConverterService, AppState appState) : this(itemNameConverterService, appState)
|
||||||
{
|
{
|
||||||
Element = element;
|
Element = element;
|
||||||
Parent = parent;
|
Parent = parent;
|
||||||
@@ -57,7 +60,11 @@ namespace FileTime.Avalonia.ViewModels
|
|||||||
|
|
||||||
public async Task Init()
|
public async Task Init()
|
||||||
{
|
{
|
||||||
Size = await _element.GetElementSize();
|
try
|
||||||
|
{
|
||||||
|
Size = await _element.GetElementSize();
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,16 +2,13 @@
|
|||||||
using FileTime.Core.Models;
|
using FileTime.Core.Models;
|
||||||
using MvvmGen;
|
using MvvmGen;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace FileTime.Avalonia.ViewModels
|
namespace FileTime.Avalonia.ViewModels.ItemPreview
|
||||||
{
|
{
|
||||||
[ViewModel]
|
[ViewModel]
|
||||||
public partial class ElementPreviewViewModel
|
public partial class ElementPreviewViewModel : IItemPreviewViewModel
|
||||||
{
|
{
|
||||||
private const int MAXTEXTPREVIEWSIZE = 1024 * 1024;
|
private const int MAXTEXTPREVIEWSIZE = 1024 * 1024;
|
||||||
[Property]
|
[Property]
|
||||||
@@ -21,16 +18,23 @@ namespace FileTime.Avalonia.ViewModels
|
|||||||
private string? _textContent;
|
private string? _textContent;
|
||||||
|
|
||||||
[Property]
|
[Property]
|
||||||
private ElementPreviewMode? _mode;
|
private ItemPreviewMode _mode = ItemPreviewMode.Unknown;
|
||||||
|
|
||||||
public async Task Init(IElement element, CancellationToken token = default)
|
public async Task Init(IElement element, CancellationToken token = default)
|
||||||
{
|
{
|
||||||
Element = element;
|
Element = element;
|
||||||
|
|
||||||
var elementSize = await element.GetElementSize(token);
|
long? elementSize = null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
elementSize = await element.GetElementSize(token);
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
|
||||||
if (elementSize == 0)
|
if (elementSize == 0)
|
||||||
{
|
{
|
||||||
Mode = ElementPreviewMode.Empty;
|
Mode = ItemPreviewMode.Empty;
|
||||||
}
|
}
|
||||||
else if (elementSize < MAXTEXTPREVIEWSIZE)
|
else if (elementSize < MAXTEXTPREVIEWSIZE)
|
||||||
{
|
{
|
||||||
@@ -38,15 +42,15 @@ namespace FileTime.Avalonia.ViewModels
|
|||||||
{
|
{
|
||||||
TextContent = await element.GetContent();
|
TextContent = await element.GetContent();
|
||||||
}
|
}
|
||||||
catch(Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
TextContent = $"Error while getting content of {element.FullName}. " + e.ToString();
|
TextContent = $"Error while getting content of {element.FullName}. " + e.ToString();
|
||||||
}
|
}
|
||||||
Mode = ElementPreviewMode.Text;
|
Mode = ItemPreviewMode.Text;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Mode = ElementPreviewMode.Unknown;
|
Mode = ItemPreviewMode.Unknown;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
using FileTime.Avalonia.Models;
|
||||||
|
|
||||||
|
namespace FileTime.Avalonia.ViewModels.ItemPreview
|
||||||
|
{
|
||||||
|
public interface IItemPreviewViewModel
|
||||||
|
{
|
||||||
|
ItemPreviewMode Mode { get; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
using Avalonia.Media;
|
||||||
|
using Avalonia.Threading;
|
||||||
|
using FileTime.Avalonia.Models;
|
||||||
|
using FileTime.Core.Helper;
|
||||||
|
using FileTime.Core.Models;
|
||||||
|
using FileTime.Core.Search;
|
||||||
|
using MvvmGen;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace FileTime.Avalonia.ViewModels.ItemPreview
|
||||||
|
{
|
||||||
|
[ViewModel]
|
||||||
|
public partial class SearchContainerPreview : IItemPreviewViewModel
|
||||||
|
{
|
||||||
|
[Property]
|
||||||
|
private ItemPreviewMode _mode = ItemPreviewMode.SearchContainer;
|
||||||
|
|
||||||
|
[Property]
|
||||||
|
private List<ItemNamePartViewModel>? _itemNameParts;
|
||||||
|
|
||||||
|
[Property]
|
||||||
|
private string? _realtiveParentPath;
|
||||||
|
|
||||||
|
public async Task Init(ChildSearchContainer container, IContainer currentLocation)
|
||||||
|
{
|
||||||
|
var pathCommonPath = PathHelper.GetCommonPath(currentLocation.FullName!, container.FullName!);
|
||||||
|
RealtiveParentPath = new AbsolutePath(null!, container.FullName!.Substring(pathCommonPath.Length).Trim(Constants.SeparatorChar), AbsolutePathType.Unknown, null).GetParentPath();
|
||||||
|
ItemNameParts = await Task.Run(async () => await Dispatcher.UIThread.InvokeAsync(() => container.SearchDisplayName.Select(p => new ItemNamePartViewModel(p.Text, p.IsSpecial ? TextDecorations.Underline : null)).ToList()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
using Avalonia.Media;
|
||||||
|
using Avalonia.Threading;
|
||||||
|
using FileTime.Avalonia.Models;
|
||||||
|
using FileTime.Avalonia.Services;
|
||||||
|
using FileTime.Core.Helper;
|
||||||
|
using FileTime.Core.Models;
|
||||||
|
using FileTime.Core.Search;
|
||||||
|
using MvvmGen;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace FileTime.Avalonia.ViewModels.ItemPreview
|
||||||
|
{
|
||||||
|
[ViewModel]
|
||||||
|
public partial class SearchElementPreview : IItemPreviewViewModel
|
||||||
|
{
|
||||||
|
|
||||||
|
[Property]
|
||||||
|
private ItemPreviewMode _mode = ItemPreviewMode.SearchElement;
|
||||||
|
|
||||||
|
[Property]
|
||||||
|
private List<ItemNamePartViewModel>? _itemNameParts;
|
||||||
|
|
||||||
|
[Property]
|
||||||
|
private string? _realtiveParentPath;
|
||||||
|
|
||||||
|
public async Task Init(ChildSearchElement element, IContainer currentLocation)
|
||||||
|
{
|
||||||
|
var pathCommonPath = PathHelper.GetCommonPath(currentLocation.FullName!, element.FullName!);
|
||||||
|
RealtiveParentPath = new AbsolutePath(null!, element.FullName!.Substring(pathCommonPath.Length).Trim(Constants.SeparatorChar), AbsolutePathType.Unknown, null).GetParentPath();
|
||||||
|
ItemNameParts = await Task.Run(async () => await Dispatcher.UIThread.InvokeAsync(() => element.SearchDisplayName.Select(p => new ItemNamePartViewModel(p.Text, p.IsSpecial ? TextDecorations.Underline : null)).ToList()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -17,11 +17,11 @@ using Microsoft.Extensions.DependencyInjection;
|
|||||||
using FileTime.Core.Timeline;
|
using FileTime.Core.Timeline;
|
||||||
using FileTime.Core.Providers;
|
using FileTime.Core.Providers;
|
||||||
using Syroot.Windows.IO;
|
using Syroot.Windows.IO;
|
||||||
using FileTime.Avalonia.IconProviders;
|
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using Avalonia.Input;
|
using Avalonia.Input;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using FileTime.Core.Services;
|
||||||
|
|
||||||
namespace FileTime.Avalonia.ViewModels
|
namespace FileTime.Avalonia.ViewModels
|
||||||
{
|
{
|
||||||
@@ -35,6 +35,7 @@ namespace FileTime.Avalonia.ViewModels
|
|||||||
[Inject(typeof(CommandHandlerService), PropertyAccessModifier = AccessModifier.Public)]
|
[Inject(typeof(CommandHandlerService), PropertyAccessModifier = AccessModifier.Public)]
|
||||||
[Inject(typeof(IDialogService), PropertyName = "_dialogService")]
|
[Inject(typeof(IDialogService), PropertyName = "_dialogService")]
|
||||||
[Inject(typeof(KeyInputHandlerService))]
|
[Inject(typeof(KeyInputHandlerService))]
|
||||||
|
[Inject(typeof(IServiceProvider), PropertyName = "_serviceProvider")]
|
||||||
public partial class MainPageViewModel : IMainPageViewModelBase
|
public partial class MainPageViewModel : IMainPageViewModelBase
|
||||||
{
|
{
|
||||||
public const string RAPIDTRAVEL = "rapidTravel";
|
public const string RAPIDTRAVEL = "rapidTravel";
|
||||||
@@ -84,7 +85,7 @@ namespace FileTime.Avalonia.ViewModels
|
|||||||
var tab = new Tab();
|
var tab = new Tab();
|
||||||
await tab.Init(LocalContentProvider);
|
await tab.Init(LocalContentProvider);
|
||||||
|
|
||||||
var tabContainer = new TabContainer(_timeRunner, tab, LocalContentProvider, ItemNameConverterService);
|
var tabContainer = new TabContainer(_serviceProvider, _timeRunner, tab, LocalContentProvider, ItemNameConverterService, AppState);
|
||||||
await tabContainer.Init(1);
|
await tabContainer.Init(1);
|
||||||
tabContainer.IsSelected = true;
|
tabContainer.IsSelected = true;
|
||||||
AppState.Tabs.Add(tabContainer);
|
AppState.Tabs.Add(tabContainer);
|
||||||
|
|||||||
@@ -37,7 +37,7 @@
|
|||||||
<StackPanel Margin="20,10" Orientation="Horizontal">
|
<StackPanel Margin="20,10" Orientation="Horizontal">
|
||||||
<local:PathPresenter DataContext="{Binding AppState.SelectedTab.CurrentLocation.Container.FullName,Converter={StaticResource PathPreformatter}}"/>
|
<local:PathPresenter DataContext="{Binding AppState.SelectedTab.CurrentLocation.Container.FullName,Converter={StaticResource PathPreformatter}}"/>
|
||||||
<TextBlock
|
<TextBlock
|
||||||
Text="{Binding AppState.SelectedTab.SelectedItem.Item.Name}" Foreground="{StaticResource AccentBrush}" />
|
Text="{Binding AppState.SelectedTab.SelectedItem.Item.DisplayName}" Foreground="{StaticResource AccentBrush}" />
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
@@ -242,8 +242,12 @@
|
|||||||
VerticalAlignment="Stretch"
|
VerticalAlignment="Stretch"
|
||||||
Fill="{DynamicResource ContentSeparatorBrush}" />
|
Fill="{DynamicResource ContentSeparatorBrush}" />
|
||||||
|
|
||||||
<Grid Grid.Column="2">
|
<Grid Grid.Column="2" RowDefinitions="Auto,*">
|
||||||
|
<Grid IsVisible="{Binding AppState.SelectedTab.CurrentLocation.LazyLoading}">
|
||||||
|
<Image Width="40" Height="40" Source="{SvgImage /Assets/loading.svg}" Classes="LoadingAnimation"/>
|
||||||
|
</Grid>
|
||||||
<ListBox
|
<ListBox
|
||||||
|
Grid.Row="1"
|
||||||
x:Name="CurrentItems"
|
x:Name="CurrentItems"
|
||||||
x:CompileBindings="False"
|
x:CompileBindings="False"
|
||||||
AutoScrollToSelectedItem="True"
|
AutoScrollToSelectedItem="True"
|
||||||
@@ -261,6 +265,7 @@
|
|||||||
</ListBox>
|
</ListBox>
|
||||||
|
|
||||||
<TextBlock
|
<TextBlock
|
||||||
|
Grid.Row="1"
|
||||||
x:CompileBindings="False"
|
x:CompileBindings="False"
|
||||||
x:Name="CurrentEmpty"
|
x:Name="CurrentEmpty"
|
||||||
Margin="10"
|
Margin="10"
|
||||||
@@ -300,15 +305,17 @@
|
|||||||
x:CompileBindings="False"
|
x:CompileBindings="False"
|
||||||
IsVisible="{Binding AppState.SelectedTab.ChildContainer.Items^.Count, Converter={StaticResource EqualityConverter}, ConverterParameter=0}">
|
IsVisible="{Binding AppState.SelectedTab.ChildContainer.Items^.Count, Converter={StaticResource EqualityConverter}, ConverterParameter=0}">
|
||||||
|
|
||||||
<TextBlock
|
<Grid IsVisible="{Binding AppState.SelectedTab.ItemPreview, Converter={StaticResource IsNullConverter}}">
|
||||||
x:Name="ChildEmpty"
|
<TextBlock
|
||||||
Margin="10"
|
x:Name="ChildEmpty"
|
||||||
HorizontalAlignment="Center"
|
Margin="10"
|
||||||
FontWeight="Bold"
|
HorizontalAlignment="Center"
|
||||||
Foreground="{DynamicResource ErrorBrush}"
|
FontWeight="Bold"
|
||||||
IsVisible="{Binding AppState.SelectedTab.ChildContainer.Exceptions.Count, Converter={StaticResource EqualityConverter}, ConverterParameter=0}">
|
Foreground="{DynamicResource ErrorBrush}"
|
||||||
Empty
|
IsVisible="{Binding AppState.SelectedTab.ChildContainer.Exceptions.Count, Converter={StaticResource EqualityConverter}, ConverterParameter=0}">
|
||||||
</TextBlock>
|
Empty
|
||||||
|
</TextBlock>
|
||||||
|
</Grid>
|
||||||
|
|
||||||
<Grid
|
<Grid
|
||||||
RowDefinitions="Auto, Auto"
|
RowDefinitions="Auto, Auto"
|
||||||
@@ -332,14 +339,65 @@
|
|||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
<Grid IsVisible="{Binding AppState.SelectedTab.ElementPreview, Converter={StaticResource IsNotNullConverter}}">
|
<Grid IsVisible="{Binding AppState.SelectedTab.ItemPreview, Converter={StaticResource IsNotNullConverter}}">
|
||||||
<TextBlock HorizontalAlignment="Center" Text="Don't know how to preview this file" IsVisible="{Binding AppState.SelectedTab.ElementPreview.Mode, Converter={StaticResource EqualityConverter}, ConverterParameter={x:Static models:ElementPreviewMode.Unknown}}"/>
|
<TextBlock HorizontalAlignment="Center" Text="Don't know how to preview this item." IsVisible="{Binding AppState.SelectedTab.ItemPreview.Mode, Converter={StaticResource EqualityConverter}, ConverterParameter={x:Static models:ItemPreviewMode.Unknown}}"/>
|
||||||
<TextBlock HorizontalAlignment="Center" Text="Empty" IsVisible="{Binding AppState.SelectedTab.ElementPreview.Mode, Converter={StaticResource EqualityConverter}, ConverterParameter={x:Static models:ElementPreviewMode.Empty}}"/>
|
<TextBlock HorizontalAlignment="Center" Text="Empty" IsVisible="{Binding AppState.SelectedTab.ItemPreview.Mode, Converter={StaticResource EqualityConverter}, ConverterParameter={x:Static models:ItemPreviewMode.Empty}}"/>
|
||||||
<ScrollViewer IsVisible="{Binding AppState.SelectedTab.ElementPreview.Mode, Converter={StaticResource EqualityConverter}, ConverterParameter={x:Static models:ElementPreviewMode.Text}}">
|
<ScrollViewer IsVisible="{Binding AppState.SelectedTab.ItemPreview.Mode, Converter={StaticResource EqualityConverter}, ConverterParameter={x:Static models:ItemPreviewMode.Text}}">
|
||||||
<TextBox
|
<TextBox
|
||||||
IsReadOnly="True"
|
IsReadOnly="True"
|
||||||
Text="{Binding AppState.SelectedTab.ElementPreview.TextContent}" />
|
x:CompileBindings="False"
|
||||||
|
Text="{Binding AppState.SelectedTab.ItemPreview.TextContent}" />
|
||||||
</ScrollViewer>
|
</ScrollViewer>
|
||||||
|
<Grid
|
||||||
|
IsVisible="{Binding AppState.SelectedTab.ItemPreview.Mode, Converter={StaticResource EqualityConverter}, ConverterParameter={x:Static models:ItemPreviewMode.SearchContainer}}"
|
||||||
|
ColumnDefinitions="Auto,*"
|
||||||
|
RowDefinitions="Auto,Auto">
|
||||||
|
<TextBlock Text="Name" Margin="0,0,10,20" VerticalAlignment="Top"/>
|
||||||
|
<ItemsControl Grid.Column="1" x:CompileBindings="False" Items="{Binding AppState.SelectedTab.ItemPreview.ItemNameParts}" VerticalAlignment="Top">
|
||||||
|
<ItemsControl.ItemsPanel>
|
||||||
|
<ItemsPanelTemplate>
|
||||||
|
<StackPanel Orientation="Horizontal" />
|
||||||
|
</ItemsPanelTemplate>
|
||||||
|
</ItemsControl.ItemsPanel>
|
||||||
|
<ItemsControl.ItemTemplate>
|
||||||
|
<DataTemplate>
|
||||||
|
<Grid>
|
||||||
|
<TextBlock
|
||||||
|
Text="{Binding Text}"
|
||||||
|
TextDecorations="{Binding TextDecorations}"/>
|
||||||
|
</Grid>
|
||||||
|
</DataTemplate>
|
||||||
|
</ItemsControl.ItemTemplate>
|
||||||
|
</ItemsControl>
|
||||||
|
|
||||||
|
<TextBlock Margin="0,0,10,0" Grid.Row="1" Text="Path"/>
|
||||||
|
<local:PathPresenter Grid.Column="1" Grid.Row="1" x:CompileBindings="False" DataContext="{Binding AppState.SelectedTab.ItemPreview.RealtiveParentPath,Converter={StaticResource PathPreformatter}}"/>
|
||||||
|
</Grid>
|
||||||
|
<Grid
|
||||||
|
IsVisible="{Binding AppState.SelectedTab.ItemPreview.Mode, Converter={StaticResource EqualityConverter}, ConverterParameter={x:Static models:ItemPreviewMode.SearchElement}}"
|
||||||
|
ColumnDefinitions="Auto,*"
|
||||||
|
RowDefinitions="Auto,Auto">
|
||||||
|
<TextBlock Text="Name" Margin="0,0,10,20" VerticalAlignment="Top"/>
|
||||||
|
<ItemsControl Grid.Column="1" x:CompileBindings="False" Items="{Binding AppState.SelectedTab.ItemPreview.ItemNameParts}" Margin="0,0,0,20">
|
||||||
|
<ItemsControl.ItemsPanel>
|
||||||
|
<ItemsPanelTemplate>
|
||||||
|
<StackPanel Orientation="Horizontal" />
|
||||||
|
</ItemsPanelTemplate>
|
||||||
|
</ItemsControl.ItemsPanel>
|
||||||
|
<ItemsControl.ItemTemplate>
|
||||||
|
<DataTemplate>
|
||||||
|
<Grid>
|
||||||
|
<TextBlock
|
||||||
|
Text="{Binding Text}"
|
||||||
|
TextDecorations="{Binding TextDecorations}"/>
|
||||||
|
</Grid>
|
||||||
|
</DataTemplate>
|
||||||
|
</ItemsControl.ItemTemplate>
|
||||||
|
</ItemsControl>
|
||||||
|
|
||||||
|
<TextBlock Margin="0,0,10,0" Grid.Row="1" Text="Path"/>
|
||||||
|
<local:PathPresenter Grid.Column="1" Grid.Row="1" x:CompileBindings="False" DataContext="{Binding AppState.SelectedTab.ItemPreview.RealtiveParentPath,Converter={StaticResource PathPreformatter}}"/>
|
||||||
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ namespace FileTime.Providers.Local
|
|||||||
public FileInfo File { get; }
|
public FileInfo File { get; }
|
||||||
|
|
||||||
public string Name { get; }
|
public string Name { get; }
|
||||||
|
public string DisplayName { get; }
|
||||||
|
|
||||||
public string FullName { get; }
|
public string FullName { get; }
|
||||||
public string? NativePath => File.FullName;
|
public string? NativePath => File.FullName;
|
||||||
@@ -39,7 +40,7 @@ namespace FileTime.Providers.Local
|
|||||||
_parent = parent;
|
_parent = parent;
|
||||||
File = file;
|
File = file;
|
||||||
|
|
||||||
Name = file.Name;
|
DisplayName = Name = file.Name;
|
||||||
FullName = parent.FullName + Constants.SeparatorChar + file.Name;
|
FullName = parent.FullName + Constants.SeparatorChar + file.Name;
|
||||||
Provider = contentProvider;
|
Provider = contentProvider;
|
||||||
}
|
}
|
||||||
@@ -86,7 +87,7 @@ namespace FileTime.Providers.Local
|
|||||||
public IContainer? GetParent() => _parent;
|
public IContainer? GetParent() => _parent;
|
||||||
|
|
||||||
public async Task<string> GetContent(CancellationToken token = default) => await System.IO.File.ReadAllTextAsync(File.FullName, token);
|
public async Task<string> GetContent(CancellationToken token = default) => await System.IO.File.ReadAllTextAsync(File.FullName, token);
|
||||||
public Task<long> GetElementSize(CancellationToken token = default) => Task.FromResult(File.Length);
|
public Task<long?> GetElementSize(CancellationToken token = default) => Task.FromResult((long?)File.Length);
|
||||||
|
|
||||||
public void Destroy() => IsDestroyed = true;
|
public void Destroy() => IsDestroyed = true;
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ namespace FileTime.Providers.Sftp
|
|||||||
public bool IsSpecial => throw new NotImplementedException();
|
public bool IsSpecial => throw new NotImplementedException();
|
||||||
|
|
||||||
public string Name => throw new NotImplementedException();
|
public string Name => throw new NotImplementedException();
|
||||||
|
public string DisplayName => throw new NotImplementedException();
|
||||||
|
|
||||||
public string? FullName => throw new NotImplementedException();
|
public string? FullName => throw new NotImplementedException();
|
||||||
|
|
||||||
@@ -50,7 +51,7 @@ namespace FileTime.Providers.Sftp
|
|||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<long> GetElementSize(CancellationToken token = default)
|
public Task<long?> GetElementSize(CancellationToken token = default)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ namespace FileTime.Providers.Smb
|
|||||||
public bool IsSpecial => false;
|
public bool IsSpecial => false;
|
||||||
|
|
||||||
public string Name { get; }
|
public string Name { get; }
|
||||||
|
public string DisplayName { get; }
|
||||||
|
|
||||||
public string? FullName { get; }
|
public string? FullName { get; }
|
||||||
public string? NativePath { get; }
|
public string? NativePath { get; }
|
||||||
@@ -34,7 +35,7 @@ namespace FileTime.Providers.Smb
|
|||||||
_smbClientContext = smbClientContext;
|
_smbClientContext = smbClientContext;
|
||||||
_smbShare = smbShare;
|
_smbShare = smbShare;
|
||||||
|
|
||||||
Name = name;
|
DisplayName = Name = name;
|
||||||
FullName = parent.FullName + Constants.SeparatorChar + Name;
|
FullName = parent.FullName + Constants.SeparatorChar + Name;
|
||||||
NativePath = parent.NativePath + SmbContentProvider.GetNativePathSeparator() + name;
|
NativePath = parent.NativePath + SmbContentProvider.GetNativePathSeparator() + name;
|
||||||
}
|
}
|
||||||
@@ -80,7 +81,7 @@ namespace FileTime.Providers.Smb
|
|||||||
|
|
||||||
public IContainer? GetParent() => _parent;
|
public IContainer? GetParent() => _parent;
|
||||||
public Task<string> GetContent(CancellationToken token = default) => Task.FromResult("NotImplemented");
|
public Task<string> GetContent(CancellationToken token = default) => Task.FromResult("NotImplemented");
|
||||||
public Task<long> GetElementSize(CancellationToken token = default) => Task.FromResult(-1L);
|
public Task<long?> GetElementSize(CancellationToken token = default) => Task.FromResult((long?)null);
|
||||||
|
|
||||||
public void Destroy() => IsDestroyed = true;
|
public void Destroy() => IsDestroyed = true;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user