wip..
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
|
||||
namespace Hyperbar.UI.Windows;
|
||||
|
||||
public class ContentControlHandler(IViewModelContentBinder viewModelContentBinder) :
|
||||
INavigationHandler<ContentControl>
|
||||
{
|
||||
public Task Handle(Navigate<ContentControl> args,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
if (args.Target is ContentControl contentControl)
|
||||
{
|
||||
contentControl.Content = args.View;
|
||||
contentControl.DataContext = args.ViewModel;
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
@@ -1,23 +1,7 @@
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
|
||||
namespace Hyperbar.UI.Windows;
|
||||
|
||||
public class ContentControlHandler(IViewModelContentBinder viewModelContentBinder) :
|
||||
INavigationHandler<ContentControl>
|
||||
{
|
||||
public Task Handle(Navigate<ContentControl> args,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
if (args.Target is ContentControl contentControl)
|
||||
{
|
||||
contentControl.Content = args.View;
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
|
||||
public class WindowHandler(IViewModelContentBinder viewModelContentBinder) :
|
||||
INavigationHandler<Window>
|
||||
{
|
||||
|
||||
@@ -8,9 +8,9 @@
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<None Remove="WidgetConfigurationNavigationView.xaml" />
|
||||
<None Remove="WidgetConfigurationView.xaml" />
|
||||
<None Remove="WidgetNavigationView.xaml" />
|
||||
<None Remove="WidgetSettingsNavigationView.xaml" />
|
||||
<None Remove="WidgetSettingsView.xaml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.5.240124002-experimental2" />
|
||||
@@ -24,7 +24,7 @@
|
||||
<ProjectReference Include="..\Hyperbar\Hyperbar.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Page Update="WidgetSettingsNavigationView.xaml">
|
||||
<Page Update="WidgetConfigurationNavigationView.xaml">
|
||||
<XamlRuntime>$(DefaultXamlRuntime)</XamlRuntime>
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
@@ -32,7 +32,7 @@
|
||||
<XamlRuntime>$(DefaultXamlRuntime)</XamlRuntime>
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
<Page Update="WidgetSettingsView.xaml">
|
||||
<Page Update="WidgetConfigurationView.xaml">
|
||||
<XamlRuntime>$(DefaultXamlRuntime)</XamlRuntime>
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
|
||||
@@ -36,8 +36,8 @@ public static class IServiceCollectionExtensions
|
||||
services.AddContentTemplate<WidgetButtonViewModel, WidgetButtonView>();
|
||||
services.AddContentTemplate<WidgetSplitButtonViewModel, WidgetSplitButtonView>();
|
||||
|
||||
services.AddContentTemplate<WidgetSettingsNavigationViewModel, WidgetSettingsNavigationView>();
|
||||
services.AddContentTemplate<WidgetSettingsViewModel, WidgetSettingsView>("WidgetSettings");
|
||||
services.AddContentTemplate<WidgetConfigurationNavigationViewModel, WidgetConfigurationNavigationView>();
|
||||
services.AddContentTemplate<WidgetConfigurationViewModel, WidgetConfigurationView>("WidgetSettings");
|
||||
})));
|
||||
|
||||
return services;
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<NavigationViewItem
|
||||
x:Class="Hyperbar.Widget.Windows.WidgetSettingsNavigationView"
|
||||
x:Class="Hyperbar.Widget.Windows.WidgetConfigurationNavigationView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:interactions="using:Microsoft.Xaml.Interactions.Core"
|
||||
+2
-2
@@ -2,9 +2,9 @@ using Microsoft.UI.Xaml.Controls;
|
||||
|
||||
namespace Hyperbar.Widget.Windows;
|
||||
|
||||
public sealed partial class WidgetSettingsNavigationView :
|
||||
public sealed partial class WidgetConfigurationNavigationView :
|
||||
NavigationViewItem
|
||||
{
|
||||
public WidgetSettingsNavigationView() =>
|
||||
public WidgetConfigurationNavigationView() =>
|
||||
InitializeComponent();
|
||||
}
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
namespace Hyperbar.Widget.Windows;
|
||||
|
||||
public class WidgetSettingsNavigationViewModel(IServiceProvider serviceProvider,
|
||||
public class WidgetConfigurationNavigationViewModel(IServiceProvider serviceProvider,
|
||||
IServiceFactory serviceFactory,
|
||||
IPublisher publisher,
|
||||
ISubscriber subscriber,
|
||||
+5
-5
@@ -2,19 +2,19 @@
|
||||
|
||||
namespace Hyperbar.Widget.Windows;
|
||||
|
||||
public class WidgetSettingsNavigationViewModelEnumerator(IPublisher publisher,
|
||||
public class WidgetConfigurationNavigationViewModelEnumerator(IPublisher publisher,
|
||||
IWidgetHostCollection widgetHosts) :
|
||||
INotificationHandler<Enumerate<WidgetSettingsNavigationViewModel>>
|
||||
INotificationHandler<Enumerate<WidgetConfigurationNavigationViewModel>>
|
||||
{
|
||||
public async Task Handle(Enumerate<WidgetSettingsNavigationViewModel> args,
|
||||
public async Task Handle(Enumerate<WidgetConfigurationNavigationViewModel> args,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
foreach (IWidgetHost host in widgetHosts)
|
||||
{
|
||||
if (host.Services.GetService<IServiceFactory>() is IServiceFactory serviceFactory)
|
||||
{
|
||||
await publisher.PublishAsync(new Create<WidgetSettingsNavigationViewModel>(serviceFactory
|
||||
.Create<WidgetSettingsNavigationViewModel>(host.Configuration.Name)),
|
||||
await publisher.PublishAsync(new Create<WidgetConfigurationNavigationViewModel>(serviceFactory
|
||||
.Create<WidgetConfigurationNavigationViewModel>(host.Configuration.Name)),
|
||||
nameof(WidgetNavigationViewModel), cancellationToken);
|
||||
}
|
||||
}
|
||||
+2
-4
@@ -1,9 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<UserControl
|
||||
x:Class="Hyperbar.Widget.Windows.WidgetSettingsView"
|
||||
x:Class="Hyperbar.Widget.Windows.WidgetConfigurationView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||
<Grid>
|
||||
<Button>Test</Button>
|
||||
</Grid>
|
||||
<ListBox ItemsSource="{Binding Mode=TwoWay}" />
|
||||
</UserControl>
|
||||
@@ -0,0 +1,12 @@
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
|
||||
namespace Hyperbar.Widget.Windows;
|
||||
|
||||
public partial class WidgetConfigurationView : UserControl
|
||||
{
|
||||
public WidgetConfigurationView() =>
|
||||
InitializeComponent();
|
||||
|
||||
protected WidgetConfigurationViewModel ViewModel =>
|
||||
(WidgetConfigurationViewModel)DataContext;
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
using Hyperbar.UI.Windows;
|
||||
|
||||
namespace Hyperbar.Widget.Windows;
|
||||
|
||||
public class WidgetConfigurationViewModel<TConfiguration, TValue> :
|
||||
ValueViewModel<TValue>,
|
||||
INotificationHandler<Changed<TConfiguration>>
|
||||
where TConfiguration :
|
||||
class
|
||||
{
|
||||
private readonly Func<TConfiguration, TValue> valueFactory;
|
||||
|
||||
public WidgetConfigurationViewModel(IServiceProvider serviceProvider,
|
||||
IServiceFactory serviceFactory,
|
||||
IPublisher publisher,
|
||||
IDisposer disposer,
|
||||
Func<TConfiguration, TValue> valueFactory) : base(serviceProvider, serviceFactory, publisher, disposer)
|
||||
{
|
||||
this.valueFactory = valueFactory;
|
||||
}
|
||||
|
||||
public Task Handle(Changed<TConfiguration> args,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (args.Value is TConfiguration configuration)
|
||||
{
|
||||
valueFactory.Invoke(configuration);
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
|
||||
public class WidgetConfigurationViewModel :
|
||||
ObservableCollectionViewModel<IObservableViewModel>
|
||||
{
|
||||
public WidgetConfigurationViewModel(IViewModelTemplateSelector viewModelTemplateSelector,
|
||||
IServiceProvider serviceProvider,
|
||||
IServiceFactory serviceFactory,
|
||||
IPublisher publisher,
|
||||
ISubscriber subscriber,
|
||||
IDisposer disposer) : base(serviceProvider, serviceFactory, publisher, subscriber, disposer)
|
||||
{
|
||||
ViewModelTemplateSelector = viewModelTemplateSelector;
|
||||
|
||||
Add<WidgetConfigurationViewModel<WidgetAvailability,
|
||||
bool>>((Func<WidgetAvailability, bool>)(config => config.Value));
|
||||
}
|
||||
|
||||
public IViewModelTemplateSelector ViewModelTemplateSelector { get; }
|
||||
}
|
||||
@@ -10,7 +10,7 @@ public class WidgetNavigationViewModel(IViewModelTemplateSelector viewModelTempl
|
||||
ISubscriber subscriber,
|
||||
IDisposer disposer,
|
||||
string text) :
|
||||
NavigationViewModel<WidgetSettingsNavigationViewModel>(serviceProvider, serviceFactory, publisher, subscriber, disposer, text)
|
||||
NavigationViewModel<WidgetConfigurationNavigationViewModel>(serviceProvider, serviceFactory, publisher, subscriber, disposer, text)
|
||||
{
|
||||
public IViewModelTemplateSelector ViewModelTemplateSelector => viewModelTemplateSelector;
|
||||
}
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
|
||||
namespace Hyperbar.Widget.Windows;
|
||||
|
||||
public partial class WidgetSettingsView : UserControl
|
||||
{
|
||||
public WidgetSettingsView() =>
|
||||
InitializeComponent();
|
||||
|
||||
protected WidgetSettingsViewModel ViewModel =>
|
||||
(WidgetSettingsViewModel)DataContext;
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
using Hyperbar.UI.Windows;
|
||||
|
||||
namespace Hyperbar.Widget.Windows;
|
||||
|
||||
public class WidgetSettingsViewModel(IViewModelTemplateSelector viewModelTemplateSelector,
|
||||
IServiceProvider serviceProvider,
|
||||
IServiceFactory serviceFactory,
|
||||
IPublisher publisher,
|
||||
ISubscriber subscriber,
|
||||
IDisposer disposer) :
|
||||
ObservableCollectionViewModel<IObservableViewModel>(serviceProvider, serviceFactory, publisher, subscriber, disposer)
|
||||
{
|
||||
public IViewModelTemplateSelector ViewModelTemplateSelector => viewModelTemplateSelector;
|
||||
}
|
||||
@@ -5,7 +5,6 @@
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:interactions="using:Microsoft.Xaml.Interactions.Core"
|
||||
xmlns:interactivity="using:Microsoft.Xaml.Interactivity">
|
||||
<Grid>
|
||||
<ItemsControl ItemTemplateSelector="{Binding ViewModelTemplateSelector}" ItemsSource="{Binding Mode=TwoWay}">
|
||||
<ItemsControl.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
@@ -23,5 +22,4 @@
|
||||
</interactions:EventTriggerBehavior>
|
||||
</interactivity:Interaction.Behaviors>
|
||||
</ItemsControl>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -42,7 +42,7 @@ public class WidgetBuilder :
|
||||
services.AddSingleton<IDisposer, Disposer>();
|
||||
|
||||
services.AddHandler<WidgetAvailabilityChangedHandler>();
|
||||
services.AddValueChangedNotification<WidgetConfiguration,
|
||||
services.AddConfigurationChanged<WidgetConfiguration,
|
||||
WidgetAvailability>((config) => (args) =>
|
||||
{
|
||||
args.Value = config.IsEnabled;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace Hyperbar.Widget;
|
||||
|
||||
public class WidgetConfigurationHandler(IEnumerable<IConfigurationValueChangedNotification<WidgetConfiguration>>
|
||||
public class WidgetConfigurationHandler(IEnumerable<IConfigurationChangedPublisher<WidgetConfiguration>>
|
||||
configurationValueChangedNotifications) :
|
||||
INotificationHandler<Changed<WidgetConfiguration>>
|
||||
{
|
||||
@@ -9,7 +9,7 @@ public class WidgetConfigurationHandler(IEnumerable<IConfigurationValueChangedNo
|
||||
{
|
||||
if (args.Value is WidgetConfiguration configuration)
|
||||
{
|
||||
foreach (IConfigurationValueChangedNotification<WidgetConfiguration> notification in
|
||||
foreach (IConfigurationChangedPublisher<WidgetConfiguration> notification in
|
||||
configurationValueChangedNotifications)
|
||||
{
|
||||
await notification.PublishAsync(configuration);
|
||||
|
||||
@@ -63,7 +63,7 @@ public partial class App :
|
||||
services.AddContentTemplate<GeneralSettingsNavigationViewModel, GeneralSettingsNavigationView>();
|
||||
services.AddContentTemplate<WidgetNavigationViewModel, WidgetNavigationView>();
|
||||
|
||||
services.AddHandler<WidgetSettingsNavigationViewModelEnumerator>();
|
||||
services.AddHandler<WidgetConfigurationNavigationViewModelEnumerator>();
|
||||
services.AddTransient<IInitializer, AppInitializer>();
|
||||
})
|
||||
.Build();
|
||||
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
namespace Hyperbar;
|
||||
|
||||
public class ConfigurationValueChangedNotification<TConfiguration, TValue>(IPublisher publisher,
|
||||
public class ConfigurationChangedPublisher<TConfiguration, TValue>(IPublisher publisher,
|
||||
Func<TConfiguration, Action<TValue>> factory) :
|
||||
IConfigurationValueChangedNotification<TConfiguration>
|
||||
IConfigurationChangedPublisher<TConfiguration>
|
||||
where TConfiguration :
|
||||
class
|
||||
where TValue :
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
namespace Hyperbar;
|
||||
|
||||
public interface IConfigurationValueChangedNotification<TConfiguration>
|
||||
public interface IConfigurationChangedPublisher<TConfiguration>
|
||||
{
|
||||
Task PublishAsync(TConfiguration configuration);
|
||||
}
|
||||
@@ -10,15 +10,15 @@ namespace Hyperbar;
|
||||
|
||||
public static class IServiceCollectionExtensions
|
||||
{
|
||||
public static IServiceCollection AddValueChangedNotification<TConfiguration, TValue>(this IServiceCollection services,
|
||||
public static IServiceCollection AddConfigurationChanged<TConfiguration, TValue>(this IServiceCollection services,
|
||||
Func<TConfiguration, Action<TValue>> factory)
|
||||
where TConfiguration :
|
||||
class
|
||||
where TValue :
|
||||
class, new()
|
||||
{
|
||||
services.AddSingleton<IConfigurationValueChangedNotification<TConfiguration>>(provider =>
|
||||
new ConfigurationValueChangedNotification<TConfiguration, TValue>(provider.GetRequiredService<IPublisher>(),
|
||||
services.AddSingleton<IConfigurationChangedPublisher<TConfiguration>>(provider =>
|
||||
new ConfigurationChangedPublisher<TConfiguration, TValue>(provider.GetRequiredService<IPublisher>(),
|
||||
factory));
|
||||
|
||||
return services;
|
||||
|
||||
@@ -7,7 +7,6 @@ using System.Reactive.Disposables;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace Hyperbar;
|
||||
|
||||
public partial class ObservableCollectionViewModel<TViewModel> :
|
||||
ObservableObject,
|
||||
IObservableCollectionViewModel<TViewModel>,
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace Hyperbar;
|
||||
|
||||
public partial class ValueViewModel<TValue>(IServiceProvider serviceProvider,
|
||||
IServiceFactory serviceFactory,
|
||||
IPublisher publisher,
|
||||
IDisposer disposer) :
|
||||
ObservableViewModel(serviceProvider, serviceFactory, publisher, disposer)
|
||||
{
|
||||
public TValue? Value { get; set; }
|
||||
}
|
||||
Reference in New Issue
Block a user