Controls, Startup&Driver improvements

This commit is contained in:
2023-08-09 11:54:32 +02:00
parent 2528487ff6
commit d549733b71
49 changed files with 875 additions and 120 deletions

View File

@@ -0,0 +1,3 @@
namespace FileTime.App.Core.Configuration;
public record ApplicationConfiguration(bool AllowCloseLastTab);

View File

@@ -4,4 +4,5 @@ public static class SectionNames
{
public const string KeybindingSectionName = "KeyBindings";
public const string ProgramsSectionName = "Programs";
public const string ApplicationSectionName = "Application";
}

View File

@@ -2,6 +2,7 @@ using System.Collections.ObjectModel;
using System.Diagnostics;
using DeclarativeProperty;
using FileTime.App.CommandPalette.Services;
using FileTime.App.Core.Configuration;
using FileTime.App.Core.Extensions;
using FileTime.App.Core.Models.Enums;
using FileTime.App.Core.UserCommand;
@@ -14,6 +15,7 @@ using FileTime.Core.Timeline;
using FileTime.Providers.Local;
using InitableService;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
namespace FileTime.App.Core.Services.UserCommandHandler;
@@ -29,6 +31,7 @@ public class NavigationUserCommandHandlerService : UserCommandHandlerServiceBase
private readonly IFrequencyNavigationService _frequencyNavigationService;
private readonly ICommandPaletteService _commandPaletteService;
private readonly ILogger<NavigationUserCommandHandlerService> _logger;
private readonly ApplicationConfiguration _applicationConfiguration;
private ITabViewModel? _selectedTab;
private IDeclarativeProperty<IContainer?>? _currentLocation;
private IDeclarativeProperty<IItemViewModel?>? _currentSelectedItem;
@@ -44,7 +47,8 @@ public class NavigationUserCommandHandlerService : UserCommandHandlerServiceBase
IUserCommunicationService userCommunicationService,
IFrequencyNavigationService frequencyNavigationService,
ICommandPaletteService commandPaletteService,
ILogger<NavigationUserCommandHandlerService> logger) : base(appState)
ILogger<NavigationUserCommandHandlerService> logger,
ApplicationConfiguration applicationConfiguration) : base(appState)
{
_appState = appState;
_serviceProvider = serviceProvider;
@@ -55,6 +59,7 @@ public class NavigationUserCommandHandlerService : UserCommandHandlerServiceBase
_frequencyNavigationService = frequencyNavigationService;
_commandPaletteService = commandPaletteService;
_logger = logger;
_applicationConfiguration = applicationConfiguration;
SaveSelectedTab(t => _selectedTab = t);
SaveCurrentSelectedItem(i => _currentSelectedItem = i);
@@ -387,7 +392,7 @@ public class NavigationUserCommandHandlerService : UserCommandHandlerServiceBase
private Task CloseTab()
{
if (_appState.Tabs.Count < 2 || _selectedTab == null) return Task.CompletedTask;
if ((!_applicationConfiguration.AllowCloseLastTab && _appState.Tabs.Count < 2) || _selectedTab == null) return Task.CompletedTask;
var tabToRemove = _selectedTab;
_appState.RemoveTab(tabToRemove!);

View File

@@ -41,20 +41,16 @@ public static class Startup
.AddSingleton<IExitHandler, ContainerRefreshHandler>();
}
private static IServiceCollection AddCommandHandlers(this IServiceCollection serviceCollection)
{
return serviceCollection
private static IServiceCollection AddCommandHandlers(this IServiceCollection serviceCollection) =>
serviceCollection
.AddSingleton<IUserCommandHandler, NavigationUserCommandHandlerService>()
.AddSingleton<IUserCommandHandler, ItemManipulationUserCommandHandlerService>()
.AddSingleton<IUserCommandHandler, ToolUserCommandHandlerService>()
.AddSingleton<IUserCommandHandler, CommandSchedulerUserCommandHandlerService>();
}
internal static IServiceCollection AddConfiguration(this IServiceCollection serviceCollection, IConfigurationRoot configuration)
{
return serviceCollection
internal static IServiceCollection AddConfiguration(this IServiceCollection serviceCollection, IConfigurationRoot configuration) =>
serviceCollection
.Configure<ProgramsConfiguration>(configuration.GetSection(SectionNames.ProgramsSectionName))
.Configure<KeyBindingConfiguration>(configuration.GetSection(SectionNames.KeybindingSectionName))
.AddSingleton<IConfiguration>(configuration);
}
}