Added HyperlinkEntry
This commit is contained in:
@@ -166,6 +166,7 @@ public partial class App : Application
|
|||||||
services.AddTemplate<MaskedTextEntryViewModel, MaskedTextEntryView>();
|
services.AddTemplate<MaskedTextEntryViewModel, MaskedTextEntryView>();
|
||||||
services.AddTemplate<DropdownEntryViewModel, DropdownEntryView>();
|
services.AddTemplate<DropdownEntryViewModel, DropdownEntryView>();
|
||||||
services.AddTemplate<DateEntryViewModel, DateEntryView>();
|
services.AddTemplate<DateEntryViewModel, DateEntryView>();
|
||||||
|
services.AddTemplate<HyperlinkEntryViewModel, HyperlinkEntryView>();
|
||||||
|
|
||||||
services.AddTemplate<ItemCommandHeaderViewModel, ItemCommandHeaderView>("ItemCommandHeader");
|
services.AddTemplate<ItemCommandHeaderViewModel, ItemCommandHeaderView>("ItemCommandHeader");
|
||||||
|
|
||||||
@@ -180,6 +181,8 @@ public partial class App : Application
|
|||||||
services.AddHandler<ConfirmUpdateItemHandler>(nameof(ItemState.Write));
|
services.AddHandler<ConfirmUpdateItemHandler>(nameof(ItemState.Write));
|
||||||
services.AddHandler<ConfirmCreateItemHandler>(nameof(ItemState.New));
|
services.AddHandler<ConfirmCreateItemHandler>(nameof(ItemState.New));
|
||||||
|
|
||||||
|
services.AddHandler<HyperlinkHandler>();
|
||||||
|
|
||||||
services.AddHandler<ArchiveItemHandler>();
|
services.AddHandler<ArchiveItemHandler>();
|
||||||
services.AddHandler<UnarchiveItemHandler>();
|
services.AddHandler<UnarchiveItemHandler>();
|
||||||
services.AddHandler<FavouriteItemHandler>();
|
services.AddHandler<FavouriteItemHandler>();
|
||||||
@@ -191,6 +194,7 @@ public partial class App : Application
|
|||||||
services.AddHandler<MaskedTextEntryViewModelHandler>(nameof(MaskedTextEntryConfiguration));
|
services.AddHandler<MaskedTextEntryViewModelHandler>(nameof(MaskedTextEntryConfiguration));
|
||||||
services.AddHandler<DropdownEntryViewModelHandler>(nameof(DropdownEntryConfiguration));
|
services.AddHandler<DropdownEntryViewModelHandler>(nameof(DropdownEntryConfiguration));
|
||||||
services.AddHandler<DateEntryViewModelHandler>(nameof(DateEntryConfiguration));
|
services.AddHandler<DateEntryViewModelHandler>(nameof(DateEntryConfiguration));
|
||||||
|
services.AddHandler<HyperlinkEntryViewModelHandler>(nameof(HyperlinkEntryConfiguration));
|
||||||
|
|
||||||
services.AddHandler<ItemCreatedHandler>(ServiceLifetime.Singleton);
|
services.AddHandler<ItemCreatedHandler>(ServiceLifetime.Singleton);
|
||||||
services.AddHandler<ItemModifiedHandler>(ServiceLifetime.Singleton);
|
services.AddHandler<ItemModifiedHandler>(ServiceLifetime.Singleton);
|
||||||
|
|||||||
@@ -0,0 +1,62 @@
|
|||||||
|
<SettingsExpander
|
||||||
|
x:Class="Wallet.Avalonia.HyperlinkEntryView"
|
||||||
|
xmlns="https://github.com/avaloniaui"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:vm="using:Wallet"
|
||||||
|
x:DataType="vm:HyperlinkEntryViewModel"
|
||||||
|
Header="{Binding Key}">
|
||||||
|
<SettingsExpander.Footer>
|
||||||
|
<Grid>
|
||||||
|
<TextBox Text="{Binding Value}">
|
||||||
|
<TextBox.Styles>
|
||||||
|
<Style Selector="TextBox.Write">
|
||||||
|
<Setter Property="MinWidth" Value="{Binding Width}" />
|
||||||
|
<Setter Property="IsVisible" Value="True" />
|
||||||
|
</Style>
|
||||||
|
<Style Selector="TextBox.Read">
|
||||||
|
<Setter Property="MinWidth" Value="{Binding Width}" />
|
||||||
|
<Setter Property="IsVisible" Value="False" />
|
||||||
|
</Style>
|
||||||
|
</TextBox.Styles>
|
||||||
|
<Interaction.Behaviors>
|
||||||
|
<DataTriggerBehavior Binding="{Binding State}" Value="{x:Static vm:ItemState.Read}">
|
||||||
|
<AddClassAction ClassName="Read" RemoveIfExists="True" />
|
||||||
|
<RemoveClassAction ClassName="Write" />
|
||||||
|
</DataTriggerBehavior>
|
||||||
|
<DataTriggerBehavior Binding="{Binding State}" Value="{x:Static vm:ItemState.New}">
|
||||||
|
<AddClassAction ClassName="Write" RemoveIfExists="True" />
|
||||||
|
<RemoveClassAction ClassName="Read" />
|
||||||
|
</DataTriggerBehavior>
|
||||||
|
<DataTriggerBehavior Binding="{Binding State}" Value="{x:Static vm:ItemState.Write}">
|
||||||
|
<AddClassAction ClassName="Write" RemoveIfExists="True" />
|
||||||
|
<RemoveClassAction ClassName="Read" />
|
||||||
|
</DataTriggerBehavior>
|
||||||
|
</Interaction.Behaviors>
|
||||||
|
</TextBox>
|
||||||
|
<HyperlinkButton Command="{Binding InvokeCommand}" Content="{Binding Value}">
|
||||||
|
<HyperlinkButton.Styles>
|
||||||
|
<Style Selector="HyperlinkButton.Write">
|
||||||
|
<Setter Property="IsVisible" Value="False" />
|
||||||
|
</Style>
|
||||||
|
<Style Selector="HyperlinkButton.Read">
|
||||||
|
<Setter Property="IsVisible" Value="True" />
|
||||||
|
</Style>
|
||||||
|
</HyperlinkButton.Styles>
|
||||||
|
<Interaction.Behaviors>
|
||||||
|
<DataTriggerBehavior Binding="{Binding State}" Value="{x:Static vm:ItemState.Read}">
|
||||||
|
<AddClassAction ClassName="Read" RemoveIfExists="True" />
|
||||||
|
<RemoveClassAction ClassName="Write" />
|
||||||
|
</DataTriggerBehavior>
|
||||||
|
<DataTriggerBehavior Binding="{Binding State}" Value="{x:Static vm:ItemState.New}">
|
||||||
|
<AddClassAction ClassName="Write" RemoveIfExists="True" />
|
||||||
|
<RemoveClassAction ClassName="Read" />
|
||||||
|
</DataTriggerBehavior>
|
||||||
|
<DataTriggerBehavior Binding="{Binding State}" Value="{x:Static vm:ItemState.Write}">
|
||||||
|
<AddClassAction ClassName="Write" RemoveIfExists="True" />
|
||||||
|
<RemoveClassAction ClassName="Read" />
|
||||||
|
</DataTriggerBehavior>
|
||||||
|
</Interaction.Behaviors>
|
||||||
|
</HyperlinkButton>
|
||||||
|
</Grid>
|
||||||
|
</SettingsExpander.Footer>
|
||||||
|
</SettingsExpander>
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
using Toolkit.UI.Controls.Avalonia;
|
||||||
|
|
||||||
|
namespace Wallet.Avalonia;
|
||||||
|
|
||||||
|
public partial class HyperlinkEntryView :
|
||||||
|
SettingsExpander
|
||||||
|
{
|
||||||
|
public HyperlinkEntryView() =>
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
@@ -11,5 +11,5 @@ public partial class DateEntryViewModel(IServiceProvider provider,
|
|||||||
ItemState state,
|
ItemState state,
|
||||||
ItemEntryConfiguration configuration,
|
ItemEntryConfiguration configuration,
|
||||||
string key,
|
string key,
|
||||||
object value,
|
DateTimeOffset value,
|
||||||
double width) : ItemEntryViewModel(provider, factory, mediator, publisher, subscriber, disposer, state, configuration, key, value, width);
|
double width) : ItemEntryViewModel<DateTimeOffset>(provider, factory, mediator, publisher, subscriber, disposer, state, configuration, key, value, width);
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
namespace Wallet;
|
||||||
|
|
||||||
|
public record Hyperlink(string Value);
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
using CommunityToolkit.Mvvm.Input;
|
||||||
|
using Toolkit.Foundation;
|
||||||
|
|
||||||
|
namespace Wallet;
|
||||||
|
|
||||||
|
public partial class HyperlinkEntryViewModel(IServiceProvider provider,
|
||||||
|
IServiceFactory factory,
|
||||||
|
IMediator mediator,
|
||||||
|
IPublisher publisher,
|
||||||
|
ISubscription subscriber,
|
||||||
|
IDisposer disposer,
|
||||||
|
ItemState state,
|
||||||
|
ItemEntryConfiguration configuration,
|
||||||
|
string key,
|
||||||
|
string value,
|
||||||
|
double width) : ItemEntryViewModel<string>(provider, factory, mediator, publisher, subscriber, disposer, state, configuration, key, value, width)
|
||||||
|
{
|
||||||
|
[RelayCommand]
|
||||||
|
public void Invoke() => Publisher.Publish(Create.As(new Hyperlink(Value)));
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
using Toolkit.Foundation;
|
||||||
|
|
||||||
|
namespace Wallet;
|
||||||
|
|
||||||
|
public class HyperlinkEntryViewModelHandler(IServiceFactory serviceFactory) :
|
||||||
|
IHandler<CreateEventArgs<HyperlinkEntryConfiguration>, IItemEntryViewModel?>
|
||||||
|
{
|
||||||
|
public Task<IItemEntryViewModel?> Handle(CreateEventArgs<HyperlinkEntryConfiguration> args,
|
||||||
|
CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
if (args.Sender is HyperlinkEntryConfiguration configuration)
|
||||||
|
{
|
||||||
|
string? label = configuration.Label;
|
||||||
|
string? value = $"{configuration.Value}" ?? "";
|
||||||
|
double? width = configuration.Width;
|
||||||
|
|
||||||
|
if (serviceFactory.Create<HyperlinkEntryViewModel>([.. args.Parameters, configuration, label, value, width])
|
||||||
|
is HyperlinkEntryViewModel viewModel)
|
||||||
|
{
|
||||||
|
return Task.FromResult<IItemEntryViewModel?>(viewModel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Task.FromResult<IItemEntryViewModel?>(default);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
using System.Diagnostics;
|
||||||
|
using Toolkit.Foundation;
|
||||||
|
|
||||||
|
namespace Wallet;
|
||||||
|
|
||||||
|
public class HyperlinkHandler :
|
||||||
|
INotificationHandler<CreateEventArgs<Hyperlink>>
|
||||||
|
{
|
||||||
|
public Task Handle(CreateEventArgs<Hyperlink> args)
|
||||||
|
{
|
||||||
|
if (args.Sender is Hyperlink hyperlink && hyperlink.Value is { Length: > 0 } value)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Process.Start(new ProcessStartInfo { FileName = value, UseShellExecute = true });
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,7 +3,7 @@ using Toolkit.Foundation;
|
|||||||
|
|
||||||
namespace Wallet;
|
namespace Wallet;
|
||||||
|
|
||||||
public partial class ItemEntryViewModel(IServiceProvider provider,
|
public partial class ItemEntryViewModel<TValue>(IServiceProvider provider,
|
||||||
IServiceFactory factory,
|
IServiceFactory factory,
|
||||||
IMediator mediator,
|
IMediator mediator,
|
||||||
IPublisher publisher,
|
IPublisher publisher,
|
||||||
@@ -12,13 +12,14 @@ public partial class ItemEntryViewModel(IServiceProvider provider,
|
|||||||
ItemState state,
|
ItemState state,
|
||||||
ItemEntryConfiguration configuration,
|
ItemEntryConfiguration configuration,
|
||||||
string key,
|
string key,
|
||||||
object value,
|
TValue value,
|
||||||
double width) :
|
double width) :
|
||||||
Observable<string, object>(provider, factory, mediator, publisher, subscriber, disposer, key, value),
|
Observable<string, TValue>(provider, factory, mediator, publisher, subscriber, disposer, key, value),
|
||||||
IItemEntryViewModel,
|
IItemEntryViewModel,
|
||||||
INotificationHandler<UpdateEventArgs<Item>>,
|
INotificationHandler<UpdateEventArgs<Item>>,
|
||||||
INotificationHandler<ConfirmEventArgs<Item>>,
|
INotificationHandler<ConfirmEventArgs<Item>>,
|
||||||
INotificationHandler<CancelEventArgs<Item>>
|
INotificationHandler<CancelEventArgs<Item>>
|
||||||
|
where TValue : notnull
|
||||||
{
|
{
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
private ItemState state = state;
|
private ItemState state = state;
|
||||||
@@ -46,5 +47,5 @@ public partial class ItemEntryViewModel(IServiceProvider provider,
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnValueChanged() =>
|
protected override void OnValueChanged() =>
|
||||||
configuration.Value = Value;
|
configuration.Value = Value;
|
||||||
}
|
}
|
||||||
@@ -13,8 +13,8 @@ public partial class MaskedTextEntryViewModel(IServiceProvider provider,
|
|||||||
ItemEntryConfiguration configuration,
|
ItemEntryConfiguration configuration,
|
||||||
string pattern,
|
string pattern,
|
||||||
string key,
|
string key,
|
||||||
object value,
|
string value,
|
||||||
double width) : ItemEntryViewModel(provider, factory, mediator, publisher, subscriber, disposer, state, configuration, key, value, width)
|
double width) : ItemEntryViewModel<string>(provider, factory, mediator, publisher, subscriber, disposer, state, configuration, key, value, width)
|
||||||
{
|
{
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
private string pattern = pattern;
|
private string pattern = pattern;
|
||||||
|
|||||||
@@ -11,6 +11,6 @@ public partial class MultilineTextEntryViewModel(IServiceProvider provider,
|
|||||||
ItemState state,
|
ItemState state,
|
||||||
ItemEntryConfiguration configuration,
|
ItemEntryConfiguration configuration,
|
||||||
string key,
|
string key,
|
||||||
object value,
|
string value,
|
||||||
double width) : ItemEntryViewModel(provider, factory, mediator, publisher, subscriber, disposer, state, configuration, key, value, width);
|
double width) : ItemEntryViewModel<string>(provider, factory, mediator, publisher, subscriber, disposer, state, configuration, key, value, width);
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ public class MultilineTextEntryViewModelHandler(IServiceFactory serviceFactory)
|
|||||||
if (args.Sender is MultilineTextEntryConfiguration configuration)
|
if (args.Sender is MultilineTextEntryConfiguration configuration)
|
||||||
{
|
{
|
||||||
string? label = configuration.Label;
|
string? label = configuration.Label;
|
||||||
object? value = configuration.Value ?? "";
|
string? value = $"{configuration.Value}" ?? "";
|
||||||
double? width = configuration.Width;
|
double? width = configuration.Width;
|
||||||
|
|
||||||
if (serviceFactory.Create<MultilineTextEntryViewModel>([.. args.Parameters, configuration, label, value, width])
|
if (serviceFactory.Create<MultilineTextEntryViewModel>([.. args.Parameters, configuration, label, value, width])
|
||||||
|
|||||||
@@ -11,5 +11,5 @@ public partial class PasswordEntryViewModel(IServiceProvider provider,
|
|||||||
ItemState state,
|
ItemState state,
|
||||||
ItemEntryConfiguration configuration,
|
ItemEntryConfiguration configuration,
|
||||||
string key,
|
string key,
|
||||||
object value,
|
string value,
|
||||||
double width) : ItemEntryViewModel(provider, factory, mediator, publisher, subscriber, disposer, state, configuration, key, value, width);
|
double width) : ItemEntryViewModel<string>(provider, factory, mediator, publisher, subscriber, disposer, state, configuration, key, value, width);
|
||||||
@@ -11,7 +11,7 @@ public class PasswordEntryViewModelHandler(IServiceFactory serviceFactory) :
|
|||||||
if (args.Sender is PasswordEntryConfiguration configuration)
|
if (args.Sender is PasswordEntryConfiguration configuration)
|
||||||
{
|
{
|
||||||
string? label = configuration.Label;
|
string? label = configuration.Label;
|
||||||
object? value = configuration.Value ?? "";
|
string? value = $"{configuration.Value}" ?? "";
|
||||||
double? width = configuration.Width;
|
double? width = configuration.Width;
|
||||||
|
|
||||||
if (serviceFactory.Create<PasswordEntryViewModel>([.. args.Parameters, configuration, label, value, width])
|
if (serviceFactory.Create<PasswordEntryViewModel>([.. args.Parameters, configuration, label, value, width])
|
||||||
|
|||||||
@@ -1,15 +0,0 @@
|
|||||||
using Toolkit.Foundation;
|
|
||||||
|
|
||||||
namespace Wallet;
|
|
||||||
|
|
||||||
public partial class PasswordViewModel : Observable
|
|
||||||
{
|
|
||||||
public PasswordViewModel(IServiceProvider provider,
|
|
||||||
IServiceFactory factory,
|
|
||||||
IMediator mediator,
|
|
||||||
IPublisher publisher,
|
|
||||||
ISubscription subscriber,
|
|
||||||
IDisposer disposer) : base(provider, factory, mediator, publisher, subscriber, disposer)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -9,7 +9,7 @@ public partial class SearchWalletActionViewModel(IServiceProvider provider,
|
|||||||
IMediator mediator,
|
IMediator mediator,
|
||||||
IPublisher publisher,
|
IPublisher publisher,
|
||||||
ISubscription subscriber,
|
ISubscription subscriber,
|
||||||
IDisposer disposer) : Observable<string>(provider, factory, mediator, publisher, subscriber, disposer)
|
IDisposer disposer) : Observable<string>(provider, factory, mediator, publisher, subscriber, disposer, "")
|
||||||
{
|
{
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
private int index = 2;
|
private int index = 2;
|
||||||
|
|||||||
@@ -11,5 +11,5 @@ public partial class TextEntryViewModel(IServiceProvider provider,
|
|||||||
ItemState state,
|
ItemState state,
|
||||||
ItemEntryConfiguration configuration,
|
ItemEntryConfiguration configuration,
|
||||||
string key,
|
string key,
|
||||||
object value,
|
string value,
|
||||||
double width) : ItemEntryViewModel(provider, factory, mediator, publisher, subscriber, disposer, state, configuration, key, value, width);
|
double width) : ItemEntryViewModel<string>(provider, factory, mediator, publisher, subscriber, disposer, state, configuration, key, value, width);
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ public class TextEntryViewModelHandler(IServiceFactory serviceFactory) :
|
|||||||
if (args.Sender is TextEntryConfiguration configuration)
|
if (args.Sender is TextEntryConfiguration configuration)
|
||||||
{
|
{
|
||||||
string? label = configuration.Label;
|
string? label = configuration.Label;
|
||||||
object? value = configuration.Value ?? "";
|
string? value = $"{configuration.Value}" ?? "";
|
||||||
double? width = configuration.Width;
|
double? width = configuration.Width;
|
||||||
|
|
||||||
if (serviceFactory.Create<TextEntryViewModel>([.. args.Parameters, configuration, label, value, width])
|
if (serviceFactory.Create<TextEntryViewModel>([.. args.Parameters, configuration, label, value, width])
|
||||||
|
|||||||
Reference in New Issue
Block a user