Improve vault navifaiton
This commit is contained in:
@@ -8,7 +8,14 @@
|
|||||||
IsSelected="{Binding Selected, Mode=TwoWay}">
|
IsSelected="{Binding Selected, Mode=TwoWay}">
|
||||||
<Interaction.Behaviors>
|
<Interaction.Behaviors>
|
||||||
<DataTriggerBehavior Binding="{Binding Selected}" Value="True">
|
<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>
|
</DataTriggerBehavior>
|
||||||
</Interaction.Behaviors>
|
</Interaction.Behaviors>
|
||||||
</NavigationViewItem>
|
</NavigationViewItem>
|
||||||
|
|||||||
@@ -8,7 +8,14 @@
|
|||||||
IsSelected="{Binding Selected, Mode=TwoWay}">
|
IsSelected="{Binding Selected, Mode=TwoWay}">
|
||||||
<Interaction.Behaviors>
|
<Interaction.Behaviors>
|
||||||
<DataTriggerBehavior Binding="{Binding Selected}" Value="True">
|
<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>
|
</DataTriggerBehavior>
|
||||||
</Interaction.Behaviors>
|
</Interaction.Behaviors>
|
||||||
</NavigationViewItem>
|
</NavigationViewItem>
|
||||||
|
|||||||
@@ -8,7 +8,14 @@
|
|||||||
IsSelected="{Binding Selected, Mode=TwoWay}">
|
IsSelected="{Binding Selected, Mode=TwoWay}">
|
||||||
<Interaction.Behaviors>
|
<Interaction.Behaviors>
|
||||||
<DataTriggerBehavior Binding="{Binding Selected}" Value="True">
|
<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>
|
</DataTriggerBehavior>
|
||||||
</Interaction.Behaviors>
|
</Interaction.Behaviors>
|
||||||
</NavigationViewItem>
|
</NavigationViewItem>
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
x:Name="NavigationViewItem"
|
x:Name="NavigationViewItem"
|
||||||
x:DataType="vm:VaultNavigationViewModel"
|
x:DataType="vm:VaultNavigationViewModel"
|
||||||
Content="{Binding Name}"
|
Content="{Binding Name}"
|
||||||
IsExpanded="{Binding Expanded, Mode=TwoWay}"
|
IsExpanded="{Binding Expanded}"
|
||||||
IsSelected="{Binding Selected}"
|
IsSelected="{Binding Selected}"
|
||||||
MenuItemsSource="{Binding}"
|
MenuItemsSource="{Binding}"
|
||||||
NavigationViewItemExtension.IsItemClickEnabled="True"
|
NavigationViewItemExtension.IsItemClickEnabled="True"
|
||||||
@@ -38,7 +38,7 @@
|
|||||||
PropertyName="SelectsOnInvoked"
|
PropertyName="SelectsOnInvoked"
|
||||||
TargetObject="{Binding #NavigationViewItem}"
|
TargetObject="{Binding #NavigationViewItem}"
|
||||||
Value="False" />
|
Value="False" />
|
||||||
<SelectNavigationViewItemAction />
|
<InvokeNavigationViewItemAction />
|
||||||
</ConditionAction>
|
</ConditionAction>
|
||||||
</DataTriggerBehavior>
|
</DataTriggerBehavior>
|
||||||
<AttachedEventTriggerBehaviour RoutedEvent="{x:Static NavigationViewItemExtension.ItemClickEvent}">
|
<AttachedEventTriggerBehaviour RoutedEvent="{x:Static NavigationViewItemExtension.ItemClickEvent}">
|
||||||
@@ -46,7 +46,6 @@
|
|||||||
<ConditionAction.Condition>
|
<ConditionAction.Condition>
|
||||||
<ConditionalExpression ForwardChaining="And">
|
<ConditionalExpression ForwardChaining="And">
|
||||||
<ComparisonCondition LeftOperand="{Binding Opened}" RightOperand="False" />
|
<ComparisonCondition LeftOperand="{Binding Opened}" RightOperand="False" />
|
||||||
<ComparisonCondition LeftOperand="{Binding #NavigationViewItem.IsChildSelected}" RightOperand="False" />
|
|
||||||
</ConditionalExpression>
|
</ConditionalExpression>
|
||||||
</ConditionAction.Condition>
|
</ConditionAction.Condition>
|
||||||
<NavigateAction Context="Main" Route="OpenVault" />
|
<NavigateAction Context="Main" Route="OpenVault" />
|
||||||
@@ -55,11 +54,11 @@
|
|||||||
<ConditionAction.Condition>
|
<ConditionAction.Condition>
|
||||||
<ConditionalExpression ForwardChaining="And">
|
<ConditionalExpression ForwardChaining="And">
|
||||||
<ComparisonCondition LeftOperand="{Binding Opened}" RightOperand="True" />
|
<ComparisonCondition LeftOperand="{Binding Opened}" RightOperand="True" />
|
||||||
<ComparisonCondition LeftOperand="{Binding #NavigationViewItem.IsChildSelected}" RightOperand="False" />
|
<ComparisonCondition LeftOperand="{Binding Activated}" RightOperand="False" />
|
||||||
</ConditionalExpression>
|
</ConditionalExpression>
|
||||||
</ConditionAction.Condition>
|
</ConditionAction.Condition>
|
||||||
<NavigateAction Context="Main" Route="Vault" />
|
<NavigateAction Context="Main" Route="Vault" />
|
||||||
<SelectNavigationViewItemAction />
|
<InvokeNavigationViewItemAction />
|
||||||
</ConditionAction>
|
</ConditionAction>
|
||||||
</AttachedEventTriggerBehaviour>
|
</AttachedEventTriggerBehaviour>
|
||||||
</Interaction.Behaviors>
|
</Interaction.Behaviors>
|
||||||
|
|||||||
@@ -35,13 +35,5 @@
|
|||||||
ItemTemplate="{ReflectionBinding Template}"
|
ItemTemplate="{ReflectionBinding Template}"
|
||||||
ItemsSource="{Binding}" />
|
ItemsSource="{Binding}" />
|
||||||
</Grid>
|
</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>
|
</Grid>
|
||||||
</UserControl>
|
</UserControl>
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
using CommunityToolkit.Mvvm.ComponentModel;
|
using Toolkit.Foundation;
|
||||||
using CommunityToolkit.Mvvm.Input;
|
|
||||||
using Toolkit.Foundation;
|
|
||||||
|
|
||||||
namespace Bitvault;
|
namespace Bitvault;
|
||||||
|
|
||||||
@@ -9,13 +7,5 @@ public partial class AllNavigationViewModel(IServiceProvider provider,
|
|||||||
IMediator mediator,
|
IMediator mediator,
|
||||||
IPublisher publisher,
|
IPublisher publisher,
|
||||||
ISubscriber subscriber,
|
ISubscriber subscriber,
|
||||||
IDisposer disposer) :
|
IDisposer disposer,
|
||||||
ObservableViewModel(provider, factory, mediator, publisher, subscriber, disposer),
|
string name) : FilterVaultNavigationViewModel(provider, factory, mediator, publisher, subscriber, disposer, name);
|
||||||
IVaultNavigationViewModel
|
|
||||||
{
|
|
||||||
[ObservableProperty]
|
|
||||||
private bool selected;
|
|
||||||
|
|
||||||
[RelayCommand]
|
|
||||||
public void Invoke() => Publisher.Publish(Changed.As(new VaultCategory("All")));
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
using CommunityToolkit.Mvvm.ComponentModel;
|
using Toolkit.Foundation;
|
||||||
using CommunityToolkit.Mvvm.Input;
|
|
||||||
using Toolkit.Foundation;
|
|
||||||
|
|
||||||
namespace Bitvault;
|
namespace Bitvault;
|
||||||
|
|
||||||
@@ -9,13 +7,5 @@ public partial class ArchiveNavigationViewModel(IServiceProvider provider,
|
|||||||
IMediator mediator,
|
IMediator mediator,
|
||||||
IPublisher publisher,
|
IPublisher publisher,
|
||||||
ISubscriber subscriber,
|
ISubscriber subscriber,
|
||||||
IDisposer disposer) :
|
IDisposer disposer,
|
||||||
ObservableViewModel(provider, factory, mediator, publisher, subscriber, disposer),
|
string name) : FilterVaultNavigationViewModel(provider, factory, mediator, publisher, subscriber, disposer, name);
|
||||||
IVaultNavigationViewModel
|
|
||||||
{
|
|
||||||
[ObservableProperty]
|
|
||||||
private bool selected;
|
|
||||||
|
|
||||||
[RelayCommand]
|
|
||||||
public void Invoke() => Publisher.Publish(Changed.As(new VaultCategory("Archive")));
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
using CommunityToolkit.Mvvm.ComponentModel;
|
using Toolkit.Foundation;
|
||||||
using Toolkit.Foundation;
|
|
||||||
|
|
||||||
namespace Bitvault;
|
namespace Bitvault;
|
||||||
|
|
||||||
@@ -8,10 +7,5 @@ public partial class CategoriesNavigationViewModel(IServiceProvider provider,
|
|||||||
IMediator mediator,
|
IMediator mediator,
|
||||||
IPublisher publisher,
|
IPublisher publisher,
|
||||||
ISubscriber subscriber,
|
ISubscriber subscriber,
|
||||||
IDisposer disposer) :
|
IDisposer disposer,
|
||||||
ObservableViewModel(provider, factory, mediator, publisher, subscriber, disposer),
|
string name) : FilterVaultNavigationViewModel(provider, factory, mediator, publisher, subscriber, disposer, name);
|
||||||
IVaultNavigationViewModel
|
|
||||||
{
|
|
||||||
[ObservableProperty]
|
|
||||||
private bool selected;
|
|
||||||
}
|
|
||||||
@@ -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))))
|
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 Toolkit.Foundation;
|
||||||
using CommunityToolkit.Mvvm.Input;
|
|
||||||
using Toolkit.Foundation;
|
|
||||||
|
|
||||||
namespace Bitvault;
|
namespace Bitvault;
|
||||||
|
|
||||||
@@ -9,13 +7,5 @@ public partial class StarredNavigationViewModel(IServiceProvider provider,
|
|||||||
IMediator mediator,
|
IMediator mediator,
|
||||||
IPublisher publisher,
|
IPublisher publisher,
|
||||||
ISubscriber subscriber,
|
ISubscriber subscriber,
|
||||||
IDisposer disposer) :
|
IDisposer disposer,
|
||||||
ObservableViewModel(provider, factory, mediator, publisher, subscriber, disposer),
|
string name) : FilterVaultNavigationViewModel(provider, factory, mediator, publisher, subscriber, disposer, name);
|
||||||
IVaultNavigationViewModel
|
|
||||||
{
|
|
||||||
[ObservableProperty]
|
|
||||||
private bool selected;
|
|
||||||
|
|
||||||
[RelayCommand]
|
|
||||||
public void Invoke() => Publisher.Publish(Changed.As(new VaultCategory("Starred")));
|
|
||||||
}
|
|
||||||
+5
-3
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
namespace Bitvault;
|
namespace Bitvault;
|
||||||
|
|
||||||
|
public record Vault<TValue>(TValue? Value = default);
|
||||||
|
|
||||||
public record Vault
|
public record Vault
|
||||||
{
|
{
|
||||||
public Vault(string name, string password)
|
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]
|
[MaybeNull]
|
||||||
public string Name { get; }
|
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 :
|
public partial class VaultNavigationViewModel :
|
||||||
ObservableCollectionViewModel<IVaultNavigationViewModel>,
|
ObservableCollectionViewModel<IVaultNavigationViewModel>,
|
||||||
IMainNavigationViewModel,
|
IMainNavigationViewModel,
|
||||||
INotificationHandler<Opened>,
|
INotificationHandler<Vault<Opened>>,
|
||||||
INotificationHandler<Closed>
|
INotificationHandler<Vault<Closed>>,
|
||||||
|
INotificationHandler<Vault<Activated>>,
|
||||||
|
INotificationHandler<Vault<Deactivated>>
|
||||||
{
|
{
|
||||||
|
[ObservableProperty]
|
||||||
|
private bool activated;
|
||||||
|
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
private bool expanded = true;
|
private bool expanded = true;
|
||||||
|
|
||||||
@@ -36,22 +41,32 @@ public partial class VaultNavigationViewModel :
|
|||||||
|
|
||||||
public IContentTemplate Template { get; set; }
|
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<AllNavigationViewModel>("All");
|
||||||
Add<StarredNavigationViewModel>();
|
Add<StarredNavigationViewModel>("Starred");
|
||||||
Add<ArchiveNavigationViewModel>();
|
Add<ArchiveNavigationViewModel>("Archive");
|
||||||
Add<CategoriesNavigationViewModel>();
|
Add<CategoriesNavigationViewModel>("Categories");
|
||||||
|
|
||||||
Opened = true;
|
Opened = true;
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task Handle(Closed args, CancellationToken cancellationToken = default)
|
public Task Handle(Vault<Closed> args,
|
||||||
|
CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
Opened = true;
|
Opened = true;
|
||||||
Clear();
|
Clear();
|
||||||
|
|
||||||
return Task.CompletedTask;
|
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)
|
IContentTemplate template) : ObservableCollectionViewModel<LockerNavigationViewModel>(provider, factory, mediator, publisher, subscriber, disposer)
|
||||||
{
|
{
|
||||||
public IContentTemplate Template { get; set; } = template;
|
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