using Avalonia.Controls; using Avalonia.Interactivity; using Avalonia.Markup.Xaml; using DodoSSH.Client.Shell.ViewModels; namespace DodoSSH.Client.Android.Views; /// Design 04 — everything in the vault that is not a host. internal sealed partial class KeychainScreen : UserControl { public KeychainScreen() => AvaloniaXamlLoader.Load(this); /// /// Cancels whichever of the keychain's five editors is open. /// /// Whether one was, and so whether there was anything to cancel. /// /// One place for the question the editor page's ← and the system back gesture both ask. Only one editor is /// ever open — each one's command refuses while another is — so the order only decides which test runs /// first. Cancelling rather than hiding, as the host editor does, because cancelling is what empties the /// boxes, and two of them hold a private key and a password. /// internal static bool TryCancelAnEditor(VaultViewModel vault) { if (vault.IsGeneratingKey) { vault.CancelGenerateKeyCommand.Execute(null); } else if (vault.IsEditingKey) { vault.CancelKeyEditCommand.Execute(null); } else if (vault.IsEditingCredential) { vault.CancelCredentialEditCommand.Execute(null); } else if (vault.IsEditingObjectStore) { vault.CancelObjectStoreEditCommand.Execute(null); } else if (vault.IsEditingTag) { vault.CancelTagEditCommand.Execute(null); } else { return false; } return true; } private void OnCancelEditor(object? sender, RoutedEventArgs e) { if (DataContext is VaultViewModel vault) { TryCancelAnEditor(vault); } } /// A kind was chosen on the add sheet: the sheet goes down as its editor opens. private void OnAddChosen(object? sender, RoutedEventArgs e) { if (DataContext is VaultViewModel vault) { vault.IsKeychainAddSheetOpen = false; } } }