2026-06-11 11:27:41 +02:00
|
|
|
using System.Linq;
|
2026-06-11 21:39:32 +02:00
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Avalonia;
|
2026-06-11 11:27:41 +02:00
|
|
|
using Avalonia.Controls;
|
2026-06-11 21:39:32 +02:00
|
|
|
using Avalonia.Input;
|
|
|
|
|
using Avalonia.Input.Platform;
|
2026-06-11 11:27:41 +02:00
|
|
|
using Avalonia.Interactivity;
|
|
|
|
|
using Avalonia.Platform.Storage;
|
2026-06-11 21:39:32 +02:00
|
|
|
using Avalonia.VisualTree;
|
2026-06-11 11:27:41 +02:00
|
|
|
using PalladiumWallet.App.ViewModels;
|
|
|
|
|
|
|
|
|
|
namespace PalladiumWallet.App.Views;
|
|
|
|
|
|
|
|
|
|
public partial class MainWindow : Window
|
|
|
|
|
{
|
|
|
|
|
public MainWindow()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async void OnOpenWalletFileClick(object? sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (DataContext is not MainWindowViewModel vm)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var files = await StorageProvider.OpenFilePickerAsync(new FilePickerOpenOptions
|
|
|
|
|
{
|
|
|
|
|
Title = "Apri file wallet",
|
|
|
|
|
AllowMultiple = false,
|
|
|
|
|
FileTypeFilter =
|
|
|
|
|
[
|
|
|
|
|
new FilePickerFileType("Wallet Palladium") { Patterns = ["*.wallet.json", "*.json"] },
|
|
|
|
|
],
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (files.FirstOrDefault()?.TryGetLocalPath() is { } path)
|
|
|
|
|
vm.OpenFromPath(path);
|
|
|
|
|
}
|
2026-06-11 21:39:32 +02:00
|
|
|
|
2026-06-12 08:16:39 +02:00
|
|
|
private void OnAddressListTapped(object? sender, TappedEventArgs e)
|
2026-06-11 21:39:32 +02:00
|
|
|
{
|
|
|
|
|
if (DataContext is not MainWindowViewModel vm || vm.SelectedAddressRow is not { } row)
|
|
|
|
|
return;
|
2026-06-12 08:16:39 +02:00
|
|
|
vm.ShowAddressInfo(row);
|
2026-06-11 21:39:32 +02:00
|
|
|
}
|
|
|
|
|
|
2026-06-12 08:16:39 +02:00
|
|
|
private void OnAddressListPointerPressed(object? sender, PointerPressedEventArgs e)
|
2026-06-11 21:39:32 +02:00
|
|
|
{
|
|
|
|
|
if (!e.GetCurrentPoint(null).Properties.IsRightButtonPressed) return;
|
|
|
|
|
if (sender is not ListBox lb || DataContext is not MainWindowViewModel vm) return;
|
|
|
|
|
|
|
|
|
|
var item = (e.Source as Visual)?.FindAncestorOfType<ListBoxItem>();
|
|
|
|
|
if (item is not { DataContext: AddressRow row }) return;
|
|
|
|
|
|
|
|
|
|
lb.SelectedItem = row;
|
2026-06-12 08:16:39 +02:00
|
|
|
vm.ShowAddressInfo(row);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Chiusura dell'overlay dettaglio indirizzo: click sullo sfondo scuro
|
|
|
|
|
// (solo sullo sfondo, non sulla scheda) o tasto Esc.
|
|
|
|
|
private void OnAddressOverlayBackdropTapped(object? sender, TappedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (!ReferenceEquals(e.Source, sender)) return;
|
|
|
|
|
if (DataContext is MainWindowViewModel vm)
|
|
|
|
|
vm.AddressInfo = null;
|
|
|
|
|
}
|
2026-06-11 21:39:32 +02:00
|
|
|
|
2026-06-12 08:16:39 +02:00
|
|
|
protected override void OnKeyDown(KeyEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.Key == Key.Escape && DataContext is MainWindowViewModel { AddressInfo: not null } vm)
|
|
|
|
|
{
|
|
|
|
|
vm.AddressInfo = null;
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
base.OnKeyDown(e);
|
2026-06-11 21:39:32 +02:00
|
|
|
}
|
2026-06-11 11:27:41 +02:00
|
|
|
}
|