Open by path
This commit is contained in:
@@ -0,0 +1,13 @@
|
|||||||
|
namespace FileTime.App.Core.UserCommand;
|
||||||
|
|
||||||
|
public class GoToPathCommand : IIdentifiableUserCommand
|
||||||
|
{
|
||||||
|
public const string CommandName = "go_to_path";
|
||||||
|
public static GoToPathCommand Instance { get; } = new GoToPathCommand();
|
||||||
|
|
||||||
|
private GoToPathCommand()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public string UserCommandID => CommandName;
|
||||||
|
}
|
||||||
@@ -130,7 +130,7 @@ public class ItemManipulationUserCommandHandlerService : UserCommandHandlerServi
|
|||||||
{
|
{
|
||||||
var containerNameInput = new TextInputElement("Container name");
|
var containerNameInput = new TextInputElement("Container name");
|
||||||
|
|
||||||
await _inputInterface.ReadInputs(new List<IInputElement>() { containerNameInput });
|
await _inputInterface.ReadInputs(containerNameInput);
|
||||||
|
|
||||||
//TODO: message on empty result
|
//TODO: message on empty result
|
||||||
var newContainerName = containerNameInput.Value;
|
var newContainerName = containerNameInput.Value;
|
||||||
@@ -147,7 +147,7 @@ public class ItemManipulationUserCommandHandlerService : UserCommandHandlerServi
|
|||||||
{
|
{
|
||||||
var containerNameInput = new TextInputElement("Element name");
|
var containerNameInput = new TextInputElement("Element name");
|
||||||
|
|
||||||
await _inputInterface.ReadInputs(new List<IInputElement>() { containerNameInput });
|
await _inputInterface.ReadInputs(containerNameInput);
|
||||||
|
|
||||||
//TODO: message on empty result
|
//TODO: message on empty result
|
||||||
var newContainerName = containerNameInput.Value;
|
var newContainerName = containerNameInput.Value;
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ using FileTime.App.Core.Extensions;
|
|||||||
using FileTime.App.Core.Models.Enums;
|
using FileTime.App.Core.Models.Enums;
|
||||||
using FileTime.App.Core.UserCommand;
|
using FileTime.App.Core.UserCommand;
|
||||||
using FileTime.App.Core.ViewModels;
|
using FileTime.App.Core.ViewModels;
|
||||||
|
using FileTime.Core.Interactions;
|
||||||
using FileTime.Core.Models;
|
using FileTime.Core.Models;
|
||||||
using FileTime.Core.Services;
|
using FileTime.Core.Services;
|
||||||
using FileTime.Core.Timeline;
|
using FileTime.Core.Timeline;
|
||||||
@@ -18,6 +19,7 @@ public class NavigationUserCommandHandlerService : UserCommandHandlerServiceBase
|
|||||||
private readonly ILocalContentProvider _localContentProvider;
|
private readonly ILocalContentProvider _localContentProvider;
|
||||||
private readonly IUserCommandHandlerService _userCommandHandlerService;
|
private readonly IUserCommandHandlerService _userCommandHandlerService;
|
||||||
private readonly ITimelessContentProvider _timelessContentProvider;
|
private readonly ITimelessContentProvider _timelessContentProvider;
|
||||||
|
private readonly IInputInterface _inputInterface;
|
||||||
private ITabViewModel? _selectedTab;
|
private ITabViewModel? _selectedTab;
|
||||||
private IContainer? _currentLocation;
|
private IContainer? _currentLocation;
|
||||||
private IItemViewModel? _currentSelectedItem;
|
private IItemViewModel? _currentSelectedItem;
|
||||||
@@ -29,13 +31,15 @@ public class NavigationUserCommandHandlerService : UserCommandHandlerServiceBase
|
|||||||
IServiceProvider serviceProvider,
|
IServiceProvider serviceProvider,
|
||||||
ILocalContentProvider localContentProvider,
|
ILocalContentProvider localContentProvider,
|
||||||
IUserCommandHandlerService userCommandHandlerService,
|
IUserCommandHandlerService userCommandHandlerService,
|
||||||
ITimelessContentProvider timelessContentProvider) : base(appState)
|
ITimelessContentProvider timelessContentProvider,
|
||||||
|
IInputInterface inputInterface) : base(appState)
|
||||||
{
|
{
|
||||||
_appState = appState;
|
_appState = appState;
|
||||||
_serviceProvider = serviceProvider;
|
_serviceProvider = serviceProvider;
|
||||||
_localContentProvider = localContentProvider;
|
_localContentProvider = localContentProvider;
|
||||||
_userCommandHandlerService = userCommandHandlerService;
|
_userCommandHandlerService = userCommandHandlerService;
|
||||||
_timelessContentProvider = timelessContentProvider;
|
_timelessContentProvider = timelessContentProvider;
|
||||||
|
_inputInterface = inputInterface;
|
||||||
|
|
||||||
SaveSelectedTab(t => _selectedTab = t);
|
SaveSelectedTab(t => _selectedTab = t);
|
||||||
SaveCurrentSelectedItem(i => _currentSelectedItem = i);
|
SaveCurrentSelectedItem(i => _currentSelectedItem = i);
|
||||||
@@ -50,6 +54,7 @@ public class NavigationUserCommandHandlerService : UserCommandHandlerServiceBase
|
|||||||
new TypeUserCommandHandler<EnterRapidTravelCommand>(EnterRapidTravel),
|
new TypeUserCommandHandler<EnterRapidTravelCommand>(EnterRapidTravel),
|
||||||
new TypeUserCommandHandler<ExitRapidTravelCommand>(ExitRapidTravel),
|
new TypeUserCommandHandler<ExitRapidTravelCommand>(ExitRapidTravel),
|
||||||
new TypeUserCommandHandler<GoToHomeCommand>(GoToHome),
|
new TypeUserCommandHandler<GoToHomeCommand>(GoToHome),
|
||||||
|
new TypeUserCommandHandler<GoToPathCommand>(GoToPath),
|
||||||
new TypeUserCommandHandler<GoToProviderCommand>(GoToProvider),
|
new TypeUserCommandHandler<GoToProviderCommand>(GoToProvider),
|
||||||
new TypeUserCommandHandler<GoToRootCommand>(GoToRoot),
|
new TypeUserCommandHandler<GoToRootCommand>(GoToRoot),
|
||||||
new TypeUserCommandHandler<GoUpCommand>(GoUp),
|
new TypeUserCommandHandler<GoUpCommand>(GoUp),
|
||||||
@@ -66,6 +71,20 @@ public class NavigationUserCommandHandlerService : UserCommandHandlerServiceBase
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task GoToPath()
|
||||||
|
{
|
||||||
|
var pathInput = new TextInputElement("Path");
|
||||||
|
await _inputInterface.ReadInputs(pathInput);
|
||||||
|
|
||||||
|
//TODO: message on empty result and on null pathInput.Value
|
||||||
|
var resolvedPath = await _timelessContentProvider.GetItemByNativePathAsync(new NativePath(pathInput.Value));
|
||||||
|
if (resolvedPath is IContainer container)
|
||||||
|
{
|
||||||
|
await _userCommandHandlerService.HandleCommandAsync(
|
||||||
|
new OpenContainerCommand(new AbsolutePath(_timelessContentProvider, container)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private async Task GoToHome()
|
private async Task GoToHome()
|
||||||
{
|
{
|
||||||
var path = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
|
var path = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ public class DefaultIdentifiableCommandHandlerRegister : IStartupHandler
|
|||||||
AddUserCommand(EnterRapidTravelCommand.Instance);
|
AddUserCommand(EnterRapidTravelCommand.Instance);
|
||||||
AddUserCommand(ExitRapidTravelCommand.Instance);
|
AddUserCommand(ExitRapidTravelCommand.Instance);
|
||||||
AddUserCommand(GoToHomeCommand.Instance);
|
AddUserCommand(GoToHomeCommand.Instance);
|
||||||
|
AddUserCommand(GoToPathCommand.Instance);
|
||||||
AddUserCommand(GoToProviderCommand.Instance);
|
AddUserCommand(GoToProviderCommand.Instance);
|
||||||
AddUserCommand(GoToRootCommand.Instance);
|
AddUserCommand(GoToRootCommand.Instance);
|
||||||
AddUserCommand(GoUpCommand.Instance);
|
AddUserCommand(GoUpCommand.Instance);
|
||||||
|
|||||||
@@ -24,4 +24,5 @@ public interface IContentProvider : IContainer, IOnContainerEnter
|
|||||||
NativePath GetNativePath(FullName fullName);
|
NativePath GetNativePath(FullName fullName);
|
||||||
|
|
||||||
Task<byte[]?> GetContentAsync(IElement element, int? maxLength = null, CancellationToken cancellationToken = default);
|
Task<byte[]?> GetContentAsync(IElement element, int? maxLength = null, CancellationToken cancellationToken = default);
|
||||||
|
bool CanHandlePath(NativePath path);
|
||||||
}
|
}
|
||||||
@@ -2,5 +2,5 @@ namespace FileTime.Core.Interactions;
|
|||||||
|
|
||||||
public interface IInputInterface
|
public interface IInputInterface
|
||||||
{
|
{
|
||||||
Task<bool> ReadInputs(IEnumerable<IInputElement> fields);
|
Task<bool> ReadInputs(params IInputElement[] fields);
|
||||||
}
|
}
|
||||||
@@ -13,4 +13,6 @@ public interface ITimelessContentProvider
|
|||||||
bool forceResolve = false,
|
bool forceResolve = false,
|
||||||
AbsolutePathType forceResolvePathType = AbsolutePathType.Unknown,
|
AbsolutePathType forceResolvePathType = AbsolutePathType.Unknown,
|
||||||
ItemInitializationSettings itemInitializationSettings = default);
|
ItemInitializationSettings itemInitializationSettings = default);
|
||||||
|
|
||||||
|
Task<IItem?> GetItemByNativePathAsync(NativePath nativePath, PointInTime? pointInTime = null);
|
||||||
}
|
}
|
||||||
@@ -81,4 +81,6 @@ public abstract class ContentProviderBase : IContentProvider
|
|||||||
public abstract Task<byte[]?> GetContentAsync(IElement element,
|
public abstract Task<byte[]?> GetContentAsync(IElement element,
|
||||||
int? maxLength = null,
|
int? maxLength = null,
|
||||||
CancellationToken cancellationToken = default);
|
CancellationToken cancellationToken = default);
|
||||||
|
|
||||||
|
public abstract bool CanHandlePath(NativePath path);
|
||||||
}
|
}
|
||||||
@@ -2,7 +2,6 @@ using System.Reactive.Subjects;
|
|||||||
using FileTime.Core.ContentAccess;
|
using FileTime.Core.ContentAccess;
|
||||||
using FileTime.Core.Enums;
|
using FileTime.Core.Enums;
|
||||||
using FileTime.Core.Models;
|
using FileTime.Core.Models;
|
||||||
using FileTime.Core.Services;
|
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
||||||
namespace FileTime.Core.Timeline;
|
namespace FileTime.Core.Timeline;
|
||||||
@@ -11,8 +10,7 @@ public class TimelessContentProvider : ITimelessContentProvider
|
|||||||
{
|
{
|
||||||
private readonly Lazy<List<IContentProvider>> _contentProviders;
|
private readonly Lazy<List<IContentProvider>> _contentProviders;
|
||||||
|
|
||||||
public BehaviorSubject<PointInTime> CurrentPointInTime { get; } =
|
public BehaviorSubject<PointInTime> CurrentPointInTime { get; } = new(PointInTime.Present);
|
||||||
new BehaviorSubject<PointInTime>(PointInTime.Present);
|
|
||||||
|
|
||||||
public TimelessContentProvider(IServiceProvider serviceProvider)
|
public TimelessContentProvider(IServiceProvider serviceProvider)
|
||||||
{
|
{
|
||||||
@@ -36,4 +34,16 @@ public class TimelessContentProvider : ITimelessContentProvider
|
|||||||
forceResolve, forceResolvePathType,
|
forceResolve, forceResolvePathType,
|
||||||
itemInitializationSettings);
|
itemInitializationSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<IItem?> GetItemByNativePathAsync(NativePath nativePath, PointInTime? pointInTime = null)
|
||||||
|
{
|
||||||
|
foreach (var contentProvider in _contentProviders.Value)
|
||||||
|
{
|
||||||
|
if(!contentProvider.CanHandlePath(nativePath)) continue;
|
||||||
|
|
||||||
|
return await contentProvider.GetItemByNativePathAsync(nativePath, pointInTime ?? PointInTime.Present);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -59,8 +59,8 @@ public static class MainConfiguration
|
|||||||
//new CommandBindingConfiguration(ConfigCommand.FindByName, new[] { Key.F, Key.N }),
|
//new CommandBindingConfiguration(ConfigCommand.FindByName, new[] { Key.F, Key.N }),
|
||||||
//new CommandBindingConfiguration(ConfigCommand.FindByNameRegex, new[] { Key.F, Key.R }),
|
//new CommandBindingConfiguration(ConfigCommand.FindByNameRegex, new[] { Key.F, Key.R }),
|
||||||
new CommandBindingConfiguration(GoToHomeCommand.CommandName, new[] { Key.G, Key.H }),
|
new CommandBindingConfiguration(GoToHomeCommand.CommandName, new[] { Key.G, Key.H }),
|
||||||
//new CommandBindingConfiguration(ConfigCommand.GoToPath, new KeyConfig(Key.L, ctrl: true)),
|
new CommandBindingConfiguration(GoToPathCommand.CommandName, new KeyConfig(Key.L, ctrl: true)),
|
||||||
//new CommandBindingConfiguration(ConfigCommand.GoToPath, new[] { Key.G, Key.P }),
|
new CommandBindingConfiguration(GoToPathCommand.CommandName, new[] { Key.G, Key.P }),
|
||||||
new CommandBindingConfiguration(GoToProviderCommand.CommandName, new[] { Key.G, Key.T }),
|
new CommandBindingConfiguration(GoToProviderCommand.CommandName, new[] { Key.G, Key.T }),
|
||||||
new CommandBindingConfiguration(GoToRootCommand.CommandName, new[] { Key.G, Key.R }),
|
new CommandBindingConfiguration(GoToRootCommand.CommandName, new[] { Key.G, Key.R }),
|
||||||
//new CommandBindingConfiguration(ConfigCommand.HardDelete, new[] { new KeyConfig(Key.D,shift: true), new KeyConfig(Key.D, shift: true) }),
|
//new CommandBindingConfiguration(ConfigCommand.HardDelete, new[] { new KeyConfig(Key.D,shift: true), new KeyConfig(Key.D, shift: true) }),
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ public class DialogService : IDialogService
|
|||||||
readInputsViewModel.CancelHandler?.Invoke();
|
readInputsViewModel.CancelHandler?.Invoke();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<bool> ReadInputs(IEnumerable<IInputElement> fields)
|
public Task<bool> ReadInputs(params IInputElement[] fields)
|
||||||
{
|
{
|
||||||
var taskCompletionSource = new TaskCompletionSource<bool>();
|
var taskCompletionSource = new TaskCompletionSource<bool>();
|
||||||
ReadInputs(fields, () => taskCompletionSource.SetResult(true), () => taskCompletionSource.SetResult(false));
|
ReadInputs(fields, () => taskCompletionSource.SetResult(true), () => taskCompletionSource.SetResult(false));
|
||||||
|
|||||||
@@ -46,6 +46,22 @@ public sealed partial class LocalContentProvider : ContentProviderBase, ILocalCo
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override bool CanHandlePath(NativePath path)
|
||||||
|
{
|
||||||
|
var rootDrive = _rootDirectories
|
||||||
|
.Items
|
||||||
|
.FirstOrDefault(r =>
|
||||||
|
path.Path.StartsWith(
|
||||||
|
GetNativePath(r.Path).Path,
|
||||||
|
_isCaseInsensitive
|
||||||
|
? StringComparison.InvariantCultureIgnoreCase
|
||||||
|
: StringComparison.InvariantCulture
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
return rootDrive is not null;
|
||||||
|
}
|
||||||
|
|
||||||
public override Task<IItem> GetItemByNativePathAsync(NativePath nativePath,
|
public override Task<IItem> GetItemByNativePathAsync(NativePath nativePath,
|
||||||
PointInTime pointInTime,
|
PointInTime pointInTime,
|
||||||
bool forceResolve = false,
|
bool forceResolve = false,
|
||||||
|
|||||||
Reference in New Issue
Block a user