WIP: RapidTravel, ModalService
This commit is contained in:
@@ -11,6 +11,11 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="MvvmGen" Version="1.1.5" />
|
||||||
|
<PackageReference Include="PropertyChanged.SourceGenerator" Version="1.0.3">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
<PackageReference Include="System.Reactive" Version="5.0.0" />
|
<PackageReference Include="System.Reactive" Version="5.0.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,17 @@
|
|||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
|
using System.ComponentModel;
|
||||||
using DynamicData;
|
using DynamicData;
|
||||||
|
using PropertyChanged.SourceGenerator;
|
||||||
|
|
||||||
namespace FileTime.App.Core.Models;
|
namespace FileTime.App.Core.Models;
|
||||||
|
|
||||||
public class BindedCollection<T> : IDisposable
|
public partial class BindedCollection<T> : IDisposable, INotifyPropertyChanged
|
||||||
{
|
{
|
||||||
private readonly IDisposable _disposable;
|
private readonly IDisposable _disposable;
|
||||||
public ReadOnlyObservableCollection<T> Collection { get; }
|
private IDisposable? _innerDisposable;
|
||||||
|
|
||||||
|
[Notify] private ReadOnlyObservableCollection<T>? _collection;
|
||||||
|
|
||||||
public BindedCollection(IObservable<IChangeSet<T>> dynamicList)
|
public BindedCollection(IObservable<IChangeSet<T>> dynamicList)
|
||||||
{
|
{
|
||||||
_disposable = dynamicList
|
_disposable = dynamicList
|
||||||
@@ -14,12 +19,34 @@ public class BindedCollection<T> : IDisposable
|
|||||||
.DisposeMany()
|
.DisposeMany()
|
||||||
.Subscribe();
|
.Subscribe();
|
||||||
|
|
||||||
|
_collection = collection;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BindedCollection(IObservable<IObservable<IChangeSet<T>>?> dynamicListSource)
|
||||||
|
{
|
||||||
|
_disposable = dynamicListSource.Subscribe(dynamicList =>
|
||||||
|
{
|
||||||
|
_innerDisposable?.Dispose();
|
||||||
|
if (dynamicList is not null)
|
||||||
|
{
|
||||||
|
_innerDisposable = dynamicList
|
||||||
|
.Bind(out var collection)
|
||||||
|
.DisposeMany()
|
||||||
|
.Subscribe();
|
||||||
|
|
||||||
Collection = collection;
|
Collection = collection;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Collection = null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
_disposable.Dispose();
|
_disposable.Dispose();
|
||||||
|
_innerDisposable?.Dispose();
|
||||||
GC.SuppressFinalize(this);
|
GC.SuppressFinalize(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
using DynamicData;
|
||||||
|
using FileTime.App.Core.ViewModels;
|
||||||
|
|
||||||
|
namespace FileTime.App.Core.Services;
|
||||||
|
|
||||||
|
public interface IModalService
|
||||||
|
{
|
||||||
|
IObservable<IChangeSet<IModalViewModelBase>> OpenModals { get; }
|
||||||
|
|
||||||
|
void OpenModal(IModalViewModelBase modalToOpen);
|
||||||
|
void CloseModal(IModalViewModelBase modalToClose);
|
||||||
|
}
|
||||||
@@ -8,9 +8,11 @@ public interface IAppState
|
|||||||
ObservableCollection<ITabViewModel> Tabs { get; }
|
ObservableCollection<ITabViewModel> Tabs { get; }
|
||||||
IObservable<ITabViewModel?> SelectedTab { get; }
|
IObservable<ITabViewModel?> SelectedTab { get; }
|
||||||
IObservable<string?> SearchText { get; }
|
IObservable<string?> SearchText { get; }
|
||||||
ViewMode ViewMode { get; }
|
IObservable<ViewMode> ViewMode { get; }
|
||||||
|
string RapidTravelText { get; set; }
|
||||||
|
|
||||||
void AddTab(ITabViewModel tabViewModel);
|
void AddTab(ITabViewModel tabViewModel);
|
||||||
void RemoveTab(ITabViewModel tabViewModel);
|
void RemoveTab(ITabViewModel tabViewModel);
|
||||||
void SetSearchText(string? searchText);
|
void SetSearchText(string? searchText);
|
||||||
|
void SwitchViewMode(ViewMode newViewMode);
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
namespace FileTime.App.Core.ViewModels;
|
||||||
|
|
||||||
|
public interface IModalViewModelBase
|
||||||
|
{
|
||||||
|
string Name { get; }
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
using DynamicData;
|
using System.Reactive.Linq;
|
||||||
using FileTime.App.Core.Command;
|
using FileTime.App.Core.Command;
|
||||||
using FileTime.App.Core.Models;
|
using FileTime.App.Core.Models;
|
||||||
using FileTime.App.Core.ViewModels;
|
using FileTime.App.Core.ViewModels;
|
||||||
@@ -14,7 +14,7 @@ public class ItemManipulationCommandHandler : CommandHandlerBase
|
|||||||
private IItemViewModel? _currentSelectedItem;
|
private IItemViewModel? _currentSelectedItem;
|
||||||
private readonly ICommandHandlerService _commandHandlerService;
|
private readonly ICommandHandlerService _commandHandlerService;
|
||||||
private readonly IClipboardService _clipboardService;
|
private readonly IClipboardService _clipboardService;
|
||||||
private BindedCollection<IAbsolutePath>? _markedItems;
|
private readonly BindedCollection<IAbsolutePath>? _markedItems;
|
||||||
|
|
||||||
public ItemManipulationCommandHandler(
|
public ItemManipulationCommandHandler(
|
||||||
IAppState appState,
|
IAppState appState,
|
||||||
@@ -24,14 +24,11 @@ public class ItemManipulationCommandHandler : CommandHandlerBase
|
|||||||
_commandHandlerService = commandHandlerService;
|
_commandHandlerService = commandHandlerService;
|
||||||
_clipboardService = clipboardService;
|
_clipboardService = clipboardService;
|
||||||
|
|
||||||
SaveSelectedTab(t =>
|
SaveSelectedTab(t => _selectedTab = t);
|
||||||
{
|
|
||||||
_selectedTab = t;
|
|
||||||
_markedItems?.Dispose();
|
|
||||||
_markedItems = t == null ? null : new BindedCollection<IAbsolutePath>(t.MarkedItems);
|
|
||||||
});
|
|
||||||
SaveCurrentSelectedItem(i => _currentSelectedItem = i);
|
SaveCurrentSelectedItem(i => _currentSelectedItem = i);
|
||||||
|
|
||||||
|
_markedItems = new BindedCollection<IAbsolutePath>(appState.SelectedTab.Select(t => t?.MarkedItems));
|
||||||
|
|
||||||
AddCommandHandlers(new (Commands, Func<Task>)[]
|
AddCommandHandlers(new (Commands, Func<Task>)[]
|
||||||
{
|
{
|
||||||
(Commands.Copy, Copy),
|
(Commands.Copy, Copy),
|
||||||
@@ -55,9 +52,9 @@ public class ItemManipulationCommandHandler : CommandHandlerBase
|
|||||||
_clipboardService.Clear();
|
_clipboardService.Clear();
|
||||||
_clipboardService.SetCommand<CopyCommand>();
|
_clipboardService.SetCommand<CopyCommand>();
|
||||||
|
|
||||||
if ((_markedItems?.Collection.Count ?? 0) > 0)
|
if ((_markedItems?.Collection?.Count ?? 0) > 0)
|
||||||
{
|
{
|
||||||
foreach (var item in _markedItems!.Collection)
|
foreach (var item in _markedItems!.Collection!)
|
||||||
{
|
{
|
||||||
_clipboardService.AddContent(item);
|
_clipboardService.AddContent(item);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using System.Reactive.Linq;
|
using System.Reactive.Linq;
|
||||||
using FileTime.App.Core.Command;
|
using FileTime.App.Core.Command;
|
||||||
using FileTime.App.Core.Extensions;
|
using FileTime.App.Core.Extensions;
|
||||||
|
using FileTime.App.Core.Models.Enums;
|
||||||
using FileTime.App.Core.ViewModels;
|
using FileTime.App.Core.ViewModels;
|
||||||
using FileTime.Core.Models;
|
using FileTime.Core.Models;
|
||||||
|
|
||||||
@@ -8,6 +9,7 @@ namespace FileTime.App.Core.Services.CommandHandler;
|
|||||||
|
|
||||||
public class NavigationCommandHandler : CommandHandlerBase
|
public class NavigationCommandHandler : CommandHandlerBase
|
||||||
{
|
{
|
||||||
|
private readonly IAppState _appState;
|
||||||
private ITabViewModel? _selectedTab;
|
private ITabViewModel? _selectedTab;
|
||||||
private IContainer? _currentLocation;
|
private IContainer? _currentLocation;
|
||||||
private IItemViewModel? _currentSelectedItem;
|
private IItemViewModel? _currentSelectedItem;
|
||||||
@@ -15,6 +17,8 @@ public class NavigationCommandHandler : CommandHandlerBase
|
|||||||
|
|
||||||
public NavigationCommandHandler(IAppState appState) : base(appState)
|
public NavigationCommandHandler(IAppState appState) : base(appState)
|
||||||
{
|
{
|
||||||
|
_appState = appState;
|
||||||
|
|
||||||
SaveSelectedTab(t => _selectedTab = t);
|
SaveSelectedTab(t => _selectedTab = t);
|
||||||
SaveCurrentSelectedItem(i => _currentSelectedItem = i);
|
SaveCurrentSelectedItem(i => _currentSelectedItem = i);
|
||||||
SaveCurrentLocation(l => _currentLocation = l);
|
SaveCurrentLocation(l => _currentLocation = l);
|
||||||
@@ -22,6 +26,7 @@ public class NavigationCommandHandler : CommandHandlerBase
|
|||||||
|
|
||||||
AddCommandHandlers(new (Commands, Func<Task>)[]
|
AddCommandHandlers(new (Commands, Func<Task>)[]
|
||||||
{
|
{
|
||||||
|
(Commands.EnterRapidTravel, EnterRapidTravel),
|
||||||
(Commands.GoUp, GoUp),
|
(Commands.GoUp, GoUp),
|
||||||
(Commands.MoveCursorDown, MoveCursorDown),
|
(Commands.MoveCursorDown, MoveCursorDown),
|
||||||
(Commands.MoveCursorUp, MoveCursorUp),
|
(Commands.MoveCursorUp, MoveCursorUp),
|
||||||
@@ -64,4 +69,10 @@ public class NavigationCommandHandler : CommandHandlerBase
|
|||||||
|
|
||||||
_selectedTab.Tab?.SetSelectedItem(newSelectedItem.ToAbsolutePath());
|
_selectedTab.Tab?.SetSelectedItem(newSelectedItem.ToAbsolutePath());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Task EnterRapidTravel()
|
||||||
|
{
|
||||||
|
_appState.SwitchViewMode(ViewMode.RapidTravel);
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -13,17 +13,21 @@ public abstract partial class AppStateBase : IAppState
|
|||||||
private readonly BehaviorSubject<string?> _searchText = new(null);
|
private readonly BehaviorSubject<string?> _searchText = new(null);
|
||||||
private readonly BehaviorSubject<ITabViewModel?> _selectedTab = new(null);
|
private readonly BehaviorSubject<ITabViewModel?> _selectedTab = new(null);
|
||||||
private readonly BehaviorSubject<IEnumerable<ITabViewModel>> _tabs = new(Enumerable.Empty<ITabViewModel>());
|
private readonly BehaviorSubject<IEnumerable<ITabViewModel>> _tabs = new(Enumerable.Empty<ITabViewModel>());
|
||||||
|
private readonly BehaviorSubject<ViewMode> _viewMode = new(Models.Enums.ViewMode.Default);
|
||||||
|
|
||||||
[Property]
|
public IObservable<ViewMode> ViewMode { get; private set; }
|
||||||
private ViewMode _viewMode;
|
|
||||||
|
|
||||||
public ObservableCollection<ITabViewModel> Tabs { get; } = new();
|
public ObservableCollection<ITabViewModel> Tabs { get; } = new();
|
||||||
public IObservable<string?> SearchText { get; private set; }
|
public IObservable<string?> SearchText { get; private set; }
|
||||||
|
|
||||||
public IObservable<ITabViewModel?> SelectedTab { get; private set; }
|
public IObservable<ITabViewModel?> SelectedTab { get; private set; }
|
||||||
|
|
||||||
|
[Property] private string _rapidTravelText = "";
|
||||||
|
|
||||||
partial void OnInitialize()
|
partial void OnInitialize()
|
||||||
{
|
{
|
||||||
|
ViewMode = _viewMode.AsObservable();
|
||||||
|
|
||||||
Tabs.CollectionChanged += (_, _) => _tabs.OnNext(Tabs);
|
Tabs.CollectionChanged += (_, _) => _tabs.OnNext(Tabs);
|
||||||
SearchText = _searchText.AsObservable();
|
SearchText = _searchText.AsObservable();
|
||||||
SelectedTab = Observable.CombineLatest(_tabs, _selectedTab, GetSelectedTab);
|
SelectedTab = Observable.CombineLatest(_tabs, _selectedTab, GetSelectedTab);
|
||||||
@@ -43,6 +47,11 @@ public abstract partial class AppStateBase : IAppState
|
|||||||
|
|
||||||
public void SetSearchText(string? searchText) => _searchText.OnNext(searchText);
|
public void SetSearchText(string? searchText) => _searchText.OnNext(searchText);
|
||||||
|
|
||||||
|
public void SwitchViewMode(ViewMode newViewMode)
|
||||||
|
{
|
||||||
|
_viewMode.OnNext(newViewMode);
|
||||||
|
}
|
||||||
|
|
||||||
public void SetSelectedTab(ITabViewModel tabToSelect) => _selectedTab.OnNext(tabToSelect);
|
public void SetSelectedTab(ITabViewModel tabToSelect) => _selectedTab.OnNext(tabToSelect);
|
||||||
|
|
||||||
private ITabViewModel? GetSelectedTab(IEnumerable<ITabViewModel> tabs, ITabViewModel? expectedSelectedTab)
|
private ITabViewModel? GetSelectedTab(IEnumerable<ITabViewModel> tabs, ITabViewModel? expectedSelectedTab)
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ using FileTime.App.Core.Models.Enums;
|
|||||||
using FileTime.App.Core.Services;
|
using FileTime.App.Core.Services;
|
||||||
using FileTime.Core.Models;
|
using FileTime.Core.Models;
|
||||||
using FileTime.Core.Services;
|
using FileTime.Core.Services;
|
||||||
using FileTime.Tools.Extensions;
|
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using MvvmGen;
|
using MvvmGen;
|
||||||
|
|
||||||
@@ -21,7 +20,7 @@ public partial class TabViewModel : ITabViewModel, IDisposable
|
|||||||
private readonly IRxSchedulerService _rxSchedulerService;
|
private readonly IRxSchedulerService _rxSchedulerService;
|
||||||
private readonly SourceList<IAbsolutePath> _markedItems = new();
|
private readonly SourceList<IAbsolutePath> _markedItems = new();
|
||||||
private readonly List<IDisposable> _disposables = new();
|
private readonly List<IDisposable> _disposables = new();
|
||||||
private bool disposed;
|
private bool _disposed;
|
||||||
|
|
||||||
public ITab? Tab { get; private set; }
|
public ITab? Tab { get; private set; }
|
||||||
public int TabNumber { get; private set; }
|
public int TabNumber { get; private set; }
|
||||||
@@ -96,23 +95,9 @@ public partial class TabViewModel : ITabViewModel, IDisposable
|
|||||||
SelectedsChildrenCollectionObservable = InitAsd(SelectedsChildren);
|
SelectedsChildrenCollectionObservable = InitAsd(SelectedsChildren);
|
||||||
ParentsChildrenCollectionObservable = InitAsd(ParentsChildren);
|
ParentsChildrenCollectionObservable = InitAsd(ParentsChildren);
|
||||||
|
|
||||||
CurrentItems.Subscribe(children =>
|
CurrentItemsCollection = new(CurrentItems);
|
||||||
{
|
ParentsChildrenCollection = new(ParentsChildren);
|
||||||
CurrentItemsCollection?.Dispose();
|
SelectedsChildrenCollection = new(SelectedsChildren);
|
||||||
CurrentItemsCollection = children.MapNull(c => new BindedCollection<IItemViewModel>(c!));
|
|
||||||
});
|
|
||||||
|
|
||||||
ParentsChildren.Subscribe(children =>
|
|
||||||
{
|
|
||||||
ParentsChildrenCollection?.Dispose();
|
|
||||||
ParentsChildrenCollection = children.MapNull(c => new BindedCollection<IItemViewModel>(c!));
|
|
||||||
});
|
|
||||||
|
|
||||||
SelectedsChildren.Subscribe(children =>
|
|
||||||
{
|
|
||||||
SelectedsChildrenCollection?.Dispose();
|
|
||||||
SelectedsChildrenCollection = children.MapNull(c => new BindedCollection<IItemViewModel>(c!));
|
|
||||||
});
|
|
||||||
|
|
||||||
tab.CurrentLocation.Subscribe((_) => _markedItems.Clear());
|
tab.CurrentLocation.Subscribe((_) => _markedItems.Clear());
|
||||||
|
|
||||||
@@ -131,7 +116,7 @@ public partial class TabViewModel : ITabViewModel, IDisposable
|
|||||||
i?.TransformAsync(MapItem)
|
i?.TransformAsync(MapItem)
|
||||||
.Transform(i => MapItemToViewModel(i, ItemViewModelType.SelectedChild))),
|
.Transform(i => MapItemToViewModel(i, ItemViewModelType.SelectedChild))),
|
||||||
currentSelectedItemThrottled
|
currentSelectedItemThrottled
|
||||||
.Where(c => c is null || c is not IContainerViewModel)
|
.Where(c => c is null or not IContainerViewModel)
|
||||||
.Select(_ => (IObservable<IChangeSet<IItemViewModel>>?) null)
|
.Select(_ => (IObservable<IChangeSet<IItemViewModel>>?) null)
|
||||||
)
|
)
|
||||||
.ObserveOn(_rxSchedulerService.GetWorkerScheduler())
|
.ObserveOn(_rxSchedulerService.GetWorkerScheduler())
|
||||||
@@ -251,7 +236,7 @@ public partial class TabViewModel : ITabViewModel, IDisposable
|
|||||||
|
|
||||||
private void Dispose(bool disposing)
|
private void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
if (!disposed && disposing)
|
if (!_disposed && disposing)
|
||||||
{
|
{
|
||||||
foreach (var disposable in _disposables)
|
foreach (var disposable in _disposables)
|
||||||
{
|
{
|
||||||
@@ -265,6 +250,6 @@ public partial class TabViewModel : ITabViewModel, IDisposable
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
disposed = true;
|
_disposed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
6
src/Core/FileTime.Core.Abstraction/Models/IItemFilter.cs
Normal file
6
src/Core/FileTime.Core.Abstraction/Models/IItemFilter.cs
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
namespace FileTime.Core.Models;
|
||||||
|
|
||||||
|
public record ItemFilter(
|
||||||
|
string Name,
|
||||||
|
Func<IItem, bool> Filter
|
||||||
|
);
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
namespace FileTime.Core.Models;
|
|
||||||
|
|
||||||
public record ItemsTransformator(
|
|
||||||
string Name,
|
|
||||||
Func<IEnumerable<IItem>, Task<IEnumerable<IItem>>> Transformator
|
|
||||||
);
|
|
||||||
@@ -11,8 +11,8 @@ public interface ITab : IInitable<IContainer>
|
|||||||
IObservable<IObservable<IChangeSet<IItem>>?> CurrentItems { get; }
|
IObservable<IObservable<IChangeSet<IItem>>?> CurrentItems { get; }
|
||||||
|
|
||||||
void SetCurrentLocation(IContainer newLocation);
|
void SetCurrentLocation(IContainer newLocation);
|
||||||
void AddSelectedItemsTransformator(ItemsTransformator transformator);
|
void AddItemFilter(ItemFilter filter);
|
||||||
void RemoveSelectedItemsTransformator(ItemsTransformator transformator);
|
void RemoveItemFilter(ItemFilter filter);
|
||||||
void RemoveSelectedItemsTransformatorByName(string name);
|
void RemoveItemFilter(string name);
|
||||||
void SetSelectedItem(IAbsolutePath newSelectedItem);
|
void SetSelectedItem(IAbsolutePath newSelectedItem);
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
using System.Reactive.Linq;
|
using System.Reactive.Linq;
|
||||||
using System.Reactive.Subjects;
|
using System.Reactive.Subjects;
|
||||||
using DynamicData;
|
using DynamicData;
|
||||||
|
using DynamicData.Alias;
|
||||||
using FileTime.Core.Models;
|
using FileTime.Core.Models;
|
||||||
|
|
||||||
namespace FileTime.Core.Services;
|
namespace FileTime.Core.Services;
|
||||||
@@ -9,7 +10,7 @@ public class Tab : ITab
|
|||||||
{
|
{
|
||||||
private readonly BehaviorSubject<IContainer?> _currentLocation = new(null);
|
private readonly BehaviorSubject<IContainer?> _currentLocation = new(null);
|
||||||
private readonly BehaviorSubject<IAbsolutePath?> _currentSelectedItem = new(null);
|
private readonly BehaviorSubject<IAbsolutePath?> _currentSelectedItem = new(null);
|
||||||
private readonly List<ItemsTransformator> _transformators = new();
|
private readonly SourceList<ItemFilter> _itemFilters = new();
|
||||||
private IAbsolutePath? _currentSelectedItemCached;
|
private IAbsolutePath? _currentSelectedItemCached;
|
||||||
|
|
||||||
public IObservable<IContainer?> CurrentLocation { get; }
|
public IObservable<IContainer?> CurrentLocation { get; }
|
||||||
@@ -21,11 +22,14 @@ public class Tab : ITab
|
|||||||
CurrentLocation = _currentLocation.DistinctUntilChanged().Publish(null).RefCount();
|
CurrentLocation = _currentLocation.DistinctUntilChanged().Publish(null).RefCount();
|
||||||
CurrentItems =
|
CurrentItems =
|
||||||
Observable.Merge(
|
Observable.Merge(
|
||||||
|
Observable.CombineLatest(
|
||||||
CurrentLocation
|
CurrentLocation
|
||||||
.Where(c => c is not null)
|
.Where(c => c is not null)
|
||||||
.Select(c => c!.Items)
|
.Select(c => c!.Items)
|
||||||
.Switch()
|
.Switch()
|
||||||
.Select(items => items?.TransformAsync(MapItem)),
|
.Select(items => items?.TransformAsync(MapItem)),
|
||||||
|
_itemFilters.Connect().StartWithEmpty().ToCollection(),
|
||||||
|
(items, filters) => items?.Where(i => filters.All(f => f.Filter(i)))),
|
||||||
CurrentLocation
|
CurrentLocation
|
||||||
.Where(c => c is null)
|
.Where(c => c is null)
|
||||||
.Select(_ => (IObservable<IChangeSet<IItem>>?) null)
|
.Select(_ => (IObservable<IChangeSet<IItem>>?) null)
|
||||||
@@ -79,9 +83,14 @@ public class Tab : ITab
|
|||||||
|
|
||||||
public void SetSelectedItem(IAbsolutePath newSelectedItem) => _currentSelectedItem.OnNext(newSelectedItem);
|
public void SetSelectedItem(IAbsolutePath newSelectedItem) => _currentSelectedItem.OnNext(newSelectedItem);
|
||||||
|
|
||||||
public void AddSelectedItemsTransformator(ItemsTransformator transformator) => _transformators.Add(transformator);
|
public void AddItemFilter(ItemFilter filter) => _itemFilters.Add(filter);
|
||||||
public void RemoveSelectedItemsTransformator(ItemsTransformator transformator) => _transformators.Remove(transformator);
|
public void RemoveItemFilter(ItemFilter filter) => _itemFilters.Remove(filter);
|
||||||
public void RemoveSelectedItemsTransformatorByName(string name) => _transformators.RemoveAll(t => t.Name == name);
|
|
||||||
|
public void RemoveItemFilter(string name)
|
||||||
|
{
|
||||||
|
var itemsToRemove = _itemFilters.Items.Where(t => t.Name == name).ToList();
|
||||||
|
_itemFilters.RemoveMany(itemsToRemove);
|
||||||
|
}
|
||||||
|
|
||||||
public async Task OpenSelected()
|
public async Task OpenSelected()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -30,7 +30,8 @@ public static class Startup
|
|||||||
.AddSingleton<IKeyInputHandlerService, KeyInputHandlerService>()
|
.AddSingleton<IKeyInputHandlerService, KeyInputHandlerService>()
|
||||||
.AddSingleton<IDefaultModeKeyInputHandler, DefaultModeKeyInputHandler>()
|
.AddSingleton<IDefaultModeKeyInputHandler, DefaultModeKeyInputHandler>()
|
||||||
.AddSingleton<IKeyboardConfigurationService, KeyboardConfigurationService>()
|
.AddSingleton<IKeyboardConfigurationService, KeyboardConfigurationService>()
|
||||||
.AddSingleton<IRapidTravelModeKeyInputHandler, RapidTravelModeKeyInputHandler>();
|
.AddSingleton<IRapidTravelModeKeyInputHandler, RapidTravelModeKeyInputHandler>()
|
||||||
|
.AddSingleton<IModalService, ModalService>();
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static IServiceCollection RegisterLogging(this IServiceCollection serviceCollection)
|
internal static IServiceCollection RegisterLogging(this IServiceCollection serviceCollection)
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ public class KeyInputHandlerService : IKeyInputHandlerService
|
|||||||
private readonly IGuiAppState _appState;
|
private readonly IGuiAppState _appState;
|
||||||
private readonly IDefaultModeKeyInputHandler _defaultModeKeyInputHandler;
|
private readonly IDefaultModeKeyInputHandler _defaultModeKeyInputHandler;
|
||||||
private readonly IRapidTravelModeKeyInputHandler _rapidTravelModeKeyInputHandler;
|
private readonly IRapidTravelModeKeyInputHandler _rapidTravelModeKeyInputHandler;
|
||||||
|
private ViewMode _viewMode;
|
||||||
|
|
||||||
public KeyInputHandlerService(
|
public KeyInputHandlerService(
|
||||||
IGuiAppState appState,
|
IGuiAppState appState,
|
||||||
@@ -21,16 +22,18 @@ public class KeyInputHandlerService : IKeyInputHandlerService
|
|||||||
_appState = appState;
|
_appState = appState;
|
||||||
_defaultModeKeyInputHandler = defaultModeKeyInputHandler;
|
_defaultModeKeyInputHandler = defaultModeKeyInputHandler;
|
||||||
_rapidTravelModeKeyInputHandler = rapidTravelModeKeyInputHandler;
|
_rapidTravelModeKeyInputHandler = rapidTravelModeKeyInputHandler;
|
||||||
|
|
||||||
|
appState.ViewMode.Subscribe(v => _viewMode = v);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task ProcessKeyDown(Key key, KeyModifiers keyModifiers, Action<bool> setHandled)
|
public async Task ProcessKeyDown(Key key, KeyModifiers keyModifiers, Action<bool> setHandled)
|
||||||
{
|
{
|
||||||
if (key == Key.LeftAlt
|
if (key is Key.LeftAlt
|
||||||
|| key == Key.RightAlt
|
or Key.RightAlt
|
||||||
|| key == Key.LeftShift
|
or Key.LeftShift
|
||||||
|| key == Key.RightShift
|
or Key.RightShift
|
||||||
|| key == Key.LeftCtrl
|
or Key.LeftCtrl
|
||||||
|| key == Key.RightCtrl)
|
or Key.RightCtrl)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -43,7 +46,7 @@ public class KeyInputHandlerService : IKeyInputHandlerService
|
|||||||
|
|
||||||
var specialKeyStatus = new SpecialKeysStatus(isAltPressed, isShiftPressed, isCtrlPressed);
|
var specialKeyStatus = new SpecialKeysStatus(isAltPressed, isShiftPressed, isCtrlPressed);
|
||||||
|
|
||||||
if (_appState.ViewMode == ViewMode.Default)
|
if (_viewMode == ViewMode.Default)
|
||||||
{
|
{
|
||||||
await _defaultModeKeyInputHandler.HandleInputKey(key, specialKeyStatus, setHandled);
|
await _defaultModeKeyInputHandler.HandleInputKey(key, specialKeyStatus, setHandled);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,12 +49,6 @@ public class KeyboardConfigurationService : IKeyboardConfigurationService
|
|||||||
|
|
||||||
private static bool IsUniversal(CommandBindingConfiguration keyMapping)
|
private static bool IsUniversal(CommandBindingConfiguration keyMapping)
|
||||||
{
|
{
|
||||||
return keyMapping.Command == Commands.GoUp
|
return keyMapping.Command is Commands.GoUp or Commands.Open or Commands.OpenOrRun or Commands.MoveCursorUp or Commands.MoveCursorDown or Commands.MoveCursorUpPage or Commands.MoveCursorDownPage;
|
||||||
|| keyMapping.Command == Commands.Open
|
|
||||||
|| keyMapping.Command == Commands.OpenOrRun
|
|
||||||
|| keyMapping.Command == Commands.MoveCursorUp
|
|
||||||
|| keyMapping.Command == Commands.MoveCursorDown
|
|
||||||
|| keyMapping.Command == Commands.MoveCursorUpPage
|
|
||||||
|| keyMapping.Command == Commands.MoveCursorDownPage;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
20
src/GuiApp/Avalonia/FileTime.GuiApp/Services/ModalService.cs
Normal file
20
src/GuiApp/Avalonia/FileTime.GuiApp/Services/ModalService.cs
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
using DynamicData;
|
||||||
|
using FileTime.App.Core.Services;
|
||||||
|
using FileTime.App.Core.ViewModels;
|
||||||
|
|
||||||
|
namespace FileTime.GuiApp.Services;
|
||||||
|
|
||||||
|
public class ModalService : IModalService
|
||||||
|
{
|
||||||
|
private readonly SourceList<IModalViewModelBase> _openModals = new();
|
||||||
|
public IObservable<IChangeSet<IModalViewModelBase>> OpenModals { get; }
|
||||||
|
|
||||||
|
public ModalService()
|
||||||
|
{
|
||||||
|
OpenModals = _openModals.Connect();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OpenModal(IModalViewModelBase modalToOpen) => _openModals.Add(modalToOpen);
|
||||||
|
|
||||||
|
public void CloseModal(IModalViewModelBase modalToClose) => _openModals.Remove(modalToClose);
|
||||||
|
}
|
||||||
@@ -1,29 +1,62 @@
|
|||||||
using Avalonia.Input;
|
using Avalonia.Input;
|
||||||
|
using FileTime.App.Core.Command;
|
||||||
|
using FileTime.App.Core.Models;
|
||||||
|
using FileTime.App.Core.Models.Enums;
|
||||||
|
using FileTime.App.Core.Services;
|
||||||
|
using FileTime.App.Core.ViewModels;
|
||||||
|
using FileTime.Core.Models;
|
||||||
|
using FileTime.Core.Services;
|
||||||
|
using FileTime.GuiApp.Configuration;
|
||||||
|
using FileTime.GuiApp.Extensions;
|
||||||
using FileTime.GuiApp.Models;
|
using FileTime.GuiApp.Models;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
namespace FileTime.GuiApp.Services;
|
namespace FileTime.GuiApp.Services;
|
||||||
|
|
||||||
public class RapidTravelModeKeyInputHandler : IRapidTravelModeKeyInputHandler
|
public class RapidTravelModeKeyInputHandler : IRapidTravelModeKeyInputHandler
|
||||||
{
|
{
|
||||||
|
private const string RAPIDTRAVELFILTERNAME = "rapid_travel_filter";
|
||||||
|
private readonly IAppState _appState;
|
||||||
|
private readonly IModalService _modalService;
|
||||||
|
private readonly IKeyboardConfigurationService _keyboardConfigurationService;
|
||||||
|
private readonly ICommandHandlerService _commandHandlerService;
|
||||||
|
private readonly ILogger<RapidTravelModeKeyInputHandler> _logger;
|
||||||
|
private readonly BindedCollection<IModalViewModelBase> _openModals;
|
||||||
|
private ITabViewModel? _selectedTab;
|
||||||
|
|
||||||
|
public RapidTravelModeKeyInputHandler(
|
||||||
|
IAppState appState,
|
||||||
|
IModalService modalService,
|
||||||
|
IKeyboardConfigurationService keyboardConfigurationService,
|
||||||
|
ICommandHandlerService commandHandlerService,
|
||||||
|
ILogger<RapidTravelModeKeyInputHandler> logger)
|
||||||
|
{
|
||||||
|
_appState = appState;
|
||||||
|
_modalService = modalService;
|
||||||
|
_keyboardConfigurationService = keyboardConfigurationService;
|
||||||
|
_commandHandlerService = commandHandlerService;
|
||||||
|
_logger = logger;
|
||||||
|
|
||||||
|
_appState.SelectedTab.Subscribe(t => _selectedTab = t);
|
||||||
|
|
||||||
|
_openModals = new BindedCollection<IModalViewModelBase>(modalService.OpenModals);
|
||||||
|
}
|
||||||
|
|
||||||
public async Task HandleInputKey(Key key, SpecialKeysStatus specialKeysStatus, Action<bool> setHandled)
|
public async Task HandleInputKey(Key key, SpecialKeysStatus specialKeysStatus, Action<bool> setHandled)
|
||||||
{
|
{
|
||||||
/*var keyString = key.ToString();
|
var keyString = key.ToString();
|
||||||
var updateRapidTravelFilter = false;
|
var updateRapidTravelFilter = false;
|
||||||
|
|
||||||
if (key == Key.Escape)
|
if (key == Key.Escape)
|
||||||
{
|
{
|
||||||
setHandled(true);
|
setHandled(true);
|
||||||
if (_appState.IsAllShortcutVisible)
|
if ((_openModals.Collection?.Count ?? 0) > 0)
|
||||||
{
|
{
|
||||||
_appState.IsAllShortcutVisible = false;
|
_modalService.CloseModal(_openModals.Collection!.Last());
|
||||||
}
|
|
||||||
else if (_appState.MessageBoxText != null)
|
|
||||||
{
|
|
||||||
_appState.MessageBoxText = null;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
await _appState.ExitRapidTravelMode();
|
_appState.SwitchViewMode(ViewMode.Default);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (key == Key.Back)
|
else if (key == Key.Back)
|
||||||
@@ -44,7 +77,7 @@ public class RapidTravelModeKeyInputHandler : IRapidTravelModeKeyInputHandler
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
var currentKeyAsList = new List<KeyConfig>() {new KeyConfig(key)};
|
var currentKeyAsList = new List<KeyConfig>() {new KeyConfig(key)};
|
||||||
var selectedCommandBinding = _keyboardConfigurationService.UniversalCommandBindings.FirstOrDefault(c => AreKeysEqual(c.Keys, currentKeyAsList));
|
var selectedCommandBinding = _keyboardConfigurationService.UniversalCommandBindings.FirstOrDefault(c => c.Keys.AreKeysEqual(currentKeyAsList));
|
||||||
if (selectedCommandBinding != null)
|
if (selectedCommandBinding != null)
|
||||||
{
|
{
|
||||||
setHandled(true);
|
setHandled(true);
|
||||||
@@ -54,7 +87,11 @@ public class RapidTravelModeKeyInputHandler : IRapidTravelModeKeyInputHandler
|
|||||||
|
|
||||||
if (updateRapidTravelFilter)
|
if (updateRapidTravelFilter)
|
||||||
{
|
{
|
||||||
var currentLocation = await _appState.SelectedTab.CurrentLocation.Container.WithoutVirtualContainer(MainPageViewModel.RAPIDTRAVEL);
|
if (_selectedTab?.Tab is not ITab tab) return;
|
||||||
|
|
||||||
|
tab.RemoveItemFilter(RAPIDTRAVELFILTERNAME);
|
||||||
|
tab.AddItemFilter(new ItemFilter(RAPIDTRAVELFILTERNAME, i => i.Name.ToLower().Contains(_appState.RapidTravelText)));
|
||||||
|
/*var currentLocation = await _appState.SelectedTab.CurrentLocation.Container.WithoutVirtualContainer(MainPageViewModel.RAPIDTRAVEL);
|
||||||
var newLocation = new VirtualContainer(
|
var newLocation = new VirtualContainer(
|
||||||
currentLocation,
|
currentLocation,
|
||||||
new List<Func<IEnumerable<IContainer>, IEnumerable<IContainer>>>()
|
new List<Func<IEnumerable<IContainer>, IEnumerable<IContainer>>>()
|
||||||
@@ -81,7 +118,19 @@ public class RapidTravelModeKeyInputHandler : IRapidTravelModeKeyInputHandler
|
|||||||
else if (!currentLocationItems.Select(i => i.Item.Name).Any(n => n == selectedItemName))
|
else if (!currentLocationItems.Select(i => i.Item.Name).Any(n => n == selectedItemName))
|
||||||
{
|
{
|
||||||
await _appState.SelectedTab.MoveCursorToFirst();
|
await _appState.SelectedTab.MoveCursorToFirst();
|
||||||
}
|
|
||||||
}*/
|
}*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task CallCommandAsync(Commands command)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await _commandHandlerService.HandleCommandAsync(command);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
_logger.LogError(e, "Unknown error while running command. {Command} {Error}", command, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -236,6 +236,35 @@
|
|||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
<Grid Grid.Row="3">
|
<Grid Grid.Row="3">
|
||||||
|
<Grid
|
||||||
|
IsVisible="{Binding AppState.ViewMode^, Converter={StaticResource EqualityConverter},ConverterParameter=RapidTravel}">
|
||||||
|
<Grid.RowDefinitions>
|
||||||
|
<RowDefinition Height="1" />
|
||||||
|
<RowDefinition Height="Auto" />
|
||||||
|
</Grid.RowDefinitions>
|
||||||
|
|
||||||
|
<Rectangle
|
||||||
|
Height="1"
|
||||||
|
Margin="10,0"
|
||||||
|
HorizontalAlignment="Stretch"
|
||||||
|
VerticalAlignment="Center"
|
||||||
|
Fill="{DynamicResource ContentSeparatorBrush}" />
|
||||||
|
|
||||||
|
<StackPanel
|
||||||
|
Grid.Row="1"
|
||||||
|
Margin="30,10,10,10"
|
||||||
|
Orientation="Horizontal">
|
||||||
|
|
||||||
|
<TextBlock
|
||||||
|
Margin="0,0,30,0"
|
||||||
|
Text="Rapid travel mode" />
|
||||||
|
|
||||||
|
<TextBlock Text="Filter " />
|
||||||
|
|
||||||
|
<TextBlock Text="{Binding AppState.RapidTravelText}" />
|
||||||
|
</StackPanel>
|
||||||
|
</Grid>
|
||||||
|
|
||||||
<Grid
|
<Grid
|
||||||
IsVisible="{Binding AppState.PossibleCommands.Count, Converter={StaticResource NotEqualsConverter}, ConverterParameter=0}">
|
IsVisible="{Binding AppState.PossibleCommands.Count, Converter={StaticResource NotEqualsConverter}, ConverterParameter=0}">
|
||||||
<Grid.RowDefinitions>
|
<Grid.RowDefinitions>
|
||||||
|
|||||||
Reference in New Issue
Block a user