Too much to name... but damn, it got where we are needed

This commit is contained in:
TheXamlGuy
2024-01-14 15:06:30 +00:00
parent 66f4bb8757
commit 1283e8ff58
59 changed files with 511 additions and 250 deletions
@@ -9,4 +9,8 @@ public class PrimaryCommandConfiguration
public required Guid Id { get; set; }
public required string Icon { get; set; }
public required string Text { get; set; }
public List<PrimaryCommandConfiguration>? Commands { get; set; } = [];
}
@@ -5,6 +5,6 @@ public class PrimaryWidgetConfiguration :
{
public static PrimaryWidgetConfiguration Defaults => new()
{
new KeyAcceleratorCommandConfiguration { Id = Guid.NewGuid(), Icon = "\uE720", Key = 91, Modifiers = [] }
new KeyAcceleratorCommandConfiguration { Id = Guid.NewGuid(), Icon = "\uE720", Text = "Test", Key = 91, Modifiers = [] }
};
}
@@ -1,9 +1,9 @@
namespace Hyperbar.Windows.Primary;
public class ConfigurationChangedHandler(IMediator mediator,
public class PrimaryWidgetConfigurationHandler(IMediator mediator,
PrimaryWidgetConfiguration configuration,
IViewModelFactory<PrimaryCommandConfiguration, IWidgetComponentViewModel?> factory,
IViewModelCache<Guid, IWidgetComponentViewModel> cache) :
IFactory<PrimaryCommandConfiguration, IWidgetComponentViewModel?> factory,
ICache<Guid, IWidgetComponentViewModel> cache) :
INotificationHandler<ConfigurationChanged<PrimaryWidgetConfiguration>>
{
public async ValueTask Handle(ConfigurationChanged<PrimaryWidgetConfiguration> notification,
@@ -8,10 +8,10 @@ public class PrimaryWidgetProvider :
{
public void Create(HostBuilderContext comtext, IServiceCollection services) =>
services.AddConfiguration<PrimaryWidgetConfiguration>()
.AddSingleton<IViewModelCache<Guid, IWidgetComponentViewModel>, ViewModelCache<Guid, IWidgetComponentViewModel>>()
.AddTransient<IViewModelFactory<PrimaryCommandConfiguration, IWidgetComponentViewModel?>, WidgetComponentViewModelFactory>()
.AddSingleton<ICache<Guid, IWidgetComponentViewModel>, Cache<Guid, IWidgetComponentViewModel>>()
.AddTransient<IFactory<PrimaryCommandConfiguration, IWidgetComponentViewModel?>, WidgetComponentViewModelFactory>()
.AddTransient<IViewModelEnumerator<IWidgetComponentViewModel>, WidgetComponentViewModelEnumerator>()
.AddWidgetTemplate<PrimaryWidgetViewModel>()
.AddHandler<ConfigurationChangedHandler>();
.AddHandler<PrimaryWidgetConfigurationHandler>();
}
@@ -1,7 +1,7 @@
namespace Hyperbar.Windows.Primary;
public class WidgetComponentViewModelEnumerator(PrimaryWidgetConfiguration configuration,
IViewModelFactory<PrimaryCommandConfiguration, IWidgetComponentViewModel?> factory) :
IFactory<PrimaryCommandConfiguration, IWidgetComponentViewModel?> factory) :
IViewModelEnumerator<IWidgetComponentViewModel>
{
public IEnumerable<IWidgetComponentViewModel?> Next()
@@ -4,31 +4,71 @@ namespace Hyperbar.Windows.Primary;
public class WidgetComponentViewModelFactory(IServiceFactory service,
IMediator mediator,
IViewModelCache<Guid, IWidgetComponentViewModel> cache) :
IViewModelFactory<PrimaryCommandConfiguration, IWidgetComponentViewModel?>
ICache<Guid, IWidgetComponentViewModel> cache) :
IFactory<PrimaryCommandConfiguration, IWidgetComponentViewModel?>
{
public IWidgetComponentViewModel? Create(PrimaryCommandConfiguration value)
public IWidgetComponentViewModel? Create(PrimaryCommandConfiguration configuration)
{
IWidgetComponentViewModel? viewModel = default;
WidgetComponentViewModel? viewModel = default;
if (value is KeyAcceleratorCommandConfiguration keyAcceleratorCommand)
if (configuration is KeyAcceleratorCommandConfiguration keyAcceleratorCommandConfiguration)
{
viewModel = service.Create<WidgetButtonViewModel>(keyAcceleratorCommand.Id, keyAcceleratorCommand.Icon,
new RelayCommand(async () => await mediator.SendAsync(new KeyAcceleratorRequest((VirtualKey)
keyAcceleratorCommand.Key, keyAcceleratorCommand.Modifiers?
viewModel = service.Create<WidgetButtonViewModel>(keyAcceleratorCommandConfiguration.Id,
keyAcceleratorCommandConfiguration.Text, keyAcceleratorCommandConfiguration.Icon,
new RelayCommand(async () => await mediator.SendAsync(new KeyAccelerator((VirtualKey)
keyAcceleratorCommandConfiguration.Key, keyAcceleratorCommandConfiguration.Modifiers?
.Select(modifier => (VirtualKey)modifier).ToArray()))));
}
if (value is ProcessCommandConfiguration commandConfiguration)
if (configuration is ProcessCommandConfiguration processCommandConfiguration)
{
viewModel = service.Create<WidgetButtonViewModel>(commandConfiguration.Id,
commandConfiguration.Icon, new RelayCommand(async () =>
await mediator.SendAsync(new ProcessRequest(commandConfiguration.Path))));
if (processCommandConfiguration.Commands is { Count: > 0 } childCommandConfigurations)
{
List<IWidgetComponentViewModel> childViewModels = [];
foreach (PrimaryCommandConfiguration childCommandConfiguration in childCommandConfigurations)
{
WidgetComponentViewModel? childViewModel = null;
if (childCommandConfiguration is ProcessCommandConfiguration childProcessCommandConfiguration)
{
childViewModel = service.Create<WidgetMenuViewModel>(childProcessCommandConfiguration.Id,
childProcessCommandConfiguration.Icon, childProcessCommandConfiguration.Text,
new RelayCommand(async () => await mediator.SendAsync(new StartProcess(childProcessCommandConfiguration.Path))));
}
if (childCommandConfiguration is KeyAcceleratorCommandConfiguration childKeyAcceleratorCommandConfiguration)
{
childViewModel = service.Create<WidgetMenuViewModel>(childKeyAcceleratorCommandConfiguration.Id,
childKeyAcceleratorCommandConfiguration.Text, childKeyAcceleratorCommandConfiguration.Icon,
new RelayCommand(async () =>
await mediator.SendAsync(new KeyAccelerator((VirtualKey)childKeyAcceleratorCommandConfiguration.Key,
childKeyAcceleratorCommandConfiguration.Modifiers?.Select(modifier => (VirtualKey)modifier).ToArray()))));
}
if (childViewModel is not null)
{
childViewModels.Add(childViewModel);
cache.Add(childViewModel.Id, childViewModel);
}
}
viewModel = service.Create<WidgetSplitButtonViewModel>(childViewModels,
processCommandConfiguration.Id, processCommandConfiguration.Text,
processCommandConfiguration.Icon, new RelayCommand(async () =>
await mediator.SendAsync(new StartProcess(processCommandConfiguration.Path))));
}
else
{
viewModel = service.Create<WidgetButtonViewModel>(processCommandConfiguration.Id,
processCommandConfiguration.Text, processCommandConfiguration.Icon, new RelayCommand(async () =>
await mediator.SendAsync(new StartProcess(processCommandConfiguration.Path))));
}
}
if (viewModel is not null)
{
cache.Add(value.Id, viewModel);
cache.Add(viewModel.Id, viewModel);
}
return viewModel;