Add contextual commands
This commit is contained in:
@@ -83,7 +83,7 @@ public partial class App : Application
|
||||
services.AddScoped<ContainerViewModelConfiguration>();
|
||||
|
||||
services.AddTemplate<ContainerViewModel, ContainerView>("Container");
|
||||
services.AddHandler<EnumerateContainerViewModelHandler>();
|
||||
services.AddHandler<AggerateContainerViewModelHandler>();
|
||||
|
||||
services.AddTemplate<SearchContainerActionViewModel, SearchContainerActionView>();
|
||||
services.AddTemplate<ContainerHeaderViewModel, ContainerHeaderView>("ContainerHeader");
|
||||
@@ -119,7 +119,7 @@ public partial class App : Application
|
||||
services.AddInitializer<ContainerInitializer>();
|
||||
|
||||
services.AddTemplate<MainViewModel, MainView>("Main");
|
||||
services.AddHandler<MainViewModelHandler>();
|
||||
services.AddHandler<AggerateMainViewModelHandler>();
|
||||
|
||||
services.AddTransient<FooterViewModel>();
|
||||
|
||||
|
||||
@@ -47,12 +47,8 @@
|
||||
BorderThickness="1,1,0,0"
|
||||
CornerRadius="8 0 0 0">
|
||||
<Grid RowDefinitions="Auto, *">
|
||||
<Border
|
||||
Grid.Row="0"
|
||||
Padding="4"
|
||||
BorderBrush="{DynamicResource DividerStrokeColorDefaultBrush}"
|
||||
BorderThickness="0,0,0,1">
|
||||
<ContentControl x:Name="ContentHeader">
|
||||
<Border Grid.Row="0" Padding="4">
|
||||
<ContentControl>
|
||||
<Interaction.Behaviors>
|
||||
<AttachedBehaviour>
|
||||
<NavigateRegionAction Name="{Binding Named, StringFormat='{}{0}:ContentHeader'}" />
|
||||
|
||||
@@ -15,10 +15,6 @@
|
||||
ToolTip.Tip="Add item">
|
||||
<Interaction.Behaviors>
|
||||
<EventTriggerBehavior EventName="Click">
|
||||
<NavigateAction
|
||||
Region="{Binding Named, StringFormat='{}{0}:ContentHeader'}"
|
||||
Route="ItemCommandHeader"
|
||||
Scope="self" />
|
||||
<NavigateAction
|
||||
Region="{Binding Named, StringFormat='{}{0}:Content'}"
|
||||
Route="Item"
|
||||
|
||||
@@ -14,13 +14,7 @@
|
||||
<NavigateAction
|
||||
Region="{Binding Named, StringFormat='{}{0}:Content'}"
|
||||
Route="Item"
|
||||
Scope="self">
|
||||
<NavigateAction.ParameterBindings>
|
||||
<ParameterBinding Key="Immutable" Value="{x:True}" />
|
||||
<ParameterBinding Key="Id" Value="{Binding Id}" />
|
||||
<ParameterBinding Key="Name" Value="{Binding Name}" />
|
||||
</NavigateAction.ParameterBindings>
|
||||
</NavigateAction>
|
||||
Scope="self" />
|
||||
</DataTriggerBehavior>
|
||||
</Interaction.Behaviors>
|
||||
<Grid Background="Transparent" ColumnDefinitions="Auto,*">
|
||||
|
||||
+4
-3
@@ -3,13 +3,14 @@ using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public class EnumerateContainerViewModelHandler(IMediator mediator,
|
||||
public class AggerateContainerViewModelHandler(IMediator mediator,
|
||||
IServiceProvider serviceProvider,
|
||||
ICache<Item> cache,
|
||||
IPublisher publisher) :
|
||||
INotificationHandler<Enumerate<ItemNavigationViewModel, ContainerViewModelConfiguration>>
|
||||
INotificationHandler<Aggerate<ItemNavigationViewModel, ContainerViewModelConfiguration>>
|
||||
{
|
||||
public async Task Handle(Enumerate<ItemNavigationViewModel, ContainerViewModelConfiguration> args)
|
||||
public async Task Handle(Aggerate<ItemNavigationViewModel,
|
||||
ContainerViewModelConfiguration> args)
|
||||
{
|
||||
if (args.Options is ContainerViewModelConfiguration configuration)
|
||||
{
|
||||
@@ -3,11 +3,11 @@ using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public class MainViewModelHandler(IPublisher publisher,
|
||||
public class AggerateMainViewModelHandler(IPublisher publisher,
|
||||
IContainerHostCollection containers) :
|
||||
INotificationHandler<EnumerateEventArgs<IMainNavigationViewModel>>
|
||||
INotificationHandler<AggerateEventArgs<IMainNavigationViewModel>>
|
||||
{
|
||||
public Task Handle(EnumerateEventArgs<IMainNavigationViewModel> args)
|
||||
public Task Handle(AggerateEventArgs<IMainNavigationViewModel> args)
|
||||
{
|
||||
foreach (IComponentHost container in containers.OrderBy(x => x.GetConfiguration<ContainerConfiguration>()
|
||||
is ContainerConfiguration configuration ? configuration.Name : null))
|
||||
@@ -18,7 +18,7 @@ public class MainViewModelHandler(IPublisher publisher,
|
||||
{
|
||||
if (factory.Create<ContainerNavigationViewModel>(configuration.Name) is ContainerNavigationViewModel viewModel)
|
||||
{
|
||||
publisher.Publish(new CreateEventArgs<IMainNavigationViewModel>(viewModel),
|
||||
publisher.Publish(Create.As<IMainNavigationViewModel>(viewModel),
|
||||
nameof(MainViewModel));
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,8 @@ public partial class ArchiveItemActionViewModel(IServiceProvider provider,
|
||||
IMediator mediator,
|
||||
IPublisher publisher,
|
||||
ISubscription subscriber,
|
||||
IDisposer disposer) : Observable(provider, factory, mediator, publisher, subscriber, disposer)
|
||||
IDisposer disposer) : Observable(provider, factory, mediator, publisher, subscriber, disposer),
|
||||
IRemovable
|
||||
{
|
||||
[RelayCommand]
|
||||
public void Invoke() => Publisher.Publish(Archive.As<Item>());
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public class CommandCollection :
|
||||
ReadOnlyCollection<IDisposable>
|
||||
{
|
||||
public CommandCollection(IList<IDisposable> list) : base(list)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,8 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Collections.ObjectModel;
|
||||
using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public class ItemCommandCollection : ObservableCollection
|
||||
{
|
||||
public void Add<TItem>(IDisposable diposer)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
[Enumerate(nameof(ContainerViewModel))]
|
||||
public partial class ContainerViewModel(IServiceProvider provider,
|
||||
@@ -48,7 +39,7 @@ public partial class ContainerViewModel(IServiceProvider provider,
|
||||
if (args.Value is Filter filter)
|
||||
{
|
||||
configuration = configuration with { Filter = filter.Value };
|
||||
Enumerate();
|
||||
Aggerate();
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
@@ -58,12 +49,12 @@ public partial class ContainerViewModel(IServiceProvider provider,
|
||||
if (args.Value is Search search)
|
||||
{
|
||||
configuration = configuration with { Query = search.Value };
|
||||
Enumerate();
|
||||
Aggerate();
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
protected override IEnumerate PrepareEnumeration(object? key) =>
|
||||
EnumerateEventArgs<ItemNavigationViewModel>.With(configuration) with { Key = key };
|
||||
protected override IAggerate OnAggerate(object? key) =>
|
||||
AggerateEventArgs<ItemNavigationViewModel>.With(configuration) with { Key = key };
|
||||
}
|
||||
@@ -2,24 +2,30 @@
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public partial class ItemCommandHeaderViewModel : ObservableCollection
|
||||
public partial class ItemCommandHeaderViewModel(IServiceProvider provider,
|
||||
IServiceFactory factory,
|
||||
IMediator mediator,
|
||||
IPublisher publisher,
|
||||
ISubscription subscriber,
|
||||
IDisposer disposer,
|
||||
IContentTemplate template) :
|
||||
ObservableCollection(provider, factory, mediator, publisher, subscriber, disposer),
|
||||
INotificationHandler<NotifyEventArgs<CommandCollection>>
|
||||
{
|
||||
public ItemCommandHeaderViewModel(IServiceProvider provider,
|
||||
IServiceFactory factory,
|
||||
IMediator mediator,
|
||||
IPublisher publisher,
|
||||
ISubscription subscriber,
|
||||
IDisposer disposer,
|
||||
IContentTemplate template) : base(provider, factory, mediator, publisher, subscriber, disposer)
|
||||
public IContentTemplate Template { get; set; } = template;
|
||||
|
||||
public Task Handle(NotifyEventArgs<CommandCollection> args)
|
||||
{
|
||||
Add<ConfirmItemActionViewModel>();
|
||||
Add<DismissItemActionViewModel>();
|
||||
Add<EditItemActionViewModel>();
|
||||
Add<DeleteItemActionViewModel>();
|
||||
Add<ArchiveItemActionViewModel>();
|
||||
Clear();
|
||||
|
||||
Template = template;
|
||||
if (args.Value is CommandCollection commandCollection)
|
||||
{
|
||||
foreach (IDisposable command in commandCollection)
|
||||
{
|
||||
Add(command);
|
||||
}
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public IContentTemplate Template { get; set; }
|
||||
}
|
||||
@@ -1,33 +1,25 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Toolkit.Foundation;
|
||||
using Toolkit.Foundation;
|
||||
|
||||
namespace Bitvault;
|
||||
|
||||
public partial class ItemViewModel :
|
||||
ObservableCollection<IDisposable>
|
||||
{
|
||||
[ObservableProperty]
|
||||
private int? id;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool immutable;
|
||||
|
||||
public ItemViewModel(IServiceProvider provider,
|
||||
IServiceFactory factory,
|
||||
IMediator mediator,
|
||||
IPublisher publisher,
|
||||
ISubscription subscriber,
|
||||
IDisposer disposer,
|
||||
IContentTemplate template,
|
||||
bool immutable = true,
|
||||
int? id = null,
|
||||
string? name = null) : base(provider, factory, mediator, publisher, subscriber, disposer)
|
||||
IContentTemplate template) : base(provider, factory, mediator, publisher, subscriber, disposer)
|
||||
{
|
||||
Template = template;
|
||||
Id = id;
|
||||
Immutable = immutable;
|
||||
|
||||
Add<ItemHeaderViewModel>(immutable, name ?? "");
|
||||
Publisher.Publish(Notify.As(Factory.Create<CommandCollection>(new List<IDisposable>
|
||||
{
|
||||
Factory.Create<EditItemActionViewModel>(),
|
||||
Factory.Create<ArchiveItemActionViewModel>(),
|
||||
})));
|
||||
}
|
||||
|
||||
public IContentTemplate Template { get; set; }
|
||||
|
||||
Reference in New Issue
Block a user