Improve vault navifaiton
This commit is contained in:
@@ -8,7 +8,14 @@
|
||||
IsSelected="{Binding Selected, Mode=TwoWay}">
|
||||
<Interaction.Behaviors>
|
||||
<DataTriggerBehavior Binding="{Binding Selected}" Value="True">
|
||||
<InvokeCommandAction Command="{Binding InvokeCommand}" />
|
||||
<ConditionAction>
|
||||
<ConditionAction.Condition>
|
||||
<ConditionalExpression ForwardChaining="And">
|
||||
<ComparisonCondition LeftOperand="{Binding Activated}" RightOperand="False" />
|
||||
</ConditionalExpression>
|
||||
</ConditionAction.Condition>
|
||||
<NavigateAction Context="Main" Route="Vault" />
|
||||
</ConditionAction>
|
||||
</DataTriggerBehavior>
|
||||
</Interaction.Behaviors>
|
||||
</NavigationViewItem>
|
||||
|
||||
@@ -8,7 +8,14 @@
|
||||
IsSelected="{Binding Selected, Mode=TwoWay}">
|
||||
<Interaction.Behaviors>
|
||||
<DataTriggerBehavior Binding="{Binding Selected}" Value="True">
|
||||
<InvokeCommandAction Command="{Binding InvokeCommand}" />
|
||||
<ConditionAction>
|
||||
<ConditionAction.Condition>
|
||||
<ConditionalExpression ForwardChaining="And">
|
||||
<ComparisonCondition LeftOperand="{Binding Activated}" RightOperand="False" />
|
||||
</ConditionalExpression>
|
||||
</ConditionAction.Condition>
|
||||
<NavigateAction Context="Main" Route="Vault" />
|
||||
</ConditionAction>
|
||||
</DataTriggerBehavior>
|
||||
</Interaction.Behaviors>
|
||||
</NavigationViewItem>
|
||||
|
||||
@@ -8,7 +8,14 @@
|
||||
IsSelected="{Binding Selected, Mode=TwoWay}">
|
||||
<Interaction.Behaviors>
|
||||
<DataTriggerBehavior Binding="{Binding Selected}" Value="True">
|
||||
<InvokeCommandAction Command="{Binding InvokeCommand}" />
|
||||
<ConditionAction>
|
||||
<ConditionAction.Condition>
|
||||
<ConditionalExpression ForwardChaining="And">
|
||||
<ComparisonCondition LeftOperand="{Binding Activated}" RightOperand="False" />
|
||||
</ConditionalExpression>
|
||||
</ConditionAction.Condition>
|
||||
<NavigateAction Context="Main" Route="Vault" />
|
||||
</ConditionAction>
|
||||
</DataTriggerBehavior>
|
||||
</Interaction.Behaviors>
|
||||
</NavigationViewItem>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
x:Name="NavigationViewItem"
|
||||
x:DataType="vm:VaultNavigationViewModel"
|
||||
Content="{Binding Name}"
|
||||
IsExpanded="{Binding Expanded, Mode=TwoWay}"
|
||||
IsExpanded="{Binding Expanded}"
|
||||
IsSelected="{Binding Selected}"
|
||||
MenuItemsSource="{Binding}"
|
||||
NavigationViewItemExtension.IsItemClickEnabled="True"
|
||||
@@ -38,7 +38,7 @@
|
||||
PropertyName="SelectsOnInvoked"
|
||||
TargetObject="{Binding #NavigationViewItem}"
|
||||
Value="False" />
|
||||
<SelectNavigationViewItemAction />
|
||||
<InvokeNavigationViewItemAction />
|
||||
</ConditionAction>
|
||||
</DataTriggerBehavior>
|
||||
<AttachedEventTriggerBehaviour RoutedEvent="{x:Static NavigationViewItemExtension.ItemClickEvent}">
|
||||
@@ -46,7 +46,6 @@
|
||||
<ConditionAction.Condition>
|
||||
<ConditionalExpression ForwardChaining="And">
|
||||
<ComparisonCondition LeftOperand="{Binding Opened}" RightOperand="False" />
|
||||
<ComparisonCondition LeftOperand="{Binding #NavigationViewItem.IsChildSelected}" RightOperand="False" />
|
||||
</ConditionalExpression>
|
||||
</ConditionAction.Condition>
|
||||
<NavigateAction Context="Main" Route="OpenVault" />
|
||||
@@ -55,11 +54,11 @@
|
||||
<ConditionAction.Condition>
|
||||
<ConditionalExpression ForwardChaining="And">
|
||||
<ComparisonCondition LeftOperand="{Binding Opened}" RightOperand="True" />
|
||||
<ComparisonCondition LeftOperand="{Binding #NavigationViewItem.IsChildSelected}" RightOperand="False" />
|
||||
<ComparisonCondition LeftOperand="{Binding Activated}" RightOperand="False" />
|
||||
</ConditionalExpression>
|
||||
</ConditionAction.Condition>
|
||||
<NavigateAction Context="Main" Route="Vault" />
|
||||
<SelectNavigationViewItemAction />
|
||||
<InvokeNavigationViewItemAction />
|
||||
</ConditionAction>
|
||||
</AttachedEventTriggerBehaviour>
|
||||
</Interaction.Behaviors>
|
||||
|
||||
@@ -35,13 +35,5 @@
|
||||
ItemTemplate="{ReflectionBinding Template}"
|
||||
ItemsSource="{Binding}" />
|
||||
</Grid>
|
||||
<GridSplitter Grid.Column="1" Background="Transparent" />
|
||||
<Rectangle
|
||||
Grid.Column="1"
|
||||
Width="1"
|
||||
HorizontalAlignment="Center"
|
||||
Fill="{DynamicResource DividerStrokeColorDefaultBrush}"
|
||||
IsHitTestVisible="False" />
|
||||
<Frame Grid.Row="1" Grid.Column="2" />
|
||||
</Grid>
|
||||
</UserControl>
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using Toolkit.Foundation;
|
||||
using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
@@ -9,13 +7,5 @@ public partial class AllNavigationViewModel(IServiceProvider provider,
|
||||
IMediator mediator,
|
||||
IPublisher publisher,
|
||||
ISubscriber subscriber,
|
||||
IDisposer disposer) :
|
||||
ObservableViewModel(provider, factory, mediator, publisher, subscriber, disposer),
|
||||
IVaultNavigationViewModel
|
||||
{
|
||||
[ObservableProperty]
|
||||
private bool selected;
|
||||
|
||||
[RelayCommand]
|
||||
public void Invoke() => Publisher.Publish(Changed.As(new VaultCategory("All")));
|
||||
}
|
||||
IDisposer disposer,
|
||||
string name) : FilterVaultNavigationViewModel(provider, factory, mediator, publisher, subscriber, disposer, name);
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using Toolkit.Foundation;
|
||||
using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
@@ -9,13 +7,5 @@ public partial class ArchiveNavigationViewModel(IServiceProvider provider,
|
||||
IMediator mediator,
|
||||
IPublisher publisher,
|
||||
ISubscriber subscriber,
|
||||
IDisposer disposer) :
|
||||
ObservableViewModel(provider, factory, mediator, publisher, subscriber, disposer),
|
||||
IVaultNavigationViewModel
|
||||
{
|
||||
[ObservableProperty]
|
||||
private bool selected;
|
||||
|
||||
[RelayCommand]
|
||||
public void Invoke() => Publisher.Publish(Changed.As(new VaultCategory("Archive")));
|
||||
}
|
||||
IDisposer disposer,
|
||||
string name) : FilterVaultNavigationViewModel(provider, factory, mediator, publisher, subscriber, disposer, name);
|
||||
@@ -1,5 +1,4 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Toolkit.Foundation;
|
||||
using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
@@ -8,10 +7,5 @@ public partial class CategoriesNavigationViewModel(IServiceProvider provider,
|
||||
IMediator mediator,
|
||||
IPublisher publisher,
|
||||
ISubscriber subscriber,
|
||||
IDisposer disposer) :
|
||||
ObservableViewModel(provider, factory, mediator, publisher, subscriber, disposer),
|
||||
IVaultNavigationViewModel
|
||||
{
|
||||
[ObservableProperty]
|
||||
private bool selected;
|
||||
}
|
||||
IDisposer disposer,
|
||||
string name) : FilterVaultNavigationViewModel(provider, factory, mediator, publisher, subscriber, disposer, name);
|
||||
@@ -0,0 +1,35 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public partial class FilterVaultNavigationViewModel(IServiceProvider provider,
|
||||
IServiceFactory factory,
|
||||
IMediator mediator,
|
||||
IPublisher publisher,
|
||||
ISubscriber subscriber,
|
||||
IDisposer disposer,
|
||||
string name) :
|
||||
ObservableViewModel(provider, factory, mediator, publisher, subscriber, disposer),
|
||||
IVaultNavigationViewModel,
|
||||
INotificationHandler<Vault<Activated>>,
|
||||
INotificationHandler<Vault<Deactivated>>
|
||||
{
|
||||
[ObservableProperty]
|
||||
private bool activated;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool selected;
|
||||
|
||||
public Task Handle(Vault<Deactivated> args,
|
||||
CancellationToken cancellationToken = default) =>
|
||||
Task.FromResult(Activated = false);
|
||||
|
||||
public Task Handle(Vault<Activated> args,
|
||||
CancellationToken cancellationToken = default) =>
|
||||
Task.FromResult(Activated = true);
|
||||
|
||||
[RelayCommand]
|
||||
public void Invoke() => Publisher.Publish(Vault.As(new Selected<string>(name)));
|
||||
}
|
||||
@@ -22,7 +22,7 @@ public partial class OpenVaultViewModel(IServiceProvider provider,
|
||||
{
|
||||
if (await Mediator.Handle<Open<Vault>, bool>(Open.As(new Vault(Password))))
|
||||
{
|
||||
await Publisher.Publish<Opened>();
|
||||
await Publisher.Publish(Vault.As<Opened>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using Toolkit.Foundation;
|
||||
using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
@@ -9,13 +7,5 @@ public partial class StarredNavigationViewModel(IServiceProvider provider,
|
||||
IMediator mediator,
|
||||
IPublisher publisher,
|
||||
ISubscriber subscriber,
|
||||
IDisposer disposer) :
|
||||
ObservableViewModel(provider, factory, mediator, publisher, subscriber, disposer),
|
||||
IVaultNavigationViewModel
|
||||
{
|
||||
[ObservableProperty]
|
||||
private bool selected;
|
||||
|
||||
[RelayCommand]
|
||||
public void Invoke() => Publisher.Publish(Changed.As(new VaultCategory("Starred")));
|
||||
}
|
||||
IDisposer disposer,
|
||||
string name) : FilterVaultNavigationViewModel(provider, factory, mediator, publisher, subscriber, disposer, name);
|
||||
+5
-3
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public record Vault<TValue>(TValue? Value = default);
|
||||
|
||||
public record Vault
|
||||
{
|
||||
public Vault(string name, string password)
|
||||
@@ -16,10 +18,10 @@ public record Vault
|
||||
}
|
||||
|
||||
|
||||
public Vault()
|
||||
{
|
||||
public static Vault<TValue> As<TValue>(TValue value) => new(value);
|
||||
|
||||
public static Vault<TValue> As<TValue>() where TValue : new() => new(new TValue());
|
||||
|
||||
}
|
||||
|
||||
[MaybeNull]
|
||||
public string Name { get; }
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
namespace Bitvault;
|
||||
|
||||
public record VaultCategory(string Name);
|
||||
@@ -6,9 +6,14 @@ namespace Bitvault;
|
||||
public partial class VaultNavigationViewModel :
|
||||
ObservableCollectionViewModel<IVaultNavigationViewModel>,
|
||||
IMainNavigationViewModel,
|
||||
INotificationHandler<Opened>,
|
||||
INotificationHandler<Closed>
|
||||
INotificationHandler<Vault<Opened>>,
|
||||
INotificationHandler<Vault<Closed>>,
|
||||
INotificationHandler<Vault<Activated>>,
|
||||
INotificationHandler<Vault<Deactivated>>
|
||||
{
|
||||
[ObservableProperty]
|
||||
private bool activated;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool expanded = true;
|
||||
|
||||
@@ -36,22 +41,32 @@ public partial class VaultNavigationViewModel :
|
||||
|
||||
public IContentTemplate Template { get; set; }
|
||||
|
||||
public Task Handle(Opened args, CancellationToken cancellationToken = default)
|
||||
public Task Handle(Vault<Opened> args,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
Add<AllNavigationViewModel>();
|
||||
Add<StarredNavigationViewModel>();
|
||||
Add<ArchiveNavigationViewModel>();
|
||||
Add<CategoriesNavigationViewModel>();
|
||||
Add<AllNavigationViewModel>("All");
|
||||
Add<StarredNavigationViewModel>("Starred");
|
||||
Add<ArchiveNavigationViewModel>("Archive");
|
||||
Add<CategoriesNavigationViewModel>("Categories");
|
||||
|
||||
Opened = true;
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task Handle(Closed args, CancellationToken cancellationToken = default)
|
||||
public Task Handle(Vault<Closed> args,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
Opened = true;
|
||||
Clear();
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task Handle(Vault<Deactivated> args,
|
||||
CancellationToken cancellationToken = default) =>
|
||||
Task.FromResult(Activated = false);
|
||||
|
||||
public Task Handle(Vault<Activated> args,
|
||||
CancellationToken cancellationToken = default) =>
|
||||
Task.FromResult(Activated = true);
|
||||
}
|
||||
@@ -12,4 +12,16 @@ public partial class VaultViewModel(IServiceProvider provider,
|
||||
IContentTemplate template) : ObservableCollectionViewModel<LockerNavigationViewModel>(provider, factory, mediator, publisher, subscriber, disposer)
|
||||
{
|
||||
public IContentTemplate Template { get; set; } = template;
|
||||
|
||||
public override async Task Activated()
|
||||
{
|
||||
await Publisher.Publish(Vault.As<Activated>());
|
||||
await base.Activated();
|
||||
}
|
||||
|
||||
public override async Task Deactivated()
|
||||
{
|
||||
await Publisher.Publish(Vault.As<Deactivated>());
|
||||
await base.Deactivated();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user