Search WIP
This commit is contained in:
@@ -26,6 +26,7 @@
|
||||
<ProjectReference Include="..\FileTime.App.Core.Abstraction\FileTime.App.Core.Abstraction.csproj" />
|
||||
<ProjectReference Include="..\..\Core\FileTime.Core.Command\FileTime.Core.Command.csproj" />
|
||||
<ProjectReference Include="..\FileTime.App.FrequencyNavigation.Abstractions\FileTime.App.FrequencyNavigation.Abstractions.csproj" />
|
||||
<ProjectReference Include="..\FileTime.App.Search\FileTime.App.Search.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using System.Diagnostics;
|
||||
using FileTime.App.Core.UserCommand;
|
||||
using FileTime.App.Core.ViewModels;
|
||||
using FileTime.App.Search;
|
||||
using FileTime.Core.Interactions;
|
||||
using FileTime.Core.Models;
|
||||
|
||||
namespace FileTime.App.Core.Services.UserCommandHandler;
|
||||
@@ -8,12 +10,23 @@ namespace FileTime.App.Core.Services.UserCommandHandler;
|
||||
public class ToolUserCommandHandlerService : UserCommandHandlerServiceBase
|
||||
{
|
||||
private readonly ISystemClipboardService _systemClipboardService;
|
||||
private readonly IUserCommunicationService _userCommunicationService;
|
||||
private readonly ISearchManager _searchManager;
|
||||
private readonly IItemNameConverterService _itemNameConverterService;
|
||||
private IContainer? _currentLocation;
|
||||
private IItemViewModel? _currentSelectedItem;
|
||||
|
||||
public ToolUserCommandHandlerService(IAppState appState, ISystemClipboardService systemClipboardService) : base(appState)
|
||||
public ToolUserCommandHandlerService(
|
||||
IAppState appState,
|
||||
ISystemClipboardService systemClipboardService,
|
||||
IUserCommunicationService userCommunicationService,
|
||||
ISearchManager searchManager,
|
||||
IItemNameConverterService itemNameConverterService) : base(appState)
|
||||
{
|
||||
_systemClipboardService = systemClipboardService;
|
||||
_userCommunicationService = userCommunicationService;
|
||||
_searchManager = searchManager;
|
||||
_itemNameConverterService = itemNameConverterService;
|
||||
SaveCurrentLocation(l => _currentLocation = l);
|
||||
SaveCurrentSelectedItem(i => _currentSelectedItem = i);
|
||||
|
||||
@@ -21,9 +34,45 @@ public class ToolUserCommandHandlerService : UserCommandHandlerServiceBase
|
||||
{
|
||||
new TypeUserCommandHandler<OpenInDefaultFileExplorerCommand>(OpenInDefaultFileExplorer),
|
||||
new TypeUserCommandHandler<CopyNativePathCommand>(CopyNativePath),
|
||||
new TypeUserCommandHandler<SearchCommand>(Search),
|
||||
});
|
||||
}
|
||||
|
||||
private async Task Search(SearchCommand searchCommand)
|
||||
{
|
||||
if(_currentLocation is null) return;
|
||||
|
||||
var searchQuery = searchCommand.SearchText;
|
||||
if (string.IsNullOrEmpty(searchQuery))
|
||||
{
|
||||
var title = searchCommand.SearchType switch
|
||||
{
|
||||
SearchType.NameContains => "Search by Name",
|
||||
SearchType.NameRegex => "Search by Name (Regex)",
|
||||
_ => throw new ArgumentOutOfRangeException()
|
||||
};
|
||||
var containerNameInput = new TextInputElement(title);
|
||||
await _userCommunicationService.ReadInputs(containerNameInput);
|
||||
|
||||
if (containerNameInput.Value is not null)
|
||||
{
|
||||
searchQuery = containerNameInput.Value;
|
||||
}
|
||||
}
|
||||
|
||||
//TODO proper error message
|
||||
if(string.IsNullOrWhiteSpace(searchQuery)) return;
|
||||
|
||||
var searchMatcher = searchCommand.SearchType switch
|
||||
{
|
||||
SearchType.NameContains => new NameContainsMatcher(_itemNameConverterService, searchQuery),
|
||||
//SearchType.NameRegex => new NameRegexMatcher(searchQuery),
|
||||
_ => throw new ArgumentOutOfRangeException()
|
||||
};
|
||||
|
||||
await _searchManager.StartSearchAsync(searchMatcher, _currentLocation);
|
||||
}
|
||||
|
||||
private async Task CopyNativePath()
|
||||
{
|
||||
if (_currentSelectedItem?.BaseItem?.NativePath is null) return;
|
||||
|
||||
@@ -2,7 +2,7 @@ using FileTime.App.Core.UserCommand;
|
||||
|
||||
namespace FileTime.App.Core.Services.UserCommandHandler;
|
||||
|
||||
public class TypeUserCommandHandler<T> : IUserCommandHandler
|
||||
public class TypeUserCommandHandler<T> : IUserCommandHandler where T : IUserCommand
|
||||
{
|
||||
private readonly Func<T, Task> _handler;
|
||||
|
||||
|
||||
@@ -41,6 +41,7 @@ public class DefaultIdentifiableCommandHandlerRegister : IStartupHandler
|
||||
AddUserCommand(PauseCommandSchedulerCommand.Instance);
|
||||
AddUserCommand(RefreshCommand.Instance);
|
||||
AddUserCommand(StartCommandSchedulerCommand.Instance);
|
||||
AddUserCommand(IdentifiableSearchCommand.SearchByNameContains);
|
||||
AddUserCommand(SwitchToTabCommand.SwitchToLastTab);
|
||||
AddUserCommand(SwitchToTabCommand.SwitchToTab1);
|
||||
AddUserCommand(SwitchToTabCommand.SwitchToTab2);
|
||||
|
||||
Reference in New Issue
Block a user