Add support for self scope
This commit is contained in:
@@ -15,7 +15,10 @@
|
|||||||
ToolTip.Tip="Add item">
|
ToolTip.Tip="Add item">
|
||||||
<Interaction.Behaviors>
|
<Interaction.Behaviors>
|
||||||
<EventTriggerBehavior EventName="Click">
|
<EventTriggerBehavior EventName="Click">
|
||||||
<NavigateAction Context="{Binding Named, StringFormat='{}{0}:Content'}" Route="AddItem" />
|
<NavigateAction
|
||||||
|
Context="{Binding Named, StringFormat='{}{0}:Content'}"
|
||||||
|
Route="AddItem"
|
||||||
|
Scope="self" />
|
||||||
</EventTriggerBehavior>
|
</EventTriggerBehavior>
|
||||||
</Interaction.Behaviors>
|
</Interaction.Behaviors>
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@@ -6,7 +6,10 @@
|
|||||||
x:DataType="vm:AddItemViewModel">
|
x:DataType="vm:AddItemViewModel">
|
||||||
<Interaction.Behaviors>
|
<Interaction.Behaviors>
|
||||||
<EventTriggerBehavior EventName="Loaded">
|
<EventTriggerBehavior EventName="Loaded">
|
||||||
<NavigateAction Context="{Binding Named, StringFormat='{}{0}:ContentHeader'}" Route="AddVaultContentCommandHeader" />
|
<NavigateAction
|
||||||
|
Context="{Binding Named, StringFormat='{}{0}:ContentHeader'}"
|
||||||
|
Route="AddVaultContentCommandHeader"
|
||||||
|
Scope="self" />
|
||||||
</EventTriggerBehavior>
|
</EventTriggerBehavior>
|
||||||
</Interaction.Behaviors>
|
</Interaction.Behaviors>
|
||||||
<ScrollViewer Padding="12,12,12,0">
|
<ScrollViewer Padding="12,12,12,0">
|
||||||
|
|||||||
@@ -49,12 +49,12 @@ public partial class App : Application
|
|||||||
services.AddTransient<ISecurityKeyFactory, SecurityKeyFactory>();
|
services.AddTransient<ISecurityKeyFactory, SecurityKeyFactory>();
|
||||||
services.AddTransient<IContainer, ContainerFactory>();
|
services.AddTransient<IContainer, ContainerFactory>();
|
||||||
services.TryAddSingleton<IContainer<SecurityKey>, Container<SecurityKey>>();
|
services.TryAddSingleton<IContainer<SecurityKey>, Container<SecurityKey>>();
|
||||||
services.TryAddSingleton<IContainer<ContaienrConnection>, Container<ContaienrConnection>>();
|
services.TryAddSingleton<IContainer<ContainerConnection>, Container<ContainerConnection>>();
|
||||||
|
|
||||||
services.AddDbContextFactory<VaultDbContext>((provider, args) =>
|
services.AddDbContextFactory<VaultDbContext>((provider, args) =>
|
||||||
{
|
{
|
||||||
if (provider.GetRequiredService<IContainer<ContaienrConnection>>()
|
if (provider.GetRequiredService<IContainer<ContainerConnection>>()
|
||||||
is IContainer<ContaienrConnection> connection)
|
is IContainer<ContainerConnection> connection)
|
||||||
{
|
{
|
||||||
args.UseSqlite($"{connection.Value}");
|
args.UseSqlite($"{connection.Value}");
|
||||||
}
|
}
|
||||||
@@ -78,12 +78,12 @@ public partial class App : Application
|
|||||||
services.AddTemplate<AddItemActionViewModel, AddItemActionView>();
|
services.AddTemplate<AddItemActionViewModel, AddItemActionView>();
|
||||||
|
|
||||||
services.AddTemplate<ItemNavigationViewModel, ItemNavigationView>();
|
services.AddTemplate<ItemNavigationViewModel, ItemNavigationView>();
|
||||||
services.AddTemplate<ItemViewModel, ItemView>("AddItem");
|
services.AddTemplate<ItemViewModel, ItemView>("Item");
|
||||||
|
|
||||||
services.AddTemplate<AddItemViewModel, AddItemView>("AddAddItem");
|
services.AddTemplate<AddItemViewModel, AddItemView>("AddItem");
|
||||||
services.AddTemplate<AddItemCommandHeaderViewModel, AddItemCommandHeaderView>("AddVaultContentCommandHeader");
|
services.AddTemplate<AddItemCommandHeaderViewModel, AddItemCommandHeaderView>("AddVaultContentCommandHeader");
|
||||||
|
|
||||||
services.AddTemplate<ConfirmItemActionViewModel, ConfirmVaultContentActionView>();
|
services.AddTemplate<ConfirmItemActionViewModel, ConfirmItemActionView>();
|
||||||
services.AddTemplate<DismissItemActionViewModel, DismissItemActionView>();
|
services.AddTemplate<DismissItemActionViewModel, DismissItemActionView>();
|
||||||
|
|
||||||
services.AddTemplate<ItemHeaderViewModel, ItemHeaderView>();
|
services.AddTemplate<ItemHeaderViewModel, ItemHeaderView>();
|
||||||
|
|||||||
@@ -49,6 +49,9 @@
|
|||||||
<Compile Update="AddItemView.axaml.cs">
|
<Compile Update="AddItemView.axaml.cs">
|
||||||
<DependentUpon>AddItemView.axaml</DependentUpon>
|
<DependentUpon>AddItemView.axaml</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Update="ConfirmItemActionView.axaml.cs">
|
||||||
|
<DependentUpon>ConfirmItemActionView.axaml</DependentUpon>
|
||||||
|
</Compile>
|
||||||
<Compile Update="CreateContainerNavigationView.axaml.cs">
|
<Compile Update="CreateContainerNavigationView.axaml.cs">
|
||||||
<DependentUpon>CreateContainerNavigationView.axaml</DependentUpon>
|
<DependentUpon>CreateContainerNavigationView.axaml</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
|||||||
+5
-2
@@ -1,11 +1,14 @@
|
|||||||
<UserControl
|
<UserControl
|
||||||
x:Class="Bitvault.Avalonia.ConfirmVaultContentActionView"
|
x:Class="Bitvault.Avalonia.ConfirmItemActionView"
|
||||||
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"
|
||||||
|
x:DataType="vm:ConfirmItemActionViewModel">
|
||||||
<Button
|
<Button
|
||||||
Width="{StaticResource ButtonWidth}"
|
Width="{StaticResource ButtonWidth}"
|
||||||
Height="{StaticResource ButtonHeight}"
|
Height="{StaticResource ButtonHeight}"
|
||||||
VerticalAlignment="Center"
|
VerticalAlignment="Center"
|
||||||
|
Command="{Binding InvokeCommand}"
|
||||||
Foreground="{DynamicResource IconForegroundBrush}"
|
Foreground="{DynamicResource IconForegroundBrush}"
|
||||||
ToolTip.Tip="Save">
|
ToolTip.Tip="Save">
|
||||||
<TextBlock
|
<TextBlock
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
using Avalonia.Controls;
|
||||||
|
|
||||||
|
namespace Bitvault.Avalonia;
|
||||||
|
|
||||||
|
public partial class ConfirmItemActionView : UserControl
|
||||||
|
{
|
||||||
|
public ConfirmItemActionView() => InitializeComponent();
|
||||||
|
}
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
using Avalonia.Controls;
|
|
||||||
|
|
||||||
namespace Bitvault.Avalonia;
|
|
||||||
|
|
||||||
public partial class ConfirmVaultContentActionView : UserControl
|
|
||||||
{
|
|
||||||
public ConfirmVaultContentActionView() => InitializeComponent();
|
|
||||||
}
|
|
||||||
@@ -8,7 +8,7 @@
|
|||||||
x:DataType="vm:ItemNavigationViewModel">
|
x:DataType="vm:ItemNavigationViewModel">
|
||||||
<Interaction.Behaviors>
|
<Interaction.Behaviors>
|
||||||
<DataTriggerBehavior Binding="{Binding Selected}" Value="True">
|
<DataTriggerBehavior Binding="{Binding Selected}" Value="True">
|
||||||
<NavigateAction Context="{Binding Named, StringFormat='{}{0}:Content'}" Route="AddItem" />
|
<NavigateAction Context="{Binding Named, StringFormat='{}{0}:Content'}" Route="Item" />
|
||||||
</DataTriggerBehavior>
|
</DataTriggerBehavior>
|
||||||
</Interaction.Behaviors>
|
</Interaction.Behaviors>
|
||||||
<Grid ColumnDefinitions="Auto,*">
|
<Grid ColumnDefinitions="Auto,*">
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using CommunityToolkit.Mvvm.ComponentModel;
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
|
using CommunityToolkit.Mvvm.Input;
|
||||||
using Toolkit.Foundation;
|
using Toolkit.Foundation;
|
||||||
|
|
||||||
namespace Bitvault;
|
namespace Bitvault;
|
||||||
@@ -14,4 +15,7 @@ public partial class AddItemActionViewModel(IServiceProvider provider,
|
|||||||
|
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
private string named = $"{named}";
|
private string named = $"{named}";
|
||||||
|
|
||||||
|
[RelayCommand]
|
||||||
|
public async Task Invoke() => await Publisher.Publish(new Test());
|
||||||
}
|
}
|
||||||
@@ -4,7 +4,8 @@ using Toolkit.Foundation;
|
|||||||
namespace Bitvault;
|
namespace Bitvault;
|
||||||
|
|
||||||
public partial class AddItemViewModel :
|
public partial class AddItemViewModel :
|
||||||
ObservableCollectionViewModel<IItemViewModel>
|
ObservableCollectionViewModel<IItemViewModel>,
|
||||||
|
INotificationHandler<Test>
|
||||||
{
|
{
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
private string named;
|
private string named;
|
||||||
@@ -36,4 +37,9 @@ public partial class AddItemViewModel :
|
|||||||
|
|
||||||
return Task.FromResult(true);
|
return Task.FromResult(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Task Handle(Test args, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,17 @@
|
|||||||
using Toolkit.Foundation;
|
using CommunityToolkit.Mvvm.Input;
|
||||||
|
using Toolkit.Foundation;
|
||||||
|
|
||||||
namespace Bitvault;
|
namespace Bitvault;
|
||||||
|
|
||||||
|
public record Test;
|
||||||
|
|
||||||
public partial class ConfirmItemActionViewModel(IServiceProvider provider,
|
public partial class ConfirmItemActionViewModel(IServiceProvider provider,
|
||||||
IServiceFactory factory,
|
IServiceFactory factory,
|
||||||
IMediator mediator,
|
IMediator mediator,
|
||||||
IPublisher publisher,
|
IPublisher publisher,
|
||||||
ISubscriber subscriber,
|
ISubscriber subscriber,
|
||||||
IDisposer disposer) : ObservableViewModel(provider, factory, mediator, publisher, subscriber, disposer);
|
IDisposer disposer) : ObservableViewModel(provider, factory, mediator, publisher, subscriber, disposer)
|
||||||
|
{
|
||||||
|
[RelayCommand]
|
||||||
|
public async Task Invoke() => await Publisher.Publish(new Test());
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
namespace Bitvault;
|
namespace Bitvault;
|
||||||
|
|
||||||
public class ContaienrConnection(string connection)
|
public class ContainerConnection(string connection)
|
||||||
{
|
{
|
||||||
private readonly string connection = connection;
|
private readonly string connection = connection;
|
||||||
|
|
||||||
@@ -6,7 +6,7 @@ using Toolkit.Foundation;
|
|||||||
|
|
||||||
namespace Bitvault;
|
namespace Bitvault;
|
||||||
|
|
||||||
public class ContainerFactory(IContainer<ContaienrConnection> connection,
|
public class ContainerFactory(IContainer<ContainerConnection> connection,
|
||||||
IHostEnvironment environment,
|
IHostEnvironment environment,
|
||||||
IServiceProvider provider) :
|
IServiceProvider provider) :
|
||||||
IContainer
|
IContainer
|
||||||
@@ -14,7 +14,7 @@ public class ContainerFactory(IContainer<ContaienrConnection> connection,
|
|||||||
public async Task<bool> Create(string name,
|
public async Task<bool> Create(string name,
|
||||||
SecurityKey key)
|
SecurityKey key)
|
||||||
{
|
{
|
||||||
connection.Set(new ContaienrConnection($"Data Source={Path.Combine(environment.ContentRootPath, name)}" +
|
connection.Set(new ContainerConnection($"Data Source={Path.Combine(environment.ContentRootPath, name)}" +
|
||||||
$".vault;Mode=ReadWriteCreate;Pooling=false;Password={Convert.ToBase64String(key.DecryptedKey)}"));
|
$".vault;Mode=ReadWriteCreate;Pooling=false;Password={Convert.ToBase64String(key.DecryptedKey)}"));
|
||||||
|
|
||||||
IDbContextFactory<VaultDbContext> dbContextFactory = provider.GetRequiredService<IDbContextFactory<VaultDbContext>>();
|
IDbContextFactory<VaultDbContext> dbContextFactory = provider.GetRequiredService<IDbContextFactory<VaultDbContext>>();
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ public partial class ContainerHeaderViewModel : ObservableCollectionViewModel<st
|
|||||||
{
|
{
|
||||||
Template = template;
|
Template = template;
|
||||||
|
|
||||||
Add<AddItemActionViewModel>();
|
Add<AddItemActionViewModel>(scope: true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IContentTemplate Template { get; set; }
|
public IContentTemplate Template { get; set; }
|
||||||
|
|||||||
@@ -13,7 +13,8 @@ public partial class ItemNavigationViewModel(IServiceProvider provider,
|
|||||||
NamedComponent named,
|
NamedComponent named,
|
||||||
string name,
|
string name,
|
||||||
string description) :
|
string description) :
|
||||||
ObservableViewModel(provider, factory, mediator, publisher, subscriber, disposer)
|
ObservableViewModel(provider, factory, mediator, publisher, subscriber, disposer),
|
||||||
|
INotificationHandler<Test>
|
||||||
{
|
{
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
private string? description = description;
|
private string? description = description;
|
||||||
@@ -27,4 +28,9 @@ public partial class ItemNavigationViewModel(IServiceProvider provider,
|
|||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
private bool selected;
|
private bool selected;
|
||||||
public IContentTemplate Template { get; set; } = template;
|
public IContentTemplate Template { get; set; } = template;
|
||||||
|
|
||||||
|
public Task Handle(Test args, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user