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