File scoped namespace
This commit is contained in:
@@ -1,51 +1,50 @@
|
||||
using FileTime.Core.Command;
|
||||
using FileTime.Core.Models;
|
||||
|
||||
namespace FileTime.App.Core.Services
|
||||
namespace FileTime.App.Core.Services;
|
||||
|
||||
public class ClipboardService : IClipboardService
|
||||
{
|
||||
public class ClipboardService : IClipboardService
|
||||
private List<IAbsolutePath> _content;
|
||||
public IReadOnlyList<IAbsolutePath> Content { get; private set; }
|
||||
public Type? CommandType { get; private set; }
|
||||
|
||||
public ClipboardService()
|
||||
{
|
||||
private List<IAbsolutePath> _content;
|
||||
public IReadOnlyList<IAbsolutePath> Content { get; private set; }
|
||||
public Type? CommandType { get; private set; }
|
||||
_content = new List<IAbsolutePath>();
|
||||
Content = _content.AsReadOnly();
|
||||
}
|
||||
|
||||
public ClipboardService()
|
||||
public void AddContent(IAbsolutePath absolutePath)
|
||||
{
|
||||
foreach (var content in _content)
|
||||
{
|
||||
_content = new List<IAbsolutePath>();
|
||||
Content = _content.AsReadOnly();
|
||||
if (content.Equals(absolutePath)) return;
|
||||
}
|
||||
|
||||
public void AddContent(IAbsolutePath absolutePath)
|
||||
_content.Add(absolutePath);
|
||||
}
|
||||
|
||||
public void RemoveContent(IAbsolutePath absolutePath)
|
||||
{
|
||||
for (var i = 0; i < _content.Count; i++)
|
||||
{
|
||||
foreach (var content in _content)
|
||||
if (_content[i].Equals(absolutePath))
|
||||
{
|
||||
if (content.Equals(absolutePath)) return;
|
||||
_content.RemoveAt(i--);
|
||||
}
|
||||
|
||||
_content.Add(absolutePath);
|
||||
}
|
||||
|
||||
public void RemoveContent(IAbsolutePath absolutePath)
|
||||
{
|
||||
for (var i = 0; i < _content.Count; i++)
|
||||
{
|
||||
if (_content[i].Equals(absolutePath))
|
||||
{
|
||||
_content.RemoveAt(i--);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
_content = new List<IAbsolutePath>();
|
||||
Content = _content.AsReadOnly();
|
||||
CommandType = null;
|
||||
}
|
||||
|
||||
public void SetCommand<T>() where T : ITransportationCommand
|
||||
{
|
||||
CommandType = typeof(T);
|
||||
}
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
_content = new List<IAbsolutePath>();
|
||||
Content = _content.AsReadOnly();
|
||||
CommandType = null;
|
||||
}
|
||||
|
||||
public void SetCommand<T>() where T : ITransportationCommand
|
||||
{
|
||||
CommandType = typeof(T);
|
||||
}
|
||||
}
|
||||
@@ -4,51 +4,50 @@ using FileTime.App.Core.Command;
|
||||
using FileTime.App.Core.ViewModels;
|
||||
using FileTime.Core.Models;
|
||||
|
||||
namespace FileTime.App.Core.Services.CommandHandler
|
||||
namespace FileTime.App.Core.Services.CommandHandler;
|
||||
|
||||
public abstract class CommandHandlerBase : ICommandHandler
|
||||
{
|
||||
public abstract class CommandHandlerBase : ICommandHandler
|
||||
private readonly Dictionary<Commands, Func<Task>> _commandHandlers = new();
|
||||
private readonly IAppState? _appState;
|
||||
|
||||
protected CommandHandlerBase(IAppState? appState = null)
|
||||
{
|
||||
private readonly Dictionary<Commands, Func<Task>> _commandHandlers = new();
|
||||
private readonly IAppState? _appState;
|
||||
_appState = appState;
|
||||
}
|
||||
|
||||
protected CommandHandlerBase(IAppState? appState = null)
|
||||
public bool CanHandleCommand(Commands command) => _commandHandlers.ContainsKey(command);
|
||||
|
||||
public async Task HandleCommandAsync(Commands command) => await _commandHandlers[command].Invoke();
|
||||
|
||||
protected void AddCommandHandler(Commands command, Func<Task> handler) => _commandHandlers.Add(command, handler);
|
||||
protected void AddCommandHandlers(IEnumerable<(Commands command, Func<Task> handler)> commandHandlers)
|
||||
{
|
||||
foreach (var (command, handler) in commandHandlers)
|
||||
{
|
||||
_appState = appState;
|
||||
}
|
||||
|
||||
public bool CanHandleCommand(Commands command) => _commandHandlers.ContainsKey(command);
|
||||
|
||||
public async Task HandleCommandAsync(Commands command) => await _commandHandlers[command].Invoke();
|
||||
|
||||
protected void AddCommandHandler(Commands command, Func<Task> handler) => _commandHandlers.Add(command, handler);
|
||||
protected void AddCommandHandlers(IEnumerable<(Commands command, Func<Task> handler)> commandHandlers)
|
||||
{
|
||||
foreach (var (command, handler) in commandHandlers)
|
||||
{
|
||||
AddCommandHandler(command, handler);
|
||||
}
|
||||
}
|
||||
|
||||
protected void RemoveCommandHandler(Commands command) => _commandHandlers.Remove(command);
|
||||
|
||||
protected IDisposable SaveSelectedTab(Action<ITabViewModel?> handler) => RunWithAppState(appState => appState.SelectedTab.Subscribe(handler));
|
||||
protected IDisposable SaveCurrentSelectedItem(Action<IItemViewModel?> handler)
|
||||
=> RunWithAppState(appState => appState.SelectedTab.Select(t => t == null ? Observable.Return<IItemViewModel?>(null) : t.CurrentSelectedItem).Switch().Subscribe(handler));
|
||||
|
||||
protected IDisposable SaveCurrentLocation(Action<IContainer?> handler)
|
||||
=> RunWithAppState(appState => appState.SelectedTab.Select(t => t == null ? Observable.Return<IContainer?>(null) : t.CurrentLocation).Switch().Subscribe(handler));
|
||||
|
||||
protected IDisposable SaveCurrentItems(Action<IEnumerable<IItemViewModel>> handler)
|
||||
=> RunWithAppState(appState => appState.SelectedTab.Select(t => t?.CurrentItemsCollectionObservable ?? Observable.Return((IEnumerable<IItemViewModel>?)Enumerable.Empty<IItemViewModel>())).Switch().Subscribe(i => handler(i ?? Enumerable.Empty<IItemViewModel>())));
|
||||
|
||||
protected IDisposable SaveMarkedItems(Action<IChangeSet<IAbsolutePath>> handler)
|
||||
=> RunWithAppState(appstate => appstate.SelectedTab.Select(t => t == null ? Observable.Empty<IChangeSet<IAbsolutePath>>() : t.MarkedItems).Switch().Subscribe(handler));
|
||||
|
||||
private IDisposable RunWithAppState(Func<IAppState, IDisposable> act)
|
||||
{
|
||||
if (_appState == null) throw new NullReferenceException($"AppState is nit initialized in {nameof(CommandHandlerBase)}.");
|
||||
|
||||
return act(_appState);
|
||||
AddCommandHandler(command, handler);
|
||||
}
|
||||
}
|
||||
|
||||
protected void RemoveCommandHandler(Commands command) => _commandHandlers.Remove(command);
|
||||
|
||||
protected IDisposable SaveSelectedTab(Action<ITabViewModel?> handler) => RunWithAppState(appState => appState.SelectedTab.Subscribe(handler));
|
||||
protected IDisposable SaveCurrentSelectedItem(Action<IItemViewModel?> handler)
|
||||
=> RunWithAppState(appState => appState.SelectedTab.Select(t => t == null ? Observable.Return<IItemViewModel?>(null) : t.CurrentSelectedItem).Switch().Subscribe(handler));
|
||||
|
||||
protected IDisposable SaveCurrentLocation(Action<IContainer?> handler)
|
||||
=> RunWithAppState(appState => appState.SelectedTab.Select(t => t == null ? Observable.Return<IContainer?>(null) : t.CurrentLocation).Switch().Subscribe(handler));
|
||||
|
||||
protected IDisposable SaveCurrentItems(Action<IEnumerable<IItemViewModel>> handler)
|
||||
=> RunWithAppState(appState => appState.SelectedTab.Select(t => t?.CurrentItemsCollectionObservable ?? Observable.Return((IEnumerable<IItemViewModel>?)Enumerable.Empty<IItemViewModel>())).Switch().Subscribe(i => handler(i ?? Enumerable.Empty<IItemViewModel>())));
|
||||
|
||||
protected IDisposable SaveMarkedItems(Action<IChangeSet<IAbsolutePath>> handler)
|
||||
=> RunWithAppState(appstate => appstate.SelectedTab.Select(t => t == null ? Observable.Empty<IChangeSet<IAbsolutePath>>() : t.MarkedItems).Switch().Subscribe(handler));
|
||||
|
||||
private IDisposable RunWithAppState(Func<IAppState, IDisposable> act)
|
||||
{
|
||||
if (_appState == null) throw new NullReferenceException($"AppState is nit initialized in {nameof(CommandHandlerBase)}.");
|
||||
|
||||
return act(_appState);
|
||||
}
|
||||
}
|
||||
@@ -6,91 +6,90 @@ using FileTime.Core.Command;
|
||||
using FileTime.Core.Command.Copy;
|
||||
using FileTime.Core.Models;
|
||||
|
||||
namespace FileTime.App.Core.Services.CommandHandler
|
||||
namespace FileTime.App.Core.Services.CommandHandler;
|
||||
|
||||
public class ItemManipulationCommandHandler : CommandHandlerBase
|
||||
{
|
||||
public class ItemManipulationCommandHandler : CommandHandlerBase
|
||||
private ITabViewModel? _selectedTab;
|
||||
private IItemViewModel? _currentSelectedItem;
|
||||
private readonly ICommandHandlerService _commandHandlerService;
|
||||
private readonly IClipboardService _clipboardService;
|
||||
private BindedCollection<IAbsolutePath>? _markedItems;
|
||||
|
||||
public ItemManipulationCommandHandler(
|
||||
IAppState appState,
|
||||
ICommandHandlerService commandHandlerService,
|
||||
IClipboardService clipboardService) : base(appState)
|
||||
{
|
||||
private ITabViewModel? _selectedTab;
|
||||
private IItemViewModel? _currentSelectedItem;
|
||||
private readonly ICommandHandlerService _commandHandlerService;
|
||||
private readonly IClipboardService _clipboardService;
|
||||
private BindedCollection<IAbsolutePath>? _markedItems;
|
||||
_commandHandlerService = commandHandlerService;
|
||||
_clipboardService = clipboardService;
|
||||
|
||||
public ItemManipulationCommandHandler(
|
||||
IAppState appState,
|
||||
ICommandHandlerService commandHandlerService,
|
||||
IClipboardService clipboardService) : base(appState)
|
||||
SaveSelectedTab(t =>
|
||||
{
|
||||
_commandHandlerService = commandHandlerService;
|
||||
_clipboardService = clipboardService;
|
||||
_selectedTab = t;
|
||||
_markedItems?.Dispose();
|
||||
_markedItems = t == null ? null : new BindedCollection<IAbsolutePath>(t.MarkedItems);
|
||||
});
|
||||
SaveCurrentSelectedItem(i => _currentSelectedItem = i);
|
||||
|
||||
SaveSelectedTab(t =>
|
||||
{
|
||||
_selectedTab = t;
|
||||
_markedItems?.Dispose();
|
||||
_markedItems = t == null ? null : new BindedCollection<IAbsolutePath>(t.MarkedItems);
|
||||
});
|
||||
SaveCurrentSelectedItem(i => _currentSelectedItem = i);
|
||||
|
||||
AddCommandHandlers(new (Commands, Func<Task>)[]
|
||||
{
|
||||
(Commands.Copy, Copy),
|
||||
(Commands.Mark, MarkItem),
|
||||
(Commands.PasteMerge, PasteMerge),
|
||||
(Commands.PasteOverwrite, PasteOverwrite),
|
||||
(Commands.PasteSkip, PasteSkip),
|
||||
});
|
||||
}
|
||||
|
||||
private async Task MarkItem()
|
||||
AddCommandHandlers(new (Commands, Func<Task>)[]
|
||||
{
|
||||
if (_selectedTab == null || _currentSelectedItem?.BaseItem?.FullName == null) return;
|
||||
(Commands.Copy, Copy),
|
||||
(Commands.Mark, MarkItem),
|
||||
(Commands.PasteMerge, PasteMerge),
|
||||
(Commands.PasteOverwrite, PasteOverwrite),
|
||||
(Commands.PasteSkip, PasteSkip),
|
||||
});
|
||||
}
|
||||
|
||||
_selectedTab.ToggleMarkedItem(new AbsolutePath(_currentSelectedItem.BaseItem));
|
||||
await _commandHandlerService.HandleCommandAsync(Commands.MoveCursorDown);
|
||||
}
|
||||
private async Task MarkItem()
|
||||
{
|
||||
if (_selectedTab == null || _currentSelectedItem?.BaseItem?.FullName == null) return;
|
||||
|
||||
private Task Copy()
|
||||
_selectedTab.ToggleMarkedItem(new AbsolutePath(_currentSelectedItem.BaseItem));
|
||||
await _commandHandlerService.HandleCommandAsync(Commands.MoveCursorDown);
|
||||
}
|
||||
|
||||
private Task Copy()
|
||||
{
|
||||
_clipboardService.Clear();
|
||||
_clipboardService.SetCommand<CopyCommand>();
|
||||
|
||||
if ((_markedItems?.Collection.Count ?? 0) > 0)
|
||||
{
|
||||
_clipboardService.Clear();
|
||||
_clipboardService.SetCommand<CopyCommand>();
|
||||
|
||||
if ((_markedItems?.Collection.Count ?? 0) > 0)
|
||||
foreach (var item in _markedItems!.Collection)
|
||||
{
|
||||
foreach (var item in _markedItems!.Collection)
|
||||
{
|
||||
_clipboardService.AddContent(item);
|
||||
}
|
||||
|
||||
_selectedTab?.ClearMarkedItems();
|
||||
}
|
||||
else if (_currentSelectedItem?.BaseItem != null)
|
||||
{
|
||||
_clipboardService.AddContent(new AbsolutePath(_currentSelectedItem.BaseItem));
|
||||
_clipboardService.AddContent(item);
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
_selectedTab?.ClearMarkedItems();
|
||||
}
|
||||
else if (_currentSelectedItem?.BaseItem != null)
|
||||
{
|
||||
_clipboardService.AddContent(new AbsolutePath(_currentSelectedItem.BaseItem));
|
||||
}
|
||||
|
||||
private async Task PasteMerge()
|
||||
{
|
||||
await Paste(TransportMode.Merge);
|
||||
}
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private async Task PasteOverwrite()
|
||||
{
|
||||
await Paste(TransportMode.Overwrite);
|
||||
}
|
||||
private async Task PasteMerge()
|
||||
{
|
||||
await Paste(TransportMode.Merge);
|
||||
}
|
||||
|
||||
private async Task PasteSkip()
|
||||
{
|
||||
await Paste(TransportMode.Skip);
|
||||
}
|
||||
private async Task PasteOverwrite()
|
||||
{
|
||||
await Paste(TransportMode.Overwrite);
|
||||
}
|
||||
|
||||
private Task Paste(TransportMode skip)
|
||||
{
|
||||
if (_clipboardService.CommandType is null) return Task.CompletedTask;
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
private async Task PasteSkip()
|
||||
{
|
||||
await Paste(TransportMode.Skip);
|
||||
}
|
||||
|
||||
private Task Paste(TransportMode skip)
|
||||
{
|
||||
if (_clipboardService.CommandType is null) return Task.CompletedTask;
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
@@ -4,65 +4,64 @@ using FileTime.App.Core.Extensions;
|
||||
using FileTime.App.Core.ViewModels;
|
||||
using FileTime.Core.Models;
|
||||
|
||||
namespace FileTime.App.Core.Services.CommandHandler
|
||||
namespace FileTime.App.Core.Services.CommandHandler;
|
||||
|
||||
public class NavigationCommandHandler : CommandHandlerBase
|
||||
{
|
||||
public class NavigationCommandHandler : CommandHandlerBase
|
||||
private ITabViewModel? _selectedTab;
|
||||
private IContainer? _currentLocation;
|
||||
private IItemViewModel? _currentSelectedItem;
|
||||
private IEnumerable<IItemViewModel> _currentItems = Enumerable.Empty<IItemViewModel>();
|
||||
|
||||
public NavigationCommandHandler(IAppState appState) : base(appState)
|
||||
{
|
||||
private ITabViewModel? _selectedTab;
|
||||
private IContainer? _currentLocation;
|
||||
private IItemViewModel? _currentSelectedItem;
|
||||
private IEnumerable<IItemViewModel> _currentItems = Enumerable.Empty<IItemViewModel>();
|
||||
SaveSelectedTab(t => _selectedTab = t);
|
||||
SaveCurrentSelectedItem(i => _currentSelectedItem = i);
|
||||
SaveCurrentLocation(l => _currentLocation = l);
|
||||
SaveCurrentItems(i => _currentItems = i);
|
||||
|
||||
public NavigationCommandHandler(IAppState appState) : base(appState)
|
||||
AddCommandHandlers(new (Commands, Func<Task>)[]
|
||||
{
|
||||
SaveSelectedTab(t => _selectedTab = t);
|
||||
SaveCurrentSelectedItem(i => _currentSelectedItem = i);
|
||||
SaveCurrentLocation(l => _currentLocation = l);
|
||||
SaveCurrentItems(i => _currentItems = i);
|
||||
(Commands.GoUp, GoUp),
|
||||
(Commands.MoveCursorDown, MoveCursorDown),
|
||||
(Commands.MoveCursorUp, MoveCursorUp),
|
||||
(Commands.Open, OpenContainer),
|
||||
});
|
||||
}
|
||||
|
||||
AddCommandHandlers(new (Commands, Func<Task>)[]
|
||||
{
|
||||
(Commands.GoUp, GoUp),
|
||||
(Commands.MoveCursorDown, MoveCursorDown),
|
||||
(Commands.MoveCursorUp, MoveCursorUp),
|
||||
(Commands.Open, OpenContainer),
|
||||
});
|
||||
}
|
||||
private Task OpenContainer()
|
||||
{
|
||||
if (_currentSelectedItem is not IContainerViewModel containerViewModel || containerViewModel.Container is null) return Task.CompletedTask;
|
||||
|
||||
private Task OpenContainer()
|
||||
{
|
||||
if (_currentSelectedItem is not IContainerViewModel containerViewModel || containerViewModel.Container is null) return Task.CompletedTask;
|
||||
_selectedTab?.Tab?.SetCurrentLocation(containerViewModel.Container);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
_selectedTab?.Tab?.SetCurrentLocation(containerViewModel.Container);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
private async Task GoUp()
|
||||
{
|
||||
if (_currentLocation?.Parent is not IAbsolutePath parentPath || await parentPath.ResolveAsyncSafe() is not IContainer newContainer) return;
|
||||
_selectedTab?.Tab?.SetCurrentLocation(newContainer);
|
||||
}
|
||||
|
||||
private async Task GoUp()
|
||||
{
|
||||
if (_currentLocation?.Parent is not IAbsolutePath parentPath || await parentPath.ResolveAsyncSafe() is not IContainer newContainer) return;
|
||||
_selectedTab?.Tab?.SetCurrentLocation(newContainer);
|
||||
}
|
||||
private Task MoveCursorDown()
|
||||
{
|
||||
SelectNewSelectedItem(i => i.SkipWhile(i => !i.EqualsTo(_currentSelectedItem)).Skip(1).FirstOrDefault());
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private Task MoveCursorDown()
|
||||
{
|
||||
SelectNewSelectedItem(i => i.SkipWhile(i => !i.EqualsTo(_currentSelectedItem)).Skip(1).FirstOrDefault());
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
private Task MoveCursorUp()
|
||||
{
|
||||
SelectNewSelectedItem(i => i.TakeWhile(i => !i.EqualsTo(_currentSelectedItem)).LastOrDefault());
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private Task MoveCursorUp()
|
||||
{
|
||||
SelectNewSelectedItem(i => i.TakeWhile(i => !i.EqualsTo(_currentSelectedItem)).LastOrDefault());
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
private void SelectNewSelectedItem(Func<IEnumerable<IItemViewModel>, IItemViewModel?> getNewSelected)
|
||||
{
|
||||
if (_selectedTab is null || _currentLocation is null) return;
|
||||
|
||||
private void SelectNewSelectedItem(Func<IEnumerable<IItemViewModel>, IItemViewModel?> getNewSelected)
|
||||
{
|
||||
if (_selectedTab is null || _currentLocation is null) return;
|
||||
var newSelectedItem = getNewSelected(_currentItems);
|
||||
if (newSelectedItem == null) return;
|
||||
|
||||
var newSelectedItem = getNewSelected(_currentItems);
|
||||
if (newSelectedItem == null) return;
|
||||
|
||||
_selectedTab.Tab?.SetSelectedItem(newSelectedItem.ToAbsolutePath());
|
||||
}
|
||||
_selectedTab.Tab?.SetSelectedItem(newSelectedItem.ToAbsolutePath());
|
||||
}
|
||||
}
|
||||
@@ -1,80 +1,79 @@
|
||||
using FileTime.App.Core.Command;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace FileTime.App.Core.Services
|
||||
namespace FileTime.App.Core.Services;
|
||||
|
||||
public class CommandHandlerService : ICommandHandlerService
|
||||
{
|
||||
public class CommandHandlerService : ICommandHandlerService
|
||||
private readonly Lazy<IEnumerable<ICommandHandler>> _commandHandlers;
|
||||
|
||||
public CommandHandlerService(IServiceProvider serviceProvider)
|
||||
{
|
||||
private readonly Lazy<IEnumerable<ICommandHandler>> _commandHandlers;
|
||||
_commandHandlers = new Lazy<IEnumerable<ICommandHandler>>(() => serviceProvider.GetServices<ICommandHandler>());
|
||||
|
||||
public CommandHandlerService(IServiceProvider serviceProvider)
|
||||
//(Commands.AutoRefresh, ToggleAutoRefresh),
|
||||
//(Commands.ChangeTimelineMode, ChangeTimelineMode),
|
||||
//(Commands.CloseTab, CloseTab),
|
||||
//(Commands.Compress, Compress),
|
||||
//(Commands.Copy, Copy),
|
||||
//(Commands.CopyHash, CopyHash),
|
||||
//(Commands.CopyPath, CopyPath),
|
||||
//(Commands.CreateContainer, CreateContainer),
|
||||
//(Commands.CreateElement, CreateElement),
|
||||
//(Commands.Cut, Cut),
|
||||
//(Commands.Edit, Edit),
|
||||
//(Commands.EnterRapidTravel, EnterRapidTravelMode),
|
||||
//(Commands.FindByName, FindByName),
|
||||
//(Commands.FindByNameRegex, FindByNameRegex),
|
||||
//(Commands.GoToHome, GotToHome),
|
||||
//(Commands.GoToPath, GoToContainer),
|
||||
//(Commands.GoToProvider, GotToProvider),
|
||||
//(Commands.GoToRoot, GotToRoot),
|
||||
//(Commands.HardDelete, HardDelete),
|
||||
//(Commands.Mark, MarkCurrentItem),
|
||||
//(Commands.MoveCursorDownPage, MoveCursorDownPage),
|
||||
//(Commands.MoveCursorUpPage, MoveCursorUpPage),
|
||||
//(Commands.MoveToFirst, MoveToFirst),
|
||||
//(Commands.MoveToLast, MoveToLast),
|
||||
//(Commands.NextTimelineBlock, SelectNextTimelineBlock),
|
||||
//(Commands.NextTimelineCommand, SelectNextTimelineCommand),
|
||||
//(Commands.OpenInFileBrowser, OpenInDefaultFileExplorer),
|
||||
//(Commands.OpenOrRun, OpenOrRun),
|
||||
//(Commands.PasteMerge, PasteMerge),
|
||||
//(Commands.PasteOverwrite, PasteOverwrite),
|
||||
//(Commands.PasteSkip, PasteSkip),
|
||||
//(Commands.PinFavorite, PinFavorite),
|
||||
//(Commands.PreviousTimelineBlock, SelectPreviousTimelineBlock),
|
||||
//(Commands.PreviousTimelineCommand, SelectPreviousTimelineCommand),
|
||||
//(Commands.Refresh, RefreshCurrentLocation),
|
||||
//(Commands.Rename, Rename),
|
||||
//(Commands.RunCommand, RunCommandInContainer),
|
||||
//(Commands.ScanContainerSize, ScanContainerSize),
|
||||
//(Commands.ShowAllShotcut, ShowAllShortcut),
|
||||
//(Commands.SoftDelete, SoftDelete),
|
||||
//(Commands.SwitchToLastTab, async() => await SwitchToTab(-1)),
|
||||
//(Commands.SwitchToTab1, async() => await SwitchToTab(1)),
|
||||
//(Commands.SwitchToTab2, async() => await SwitchToTab(2)),
|
||||
//(Commands.SwitchToTab3, async() => await SwitchToTab(3)),
|
||||
//(Commands.SwitchToTab4, async() => await SwitchToTab(4)),
|
||||
//(Commands.SwitchToTab5, async() => await SwitchToTab(5)),
|
||||
//(Commands.SwitchToTab6, async() => await SwitchToTab(6)),
|
||||
//(Commands.SwitchToTab7, async() => await SwitchToTab(7)),
|
||||
//(Commands.SwitchToTab8, async() => await SwitchToTab(8)),
|
||||
//(Commands.TimelinePause, PauseTimeline),
|
||||
//(Commands.TimelineRefresh, RefreshTimeline),
|
||||
//(Commands.TimelineStart, ContinueTimeline),
|
||||
//(Commands.ToggleAdvancedIcons, ToggleAdvancedIcons),
|
||||
//(Commands.ToggleHidden, ToggleHidden),
|
||||
}
|
||||
|
||||
public async Task HandleCommandAsync(Commands command)
|
||||
{
|
||||
var handler = _commandHandlers.Value.FirstOrDefault(h => h.CanHandleCommand(command));
|
||||
|
||||
if (handler != null)
|
||||
{
|
||||
_commandHandlers = new Lazy<IEnumerable<ICommandHandler>>(() => serviceProvider.GetServices<ICommandHandler>());
|
||||
|
||||
//(Commands.AutoRefresh, ToggleAutoRefresh),
|
||||
//(Commands.ChangeTimelineMode, ChangeTimelineMode),
|
||||
//(Commands.CloseTab, CloseTab),
|
||||
//(Commands.Compress, Compress),
|
||||
//(Commands.Copy, Copy),
|
||||
//(Commands.CopyHash, CopyHash),
|
||||
//(Commands.CopyPath, CopyPath),
|
||||
//(Commands.CreateContainer, CreateContainer),
|
||||
//(Commands.CreateElement, CreateElement),
|
||||
//(Commands.Cut, Cut),
|
||||
//(Commands.Edit, Edit),
|
||||
//(Commands.EnterRapidTravel, EnterRapidTravelMode),
|
||||
//(Commands.FindByName, FindByName),
|
||||
//(Commands.FindByNameRegex, FindByNameRegex),
|
||||
//(Commands.GoToHome, GotToHome),
|
||||
//(Commands.GoToPath, GoToContainer),
|
||||
//(Commands.GoToProvider, GotToProvider),
|
||||
//(Commands.GoToRoot, GotToRoot),
|
||||
//(Commands.HardDelete, HardDelete),
|
||||
//(Commands.Mark, MarkCurrentItem),
|
||||
//(Commands.MoveCursorDownPage, MoveCursorDownPage),
|
||||
//(Commands.MoveCursorUpPage, MoveCursorUpPage),
|
||||
//(Commands.MoveToFirst, MoveToFirst),
|
||||
//(Commands.MoveToLast, MoveToLast),
|
||||
//(Commands.NextTimelineBlock, SelectNextTimelineBlock),
|
||||
//(Commands.NextTimelineCommand, SelectNextTimelineCommand),
|
||||
//(Commands.OpenInFileBrowser, OpenInDefaultFileExplorer),
|
||||
//(Commands.OpenOrRun, OpenOrRun),
|
||||
//(Commands.PasteMerge, PasteMerge),
|
||||
//(Commands.PasteOverwrite, PasteOverwrite),
|
||||
//(Commands.PasteSkip, PasteSkip),
|
||||
//(Commands.PinFavorite, PinFavorite),
|
||||
//(Commands.PreviousTimelineBlock, SelectPreviousTimelineBlock),
|
||||
//(Commands.PreviousTimelineCommand, SelectPreviousTimelineCommand),
|
||||
//(Commands.Refresh, RefreshCurrentLocation),
|
||||
//(Commands.Rename, Rename),
|
||||
//(Commands.RunCommand, RunCommandInContainer),
|
||||
//(Commands.ScanContainerSize, ScanContainerSize),
|
||||
//(Commands.ShowAllShotcut, ShowAllShortcut),
|
||||
//(Commands.SoftDelete, SoftDelete),
|
||||
//(Commands.SwitchToLastTab, async() => await SwitchToTab(-1)),
|
||||
//(Commands.SwitchToTab1, async() => await SwitchToTab(1)),
|
||||
//(Commands.SwitchToTab2, async() => await SwitchToTab(2)),
|
||||
//(Commands.SwitchToTab3, async() => await SwitchToTab(3)),
|
||||
//(Commands.SwitchToTab4, async() => await SwitchToTab(4)),
|
||||
//(Commands.SwitchToTab5, async() => await SwitchToTab(5)),
|
||||
//(Commands.SwitchToTab6, async() => await SwitchToTab(6)),
|
||||
//(Commands.SwitchToTab7, async() => await SwitchToTab(7)),
|
||||
//(Commands.SwitchToTab8, async() => await SwitchToTab(8)),
|
||||
//(Commands.TimelinePause, PauseTimeline),
|
||||
//(Commands.TimelineRefresh, RefreshTimeline),
|
||||
//(Commands.TimelineStart, ContinueTimeline),
|
||||
//(Commands.ToggleAdvancedIcons, ToggleAdvancedIcons),
|
||||
//(Commands.ToggleHidden, ToggleHidden),
|
||||
}
|
||||
|
||||
public async Task HandleCommandAsync(Commands command)
|
||||
{
|
||||
var handler = _commandHandlers.Value.FirstOrDefault(h => h.CanHandleCommand(command));
|
||||
|
||||
if (handler != null)
|
||||
{
|
||||
await handler.HandleCommandAsync(command);
|
||||
}
|
||||
await handler.HandleCommandAsync(command);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,56 +1,55 @@
|
||||
using FileTime.App.Core.Models;
|
||||
|
||||
namespace FileTime.App.Core.Services
|
||||
namespace FileTime.App.Core.Services;
|
||||
|
||||
public class ItemNameConverterService : IItemNameConverterService
|
||||
{
|
||||
public class ItemNameConverterService : IItemNameConverterService
|
||||
public List<ItemNamePart> GetDisplayName(string name, string? searchText)
|
||||
{
|
||||
public List<ItemNamePart> GetDisplayName(string name, string? searchText)
|
||||
var nameParts = new List<ItemNamePart>();
|
||||
searchText = searchText?.ToLower();
|
||||
|
||||
if (!string.IsNullOrEmpty(searchText))
|
||||
{
|
||||
var nameParts = new List<ItemNamePart>();
|
||||
searchText = searchText?.ToLower();
|
||||
var nameLeft = name;
|
||||
|
||||
if (!string.IsNullOrEmpty(searchText))
|
||||
while (nameLeft.ToLower().IndexOf(searchText, StringComparison.Ordinal) is int rapidTextStart && rapidTextStart != -1)
|
||||
{
|
||||
var nameLeft = name;
|
||||
var before = rapidTextStart > 0 ? nameLeft.Substring(0, rapidTextStart) : null;
|
||||
var rapidTravel = nameLeft.Substring(rapidTextStart, searchText.Length);
|
||||
|
||||
while (nameLeft.ToLower().IndexOf(searchText, StringComparison.Ordinal) is int rapidTextStart && rapidTextStart != -1)
|
||||
nameLeft = nameLeft.Substring(rapidTextStart + searchText.Length);
|
||||
|
||||
if (before != null)
|
||||
{
|
||||
var before = rapidTextStart > 0 ? nameLeft.Substring(0, rapidTextStart) : null;
|
||||
var rapidTravel = nameLeft.Substring(rapidTextStart, searchText.Length);
|
||||
|
||||
nameLeft = nameLeft.Substring(rapidTextStart + searchText.Length);
|
||||
|
||||
if (before != null)
|
||||
{
|
||||
nameParts.Add(new ItemNamePart(before));
|
||||
}
|
||||
|
||||
nameParts.Add(new ItemNamePart(rapidTravel, true));
|
||||
nameParts.Add(new ItemNamePart(before));
|
||||
}
|
||||
|
||||
if (nameLeft.Length > 0)
|
||||
{
|
||||
nameParts.Add(new ItemNamePart(nameLeft));
|
||||
}
|
||||
nameParts.Add(new ItemNamePart(rapidTravel, true));
|
||||
}
|
||||
else
|
||||
|
||||
if (nameLeft.Length > 0)
|
||||
{
|
||||
nameParts.Add(new ItemNamePart(name));
|
||||
nameParts.Add(new ItemNamePart(nameLeft));
|
||||
}
|
||||
return nameParts;
|
||||
}
|
||||
|
||||
public string GetFileName(string fullName)
|
||||
else
|
||||
{
|
||||
var parts = fullName.Split('.');
|
||||
var fileName = string.Join('.', parts[..^1]);
|
||||
return string.IsNullOrEmpty(fileName) ? fullName : fileName;
|
||||
}
|
||||
|
||||
public string GetFileExtension(string fullName)
|
||||
{
|
||||
var parts = fullName.Split('.');
|
||||
return parts.Length == 1 || (parts.Length == 2 && string.IsNullOrEmpty(parts[0])) ? "" : parts[^1];
|
||||
nameParts.Add(new ItemNamePart(name));
|
||||
}
|
||||
return nameParts;
|
||||
}
|
||||
}
|
||||
|
||||
public string GetFileName(string fullName)
|
||||
{
|
||||
var parts = fullName.Split('.');
|
||||
var fileName = string.Join('.', parts[..^1]);
|
||||
return string.IsNullOrEmpty(fileName) ? fullName : fileName;
|
||||
}
|
||||
|
||||
public string GetFileExtension(string fullName)
|
||||
{
|
||||
var parts = fullName.Split('.');
|
||||
return parts.Length == 1 || (parts.Length == 2 && string.IsNullOrEmpty(parts[0])) ? "" : parts[^1];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user