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.AddTemplate<MainWindowViewModel, MainWindow>("MainWindow");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
services.AddSingleton<IVaultHostCollection, VaultHostCollection>();
|
||||||
|
|
||||||
services.AddTemplate<MainViewModel, MainView>("Main");
|
services.AddTemplate<MainViewModel, MainView>("Main");
|
||||||
services.AddHandler<MainViewHandler>();
|
services.AddHandler<MainViewModelHandler>();
|
||||||
|
|
||||||
services.AddTemplate<VaultNavigationViewModel, VaultNavigationView>();
|
services.AddConfiguration<VaultConfiguration>(args => args.Name = "Personal",
|
||||||
services.AddTemplate<AllNavigationViewModel, AllNavigationView>();
|
$"{nameof(VaultConfiguration)}:Personal");
|
||||||
services.AddTemplate<StarredNavigationViewModel, StarredNavigationView>();
|
|
||||||
services.AddTemplate<CategoriesNavigationViewModel, CategoriesNavigationView>();
|
|
||||||
services.AddTemplate<ArchiveNavigationViewModel, ArchiveNavigationView>();
|
|
||||||
|
|
||||||
services.AddTemplate<VaultViewModel, VaultView>("Vault");
|
|
||||||
|
|
||||||
services.AddConfiguration<VaultConfiguration>($"{nameof(VaultConfiguration)}:Personal");
|
|
||||||
})
|
})
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
|
|||||||
@@ -2,14 +2,16 @@
|
|||||||
x:Class="Bitvault.Avalonia.MainWindow"
|
x:Class="Bitvault.Avalonia.MainWindow"
|
||||||
xmlns="https://github.com/avaloniaui"
|
xmlns="https://github.com/avaloniaui"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:vm="using:Bitvault"
|
||||||
xmlns:windowing="using:FluentAvalonia.UI.Windowing"
|
xmlns:windowing="using:FluentAvalonia.UI.Windowing"
|
||||||
|
x:DataType="vm:MainWindowViewModel"
|
||||||
Background="Transparent"
|
Background="Transparent"
|
||||||
TransparencyLevelHint="Mica">
|
TransparencyLevelHint="Mica">
|
||||||
<!--<ContentControl x:Name="Window">
|
<ContentControl x:Name="Window">
|
||||||
<Interaction.Behaviors>
|
<Interaction.Behaviors>
|
||||||
<AttachedBehavior>
|
<AttachedBehavior>
|
||||||
<NavigateAction Context="Window" Route="Main" />
|
<NavigateAction Context="Window" Route="Main" />
|
||||||
</AttachedBehavior>
|
</AttachedBehavior>
|
||||||
</Interaction.Behaviors>
|
</Interaction.Behaviors>
|
||||||
</ContentControl>-->
|
</ContentControl>
|
||||||
</windowing:AppWindow>
|
</windowing:AppWindow>
|
||||||
|
|||||||
@@ -10,5 +10,6 @@ public partial class MainWindow : AppWindow
|
|||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
TitleBar.ExtendsContentIntoTitleBar = true;
|
TitleBar.ExtendsContentIntoTitleBar = true;
|
||||||
|
TitleBar.TitleBarHitTestType = TitleBarHitTestType.Complex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,12 @@ public class VaultComponent :
|
|||||||
ComponentBuilder.Create()
|
ComponentBuilder.Create()
|
||||||
.AddServices(services =>
|
.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:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:vm="using:Bitvault"
|
xmlns:vm="using:Bitvault"
|
||||||
x:DataType="vm:VaultNavigationViewModel"
|
x:DataType="vm:VaultNavigationViewModel"
|
||||||
Content="Test"
|
Content="{Binding Name}"
|
||||||
MenuItemsSource="{Binding}" />
|
MenuItemsSource="{Binding}" />
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
namespace Bitvault;
|
namespace Bitvault;
|
||||||
|
|
||||||
public interface IMainNavigationViewModel;
|
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;
|
namespace Bitvault;
|
||||||
|
|
||||||
|
[Notification(nameof(MainViewModel))]
|
||||||
public partial class MainViewModel :
|
public partial class MainViewModel :
|
||||||
ObservableCollectionViewModel<IMainNavigationViewModel>
|
ObservableCollectionViewModel<IMainNavigationViewModel>
|
||||||
{
|
{
|
||||||
@@ -13,7 +14,6 @@ public partial class MainViewModel :
|
|||||||
IContentTemplate template) : base(serviceProvider, serviceFactory, publisher, subscriber, disposer)
|
IContentTemplate template) : base(serviceProvider, serviceFactory, publisher, subscriber, disposer)
|
||||||
{
|
{
|
||||||
Template = template;
|
Template = template;
|
||||||
Add<VaultNavigationViewModel>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public IContentTemplate Template { get; set; }
|
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,
|
public class VaultComponentsInitializer(IServiceProvider provider,
|
||||||
IProxyServiceCollection<IComponentBuilder> proxy,
|
IProxyServiceCollection<IComponentBuilder> proxy,
|
||||||
IEnumerable<IConfiguration<VaultConfiguration>> configurations) : IInitializer
|
IEnumerable<IConfiguration<VaultConfiguration>> configurations,
|
||||||
|
IVaultHostCollection vaults) : IInitializer
|
||||||
{
|
{
|
||||||
public Task Initialize()
|
public Task Initialize()
|
||||||
{
|
{
|
||||||
@@ -37,10 +38,11 @@ public class VaultComponentsInitializer(IServiceProvider provider,
|
|||||||
services.AddRange(proxy.Services);
|
services.AddRange(proxy.Services);
|
||||||
});
|
});
|
||||||
|
|
||||||
builder.AddConfiguration<VaultConfiguration>(configuration.Section);
|
builder.AddConfiguration(configuration.Section, configuration.Value);
|
||||||
|
|
||||||
IComponentHost host = builder.Build();
|
IComponentHost host = builder.Build();
|
||||||
host.StartAsync();
|
host.StartAsync();
|
||||||
|
|
||||||
|
vaults.Add(host);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
using System.Text.Json.Serialization;
|
using Toolkit.Foundation;
|
||||||
using Toolkit.Foundation;
|
|
||||||
|
|
||||||
namespace Bitvault;
|
namespace Bitvault;
|
||||||
|
|
||||||
public record VaultConfiguration : ComponentConfiguration
|
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;
|
namespace Bitvault;
|
||||||
|
|
||||||
@@ -6,14 +7,19 @@ public partial class VaultNavigationViewModel :
|
|||||||
ObservableCollectionViewModel<IMainNavigationViewModel>,
|
ObservableCollectionViewModel<IMainNavigationViewModel>,
|
||||||
IMainNavigationViewModel
|
IMainNavigationViewModel
|
||||||
{
|
{
|
||||||
|
[ObservableProperty]
|
||||||
|
private string name;
|
||||||
|
|
||||||
public VaultNavigationViewModel(IServiceProvider serviceProvider,
|
public VaultNavigationViewModel(IServiceProvider serviceProvider,
|
||||||
IServiceFactory serviceFactory,
|
IServiceFactory serviceFactory,
|
||||||
IPublisher publisher,
|
IPublisher publisher,
|
||||||
ISubscriber subscriber,
|
ISubscriber subscriber,
|
||||||
IDisposer disposer,
|
IDisposer disposer,
|
||||||
IContentTemplate template) : base(serviceProvider, serviceFactory, publisher, subscriber, disposer)
|
IContentTemplate template,
|
||||||
|
string name) : base(serviceProvider, serviceFactory, publisher, subscriber, disposer)
|
||||||
{
|
{
|
||||||
Template = template;
|
Template = template;
|
||||||
|
Name = name;
|
||||||
|
|
||||||
Add<AllNavigationViewModel>();
|
Add<AllNavigationViewModel>();
|
||||||
Add<StarredNavigationViewModel>();
|
Add<StarredNavigationViewModel>();
|
||||||
|
|||||||
Reference in New Issue
Block a user