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");
|
||||
|
||||
await _inputInterface.ReadInputs(new List<IInputElement>() { containerNameInput });
|
||||
await _inputInterface.ReadInputs(containerNameInput);
|
||||
|
||||
//TODO: message on empty result
|
||||
var newContainerName = containerNameInput.Value;
|
||||
@@ -147,7 +147,7 @@ public class ItemManipulationUserCommandHandlerService : UserCommandHandlerServi
|
||||
{
|
||||
var containerNameInput = new TextInputElement("Element name");
|
||||
|
||||
await _inputInterface.ReadInputs(new List<IInputElement>() { containerNameInput });
|
||||
await _inputInterface.ReadInputs(containerNameInput);
|
||||
|
||||
//TODO: message on empty result
|
||||
var newContainerName = containerNameInput.Value;
|
||||
|
||||
@@ -2,6 +2,7 @@ using FileTime.App.Core.Extensions;
|
||||
using FileTime.App.Core.Models.Enums;
|
||||
using FileTime.App.Core.UserCommand;
|
||||
using FileTime.App.Core.ViewModels;
|
||||
using FileTime.Core.Interactions;
|
||||
using FileTime.Core.Models;
|
||||
using FileTime.Core.Services;
|
||||
using FileTime.Core.Timeline;
|
||||
@@ -18,6 +19,7 @@ public class NavigationUserCommandHandlerService : UserCommandHandlerServiceBase
|
||||
private readonly ILocalContentProvider _localContentProvider;
|
||||
private readonly IUserCommandHandlerService _userCommandHandlerService;
|
||||
private readonly ITimelessContentProvider _timelessContentProvider;
|
||||
private readonly IInputInterface _inputInterface;
|
||||
private ITabViewModel? _selectedTab;
|
||||
private IContainer? _currentLocation;
|
||||
private IItemViewModel? _currentSelectedItem;
|
||||
@@ -29,13 +31,15 @@ public class NavigationUserCommandHandlerService : UserCommandHandlerServiceBase
|
||||
IServiceProvider serviceProvider,
|
||||
ILocalContentProvider localContentProvider,
|
||||
IUserCommandHandlerService userCommandHandlerService,
|
||||
ITimelessContentProvider timelessContentProvider) : base(appState)
|
||||
ITimelessContentProvider timelessContentProvider,
|
||||
IInputInterface inputInterface) : base(appState)
|
||||
{
|
||||
_appState = appState;
|
||||
_serviceProvider = serviceProvider;
|
||||
_localContentProvider = localContentProvider;
|
||||
_userCommandHandlerService = userCommandHandlerService;
|
||||
_timelessContentProvider = timelessContentProvider;
|
||||
_inputInterface = inputInterface;
|
||||
|
||||
SaveSelectedTab(t => _selectedTab = t);
|
||||
SaveCurrentSelectedItem(i => _currentSelectedItem = i);
|
||||
@@ -50,6 +54,7 @@ public class NavigationUserCommandHandlerService : UserCommandHandlerServiceBase
|
||||
new TypeUserCommandHandler<EnterRapidTravelCommand>(EnterRapidTravel),
|
||||
new TypeUserCommandHandler<ExitRapidTravelCommand>(ExitRapidTravel),
|
||||
new TypeUserCommandHandler<GoToHomeCommand>(GoToHome),
|
||||
new TypeUserCommandHandler<GoToPathCommand>(GoToPath),
|
||||
new TypeUserCommandHandler<GoToProviderCommand>(GoToProvider),
|
||||
new TypeUserCommandHandler<GoToRootCommand>(GoToRoot),
|
||||
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()
|
||||
{
|
||||
var path = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
|
||||
|
||||
@@ -19,6 +19,7 @@ public class DefaultIdentifiableCommandHandlerRegister : IStartupHandler
|
||||
AddUserCommand(EnterRapidTravelCommand.Instance);
|
||||
AddUserCommand(ExitRapidTravelCommand.Instance);
|
||||
AddUserCommand(GoToHomeCommand.Instance);
|
||||
AddUserCommand(GoToPathCommand.Instance);
|
||||
AddUserCommand(GoToProviderCommand.Instance);
|
||||
AddUserCommand(GoToRootCommand.Instance);
|
||||
AddUserCommand(GoUpCommand.Instance);
|
||||
|
||||
@@ -24,4 +24,5 @@ public interface IContentProvider : IContainer, IOnContainerEnter
|
||||
NativePath GetNativePath(FullName fullName);
|
||||
|
||||
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
|
||||
{
|
||||
Task<bool> ReadInputs(IEnumerable<IInputElement> fields);
|
||||
Task<bool> ReadInputs(params IInputElement[] fields);
|
||||
}
|
||||
@@ -13,4 +13,6 @@ public interface ITimelessContentProvider
|
||||
bool forceResolve = false,
|
||||
AbsolutePathType forceResolvePathType = AbsolutePathType.Unknown,
|
||||
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,
|
||||
int? maxLength = null,
|
||||
CancellationToken cancellationToken = default);
|
||||
|
||||
public abstract bool CanHandlePath(NativePath path);
|
||||
}
|
||||
@@ -2,7 +2,6 @@ using System.Reactive.Subjects;
|
||||
using FileTime.Core.ContentAccess;
|
||||
using FileTime.Core.Enums;
|
||||
using FileTime.Core.Models;
|
||||
using FileTime.Core.Services;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace FileTime.Core.Timeline;
|
||||
@@ -11,8 +10,7 @@ public class TimelessContentProvider : ITimelessContentProvider
|
||||
{
|
||||
private readonly Lazy<List<IContentProvider>> _contentProviders;
|
||||
|
||||
public BehaviorSubject<PointInTime> CurrentPointInTime { get; } =
|
||||
new BehaviorSubject<PointInTime>(PointInTime.Present);
|
||||
public BehaviorSubject<PointInTime> CurrentPointInTime { get; } = new(PointInTime.Present);
|
||||
|
||||
public TimelessContentProvider(IServiceProvider serviceProvider)
|
||||
{
|
||||
@@ -36,4 +34,16 @@ public class TimelessContentProvider : ITimelessContentProvider
|
||||
forceResolve, forceResolvePathType,
|
||||
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.FindByNameRegex, new[] { Key.F, Key.R }),
|
||||
new CommandBindingConfiguration(GoToHomeCommand.CommandName, new[] { Key.G, Key.H }),
|
||||
//new CommandBindingConfiguration(ConfigCommand.GoToPath, new KeyConfig(Key.L, ctrl: true)),
|
||||
//new CommandBindingConfiguration(ConfigCommand.GoToPath, new[] { Key.G, Key.P }),
|
||||
new CommandBindingConfiguration(GoToPathCommand.CommandName, new KeyConfig(Key.L, ctrl: true)),
|
||||
new CommandBindingConfiguration(GoToPathCommand.CommandName, new[] { Key.G, Key.P }),
|
||||
new CommandBindingConfiguration(GoToProviderCommand.CommandName, new[] { Key.G, Key.T }),
|
||||
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) }),
|
||||
|
||||
@@ -62,7 +62,7 @@ public class DialogService : IDialogService
|
||||
readInputsViewModel.CancelHandler?.Invoke();
|
||||
}
|
||||
|
||||
public Task<bool> ReadInputs(IEnumerable<IInputElement> fields)
|
||||
public Task<bool> ReadInputs(params IInputElement[] fields)
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<bool>();
|
||||
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,
|
||||
PointInTime pointInTime,
|
||||
bool forceResolve = false,
|
||||
|
||||
Reference in New Issue
Block a user