get vaults rendering on the screen
This commit is contained in:
@@ -31,18 +31,13 @@ public partial class App : Application
|
||||
services.AddTemplate<MainWindowViewModel, MainWindow>("MainWindow");
|
||||
}
|
||||
|
||||
services.AddSingleton<IVaultHostCollection, VaultHostCollection>();
|
||||
|
||||
services.AddTemplate<MainViewModel, MainView>("Main");
|
||||
services.AddHandler<MainViewHandler>();
|
||||
services.AddHandler<MainViewModelHandler>();
|
||||
|
||||
services.AddTemplate<VaultNavigationViewModel, VaultNavigationView>();
|
||||
services.AddTemplate<AllNavigationViewModel, AllNavigationView>();
|
||||
services.AddTemplate<StarredNavigationViewModel, StarredNavigationView>();
|
||||
services.AddTemplate<CategoriesNavigationViewModel, CategoriesNavigationView>();
|
||||
services.AddTemplate<ArchiveNavigationViewModel, ArchiveNavigationView>();
|
||||
|
||||
services.AddTemplate<VaultViewModel, VaultView>("Vault");
|
||||
|
||||
services.AddConfiguration<VaultConfiguration>($"{nameof(VaultConfiguration)}:Personal");
|
||||
services.AddConfiguration<VaultConfiguration>(args => args.Name = "Personal",
|
||||
$"{nameof(VaultConfiguration)}:Personal");
|
||||
})
|
||||
.Build();
|
||||
|
||||
|
||||
@@ -2,14 +2,16 @@
|
||||
x:Class="Bitvault.Avalonia.MainWindow"
|
||||
xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:vm="using:Bitvault"
|
||||
xmlns:windowing="using:FluentAvalonia.UI.Windowing"
|
||||
x:DataType="vm:MainWindowViewModel"
|
||||
Background="Transparent"
|
||||
TransparencyLevelHint="Mica">
|
||||
<!--<ContentControl x:Name="Window">
|
||||
TransparencyLevelHint="Mica">
|
||||
<ContentControl x:Name="Window">
|
||||
<Interaction.Behaviors>
|
||||
<AttachedBehavior>
|
||||
<NavigateAction Context="Window" Route="Main" />
|
||||
</AttachedBehavior>
|
||||
</Interaction.Behaviors>
|
||||
</ContentControl>-->
|
||||
</ContentControl>
|
||||
</windowing:AppWindow>
|
||||
|
||||
@@ -10,5 +10,6 @@ public partial class MainWindow : AppWindow
|
||||
{
|
||||
InitializeComponent();
|
||||
TitleBar.ExtendsContentIntoTitleBar = true;
|
||||
TitleBar.TitleBarHitTestType = TitleBarHitTestType.Complex;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,12 @@ public class VaultComponent :
|
||||
ComponentBuilder.Create()
|
||||
.AddServices(services =>
|
||||
{
|
||||
|
||||
services.AddTemplate<VaultNavigationViewModel, VaultNavigationView>();
|
||||
services.AddTemplate<AllNavigationViewModel, AllNavigationView>();
|
||||
services.AddTemplate<StarredNavigationViewModel, StarredNavigationView>();
|
||||
services.AddTemplate<CategoriesNavigationViewModel, CategoriesNavigationView>();
|
||||
services.AddTemplate<ArchiveNavigationViewModel, ArchiveNavigationView>();
|
||||
|
||||
services.AddTemplate<VaultViewModel, VaultView>("Vault");
|
||||
});
|
||||
}
|
||||
|
||||
@@ -4,5 +4,5 @@
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:vm="using:Bitvault"
|
||||
x:DataType="vm:VaultNavigationViewModel"
|
||||
Content="Test"
|
||||
Content="{Binding Name}"
|
||||
MenuItemsSource="{Binding}" />
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
namespace Bitvault;
|
||||
|
||||
public interface IMainNavigationViewModel;
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public interface IVaultHostCollection :
|
||||
IEnumerable<IComponentHost>
|
||||
{
|
||||
void Add(IComponentHost host);
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public class MainViewHandler(IPublisher publisher,
|
||||
IServiceFactory factory) :
|
||||
INotificationHandler<Enumerate<IMainNavigationViewModel>>
|
||||
{
|
||||
public async Task Handle(Enumerate<IMainNavigationViewModel> args,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
[Notification(nameof(MainViewModel))]
|
||||
public partial class MainViewModel :
|
||||
ObservableCollectionViewModel<IMainNavigationViewModel>
|
||||
{
|
||||
@@ -13,7 +14,6 @@ public partial class MainViewModel :
|
||||
IContentTemplate template) : base(serviceProvider, serviceFactory, publisher, subscriber, disposer)
|
||||
{
|
||||
Template = template;
|
||||
Add<VaultNavigationViewModel>();
|
||||
}
|
||||
|
||||
public IContentTemplate Template { get; set; }
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public class MainViewModelHandler(IPublisher publisher,
|
||||
IVaultHostCollection vaults) :
|
||||
INotificationHandler<Enumerate<IMainNavigationViewModel>>
|
||||
{
|
||||
public async Task Handle(Enumerate<IMainNavigationViewModel> args,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
foreach (IComponentHost vault in vaults)
|
||||
{
|
||||
if (vault.Services.GetRequiredService<VaultConfiguration>() is VaultConfiguration configuration)
|
||||
{
|
||||
if (vault.Services.GetRequiredService<IServiceFactory>() is IServiceFactory factory)
|
||||
{
|
||||
if (factory.Create<VaultNavigationViewModel>(configuration.Name) is VaultNavigationViewModel viewModel)
|
||||
{
|
||||
await publisher.Publish(new Create<IMainNavigationViewModel>(viewModel),
|
||||
nameof(MainViewModel), cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,8 @@ namespace Bitvault;
|
||||
|
||||
public class VaultComponentsInitializer(IServiceProvider provider,
|
||||
IProxyServiceCollection<IComponentBuilder> proxy,
|
||||
IEnumerable<IConfiguration<VaultConfiguration>> configurations) : IInitializer
|
||||
IEnumerable<IConfiguration<VaultConfiguration>> configurations,
|
||||
IVaultHostCollection vaults) : IInitializer
|
||||
{
|
||||
public Task Initialize()
|
||||
{
|
||||
@@ -37,10 +38,11 @@ public class VaultComponentsInitializer(IServiceProvider provider,
|
||||
services.AddRange(proxy.Services);
|
||||
});
|
||||
|
||||
builder.AddConfiguration<VaultConfiguration>(configuration.Section);
|
||||
|
||||
builder.AddConfiguration(configuration.Section, configuration.Value);
|
||||
IComponentHost host = builder.Build();
|
||||
host.StartAsync();
|
||||
|
||||
vaults.Add(host);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
using System.Text.Json.Serialization;
|
||||
using Toolkit.Foundation;
|
||||
using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public record VaultConfiguration : ComponentConfiguration
|
||||
{
|
||||
|
||||
public string? Name { get; set; }
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
using System.Collections;
|
||||
using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public class VaultHostCollection :
|
||||
IVaultHostCollection
|
||||
|
||||
{
|
||||
private readonly List<IComponentHost> hosts = [];
|
||||
|
||||
public void Add(IComponentHost host)
|
||||
{
|
||||
hosts.Add(host);
|
||||
}
|
||||
|
||||
public IEnumerator<IComponentHost> GetEnumerator() =>
|
||||
hosts.GetEnumerator();
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator() =>
|
||||
hosts.GetEnumerator();
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using Toolkit.Foundation;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
@@ -6,14 +7,19 @@ public partial class VaultNavigationViewModel :
|
||||
ObservableCollectionViewModel<IMainNavigationViewModel>,
|
||||
IMainNavigationViewModel
|
||||
{
|
||||
[ObservableProperty]
|
||||
private string name;
|
||||
|
||||
public VaultNavigationViewModel(IServiceProvider serviceProvider,
|
||||
IServiceFactory serviceFactory,
|
||||
IServiceFactory serviceFactory,
|
||||
IPublisher publisher,
|
||||
ISubscriber subscriber,
|
||||
IDisposer disposer,
|
||||
IContentTemplate template) : base(serviceProvider, serviceFactory, publisher, subscriber, disposer)
|
||||
IContentTemplate template,
|
||||
string name) : base(serviceProvider, serviceFactory, publisher, subscriber, disposer)
|
||||
{
|
||||
Template = template;
|
||||
Name = name;
|
||||
|
||||
Add<AllNavigationViewModel>();
|
||||
Add<StarredNavigationViewModel>();
|
||||
|
||||
Reference in New Issue
Block a user