Container traits to extensions
This commit is contained in:
@@ -22,8 +22,9 @@ public class FormatSizeConverter : IValueConverter
|
||||
|
||||
public static string ToSizeString(long fileSize, int? precision = null)
|
||||
{
|
||||
var size = new ByteSize(fileSize);
|
||||
return precision == null? size.ToString()
|
||||
var size = ByteSize.FromBytes(fileSize);
|
||||
return precision == null
|
||||
? size.ToString()
|
||||
: size.ToString("0." + new string('#', precision.Value));
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,16 @@
|
||||
using System.Reactive.Linq;
|
||||
using Avalonia.Input;
|
||||
using FileTime.App.Core.Services;
|
||||
using FileTime.App.Core.UserCommand;
|
||||
using FileTime.App.Core.ViewModels;
|
||||
using FileTime.Core.Extensions;
|
||||
using FileTime.Core.Models;
|
||||
using FileTime.Core.Models.ContainerTraits;
|
||||
using FileTime.Core.Models.Extensions;
|
||||
using FileTime.GuiApp.Configuration;
|
||||
using FileTime.GuiApp.Extensions;
|
||||
using FileTime.GuiApp.Models;
|
||||
using FileTime.GuiApp.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using DeclarativeProperty;
|
||||
|
||||
namespace FileTime.GuiApp.Services;
|
||||
|
||||
@@ -20,8 +20,7 @@ public class DefaultModeKeyInputHandler : IDefaultModeKeyInputHandler
|
||||
private readonly IModalService _modalService;
|
||||
private readonly IKeyboardConfigurationService _keyboardConfigurationService;
|
||||
private readonly List<KeyConfig[]> _keysToSkip = new();
|
||||
private ITabViewModel? _selectedTab;
|
||||
private IContainer? _currentLocation;
|
||||
private readonly IDeclarativeProperty<IContainer?> _currentLocation;
|
||||
private readonly ILogger<DefaultModeKeyInputHandler> _logger;
|
||||
private readonly IUserCommandHandlerService _userCommandHandlerService;
|
||||
private readonly IIdentifiableUserCommandService _identifiableUserCommandService;
|
||||
@@ -42,19 +41,20 @@ public class DefaultModeKeyInputHandler : IDefaultModeKeyInputHandler
|
||||
_modalService = modalService;
|
||||
_userCommandHandlerService = userCommandHandlerService;
|
||||
|
||||
_appState.SelectedTab.Subscribe(t => _selectedTab = t);
|
||||
_appState.SelectedTab.Select(t => t == null ? Observable.Return<IContainer?>(null) : t.CurrentLocation!).Switch().Subscribe(l => _currentLocation = l);
|
||||
_currentLocation = _appState.SelectedTab
|
||||
.Map(t => t?.CurrentLocation)
|
||||
.Switch();
|
||||
|
||||
_openModals = modalService.OpenModals.ToBindedCollection();
|
||||
|
||||
_keysToSkip.Add(new KeyConfig[] { new KeyConfig(Key.Up) });
|
||||
_keysToSkip.Add(new KeyConfig[] { new KeyConfig(Key.Down) });
|
||||
_keysToSkip.Add(new KeyConfig[] { new KeyConfig(Key.Tab) });
|
||||
_keysToSkip.Add(new KeyConfig[] { new KeyConfig(Key.PageDown) });
|
||||
_keysToSkip.Add(new KeyConfig[] { new KeyConfig(Key.PageUp) });
|
||||
_keysToSkip.Add(new KeyConfig[] { new KeyConfig(Key.F4, alt: true) });
|
||||
_keysToSkip.Add(new KeyConfig[] { new KeyConfig(Key.LWin) });
|
||||
_keysToSkip.Add(new KeyConfig[] { new KeyConfig(Key.RWin) });
|
||||
_keysToSkip.Add(new[] {new KeyConfig(Key.Up)});
|
||||
_keysToSkip.Add(new[] {new KeyConfig(Key.Down)});
|
||||
_keysToSkip.Add(new[] {new KeyConfig(Key.Tab)});
|
||||
_keysToSkip.Add(new[] {new KeyConfig(Key.PageDown)});
|
||||
_keysToSkip.Add(new[] {new KeyConfig(Key.PageUp)});
|
||||
_keysToSkip.Add(new[] {new KeyConfig(Key.F4, alt: true)});
|
||||
_keysToSkip.Add(new[] {new KeyConfig(Key.LWin)});
|
||||
_keysToSkip.Add(new[] {new KeyConfig(Key.RWin)});
|
||||
}
|
||||
|
||||
public async Task HandleInputKey(Key key, SpecialKeysStatus specialKeysStatus, Action<bool> setHandled)
|
||||
@@ -73,7 +73,7 @@ public class DefaultModeKeyInputHandler : IDefaultModeKeyInputHandler
|
||||
{
|
||||
_modalService.CloseModal(_openModals.Collection!.Last());
|
||||
}
|
||||
else if (_currentLocation is IEscHandlerContainer escHandler)
|
||||
else if (_currentLocation.Value?.GetExtension<EscHandlerContainerExtension>() is { } escHandler)
|
||||
{
|
||||
var escapeResult = await escHandler.HandleEsc();
|
||||
if (escapeResult.NavigateTo != null)
|
||||
@@ -118,7 +118,11 @@ public class DefaultModeKeyInputHandler : IDefaultModeKeyInputHandler
|
||||
setHandled(true);
|
||||
_appState.PreviousKeys.Clear();
|
||||
_appState.PossibleCommands = new();
|
||||
await CallCommandAsync(_identifiableUserCommandService.GetCommand(selectedCommandBinding.Command));
|
||||
var command = _identifiableUserCommandService.GetCommand(selectedCommandBinding.Command);
|
||||
if (command is not null)
|
||||
{
|
||||
await CallCommandAsync(command);
|
||||
}
|
||||
}
|
||||
else if (_keysToSkip.Any(k => k.AreKeysEqual(_appState.PreviousKeys)))
|
||||
{
|
||||
|
||||
@@ -10,6 +10,7 @@ public class ModalService : IModalService
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
private readonly SourceList<IModalViewModel> _openModals = new();
|
||||
public IObservable<IChangeSet<IModalViewModel>> OpenModals { get; }
|
||||
public event EventHandler? AllModalClosed;
|
||||
|
||||
public ModalService(IServiceProvider serviceProvider)
|
||||
{
|
||||
@@ -19,8 +20,15 @@ public class ModalService : IModalService
|
||||
|
||||
public void OpenModal(IModalViewModel modalToOpen) => _openModals.Add(modalToOpen);
|
||||
|
||||
public void CloseModal(IModalViewModel modalToClose) => _openModals.Remove(modalToClose);
|
||||
|
||||
public void CloseModal(IModalViewModel modalToClose)
|
||||
{
|
||||
_openModals.Remove(modalToClose);
|
||||
if (_openModals.Count == 0)
|
||||
{
|
||||
AllModalClosed?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
public T OpenModal<T>() where T : IModalViewModel
|
||||
{
|
||||
var modal = _serviceProvider.GetRequiredService<T>();
|
||||
|
||||
@@ -32,12 +32,14 @@ namespace FileTime.GuiApp.ViewModels;
|
||||
[Inject(typeof(IRefreshSmoothnessCalculator), PropertyAccessModifier = AccessModifier.Public)]
|
||||
[Inject(typeof(IAdminElevationManager), PropertyAccessModifier = AccessModifier.Public)]
|
||||
[Inject(typeof(IClipboardService), PropertyAccessModifier = AccessModifier.Public)]
|
||||
[Inject(typeof(IModalService), PropertyName = "_modalService")]
|
||||
public partial class MainWindowViewModel : IMainWindowViewModel
|
||||
{
|
||||
public bool Loading => false;
|
||||
public IObservable<string?> MainFont => _fontService.MainFont.Select(x => x ?? "");
|
||||
public IGuiAppState AppState => _appState;
|
||||
public string Title { get; private set; }
|
||||
public Action? FocusDefaultElement { get; set; }
|
||||
|
||||
partial void OnInitialize()
|
||||
{
|
||||
@@ -59,13 +61,13 @@ public partial class MainWindowViewModel : IMainWindowViewModel
|
||||
Title += " (Debug)";
|
||||
#endif
|
||||
|
||||
_modalService.AllModalClosed += (_, _) => FocusDefaultElement?.Invoke();
|
||||
|
||||
Task.Run(async () => await _lifecycleService.InitStartupHandlersAsync()).Wait();
|
||||
}
|
||||
|
||||
public void ProcessKeyDown(Key key, KeyModifiers keyModifiers, Action<bool> setHandled)
|
||||
{
|
||||
_keyInputHandlerService.ProcessKeyDown(key, keyModifiers, setHandled);
|
||||
}
|
||||
public void ProcessKeyDown(Key key, KeyModifiers keyModifiers, Action<bool> setHandled)
|
||||
=> _keyInputHandlerService.ProcessKeyDown(key, keyModifiers, setHandled);
|
||||
|
||||
public async Task OpenContainerByFullName(FullName fullName)
|
||||
{
|
||||
@@ -75,8 +77,6 @@ public partial class MainWindowViewModel : IMainWindowViewModel
|
||||
new OpenContainerCommand(new AbsolutePath(_timelessContentProvider, resolvedContainer)));
|
||||
}
|
||||
|
||||
public async Task OnExit()
|
||||
{
|
||||
await _lifecycleService.ExitAsync();
|
||||
}
|
||||
public async Task OnExit()
|
||||
=> await _lifecycleService.ExitAsync();
|
||||
}
|
||||
@@ -74,7 +74,10 @@ public partial class MainWindow : Window, IUiAccessor
|
||||
|
||||
_logger?.LogInformation(
|
||||
$"{nameof(MainWindow)} opened, starting {nameof(MainWindowViewModel)} initialization...");
|
||||
ViewModel = DI.ServiceProvider.GetRequiredService<MainWindowViewModel>();
|
||||
|
||||
var viewModel = DI.ServiceProvider.GetRequiredService<MainWindowViewModel>();
|
||||
viewModel.FocusDefaultElement = () => Focus();
|
||||
ViewModel = viewModel;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,7 +114,7 @@ public partial class MainWindow : Window, IUiAccessor
|
||||
&& sender is StyledElement control)
|
||||
{
|
||||
FullName? path = null;
|
||||
if (control.DataContext is IHaveFullPath { Path: { } } hasFullPath)
|
||||
if (control.DataContext is IHaveFullPath {Path: { }} hasFullPath)
|
||||
{
|
||||
path = hasFullPath.Path;
|
||||
}
|
||||
@@ -154,7 +157,12 @@ public partial class MainWindow : Window, IUiAccessor
|
||||
private void OnWindowClosed(object? sender, EventArgs e)
|
||||
{
|
||||
var vm = ViewModel;
|
||||
Task.Run(() => vm?.OnExit()).Wait();
|
||||
Task.Run(async () =>
|
||||
{
|
||||
if (vm is null) return;
|
||||
await vm.OnExit();
|
||||
})
|
||||
.Wait();
|
||||
}
|
||||
|
||||
private void InputList_OnKeyUp(object? sender, KeyEventArgs e)
|
||||
|
||||
Reference in New Issue
Block a user