escape to close CreateVaultDialog + fix indentation in XAML

This commit is contained in:
2026-03-26 21:39:15 +03:00
parent 81335ce7ad
commit fc5ec11a84
3 changed files with 167 additions and 139 deletions

View File

@@ -3,6 +3,7 @@
x:Class="KeyKeeper.Views.CreateVaultFileWindow" x:Class="KeyKeeper.Views.CreateVaultFileWindow"
Title="Create New Vault" Title="Create New Vault"
Background="#fff" Background="#fff"
Focusable="True"
Icon="/Assets/icon.ico" Icon="/Assets/icon.ico"
Width="600" Height="450" Width="600" Height="450"
WindowStartupLocation="CenterOwner" WindowStartupLocation="CenterOwner"

View File

@@ -1,9 +1,8 @@
using Avalonia; using Avalonia;
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Interactivity; using Avalonia.Interactivity;
using Avalonia.Platform.Storage; using Avalonia.Platform.Storage;
using System;
using System.Threading.Tasks;
namespace KeyKeeper.Views namespace KeyKeeper.Views
{ {
@@ -22,6 +21,8 @@ namespace KeyKeeper.Views
FilePathTextBox.TextChanged += OnTextChanged; FilePathTextBox.TextChanged += OnTextChanged;
PasswordBox.TextChanged += OnPasswordTextChanged; PasswordBox.TextChanged += OnPasswordTextChanged;
ConfirmPasswordBox.TextChanged += OnPasswordTextChanged; ConfirmPasswordBox.TextChanged += OnPasswordTextChanged;
KeyDown += CreateVaultDialog_KeyDown;
} }
private async void OnTextChanged(object? sender, TextChangedEventArgs e) private async void OnTextChanged(object? sender, TextChangedEventArgs e)
@@ -60,6 +61,18 @@ namespace KeyKeeper.Views
CreateButton.IsEnabled = pathValid && passwordsEntered; CreateButton.IsEnabled = pathValid && passwordsEntered;
} }
private void CreateVaultDialog_KeyDown(object? sender, KeyEventArgs e)
{
if (e.Key == Key.Escape)
{
Close();
}
else if (e.Key == Key.Enter && CreateButton.IsEnabled)
{
Submit();
}
}
private async void BrowseButton_Click(object? sender, RoutedEventArgs e) private async void BrowseButton_Click(object? sender, RoutedEventArgs e)
{ {
var file = await StorageProvider.SaveFilePickerAsync(new FilePickerSaveOptions var file = await StorageProvider.SaveFilePickerAsync(new FilePickerSaveOptions
@@ -83,6 +96,11 @@ namespace KeyKeeper.Views
} }
private void CreateButton_Click(object? sender, RoutedEventArgs e) private void CreateButton_Click(object? sender, RoutedEventArgs e)
{
Submit();
}
private void Submit()
{ {
string path = FilePathTextBox.Text ?? ""; string path = FilePathTextBox.Text ?? "";
if (string.IsNullOrWhiteSpace(path)) if (string.IsNullOrWhiteSpace(path))

View File

@@ -20,7 +20,9 @@
Background="#2328C4" Background="#2328C4"
HorizontalAlignment="Left" HorizontalAlignment="Left"
VerticalAlignment="Stretch"/> VerticalAlignment="Stretch"/>
<StackPanel Margin="20" HorizontalAlignment="Left"> <StackPanel Margin="20" HorizontalAlignment="Left">
<!-- Надпись KeyKeeper --> <!-- Надпись KeyKeeper -->
<TextBlock Text="KeyKeeper" <TextBlock Text="KeyKeeper"
FontSize="32" FontSize="32"
@@ -36,13 +38,16 @@
Margin="0,0,0,12" Margin="0,0,0,12"
IsVisible="{Binding $parent[Window].DataContext.LockTimerDisplay, IsVisible="{Binding $parent[Window].DataContext.LockTimerDisplay,
Converter={x:Static StringConverters.IsNotNullOrEmpty}}"> Converter={x:Static StringConverters.IsNotNullOrEmpty}}">
<StackPanel Orientation="Horizontal" Spacing="6" VerticalAlignment="Center"> <StackPanel Orientation="Horizontal" Spacing="6" VerticalAlignment="Center">
<!-- Иконка замка (Material Design lock outline) --> <!-- Иконка замка (Material Design lock outline) -->
<Path Fill="White" <Path Fill="White"
VerticalAlignment="Center" VerticalAlignment="Center"
Width="13" Height="13" Width="13" Height="13"
Stretch="Uniform" Stretch="Uniform"
Data="M18 8h-1V6c0-2.76-2.24-5-5-5S7 3.24 7 6v2H6c-1.1 0-2 .9-2 2v10c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V10c0-1.1-.9-2-2-2zm-6 9c-1.1 0-2-.9-2-2s.9-2 2-2 2 .9 2 2-.9 2-2 2zm3.1-9H8.9V6c0-1.71 1.39-3.1 3.1-3.1 1.71 0 3.1 1.39 3.1 3.1v2z"/> Data="M18 8h-1V6c0-2.76-2.24-5-5-5S7 3.24 7 6v2H6c-1.1 0-2 .9-2 2v10c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V10c0-1.1-.9-2-2-2zm-6 9c-1.1 0-2-.9-2-2s.9-2 2-2 2 .9 2 2-.9 2-2 2zm3.1-9H8.9V6c0-1.71 1.39-3.1 3.1-3.1 1.71 0 3.1 1.39 3.1 3.1v2z"/>
<TextBlock Text="{Binding $parent[Window].DataContext.LockTimerDisplay}" <TextBlock Text="{Binding $parent[Window].DataContext.LockTimerDisplay}"
Foreground="White" Foreground="White"
FontSize="13" FontSize="13"
@@ -99,6 +104,7 @@
ItemsSource="{Binding Passwords}" ItemsSource="{Binding Passwords}"
Background="Transparent" Background="Transparent"
SelectionMode="Single"> SelectionMode="Single">
<ListBox.ItemsPanel> <ListBox.ItemsPanel>
<ItemsPanelTemplate> <ItemsPanelTemplate>
<WrapPanel Orientation="Horizontal"/> <WrapPanel Orientation="Horizontal"/>
@@ -108,9 +114,11 @@
<ListBox.ItemTemplate> <ListBox.ItemTemplate>
<DataTemplate> <DataTemplate>
<Border Background="Transparent" DoubleTapped="Entry_DoubleTapped"> <Border Background="Transparent" DoubleTapped="Entry_DoubleTapped">
<StackPanel Width="100" <StackPanel Width="100"
Margin="10" Margin="10"
HorizontalAlignment="Center"> HorizontalAlignment="Center">
<Svg Path="{Binding IconPath}" Width="48" Height="48"/> <Svg Path="{Binding IconPath}" Width="48" Height="48"/>
<TextBlock Text="{Binding Name}" <TextBlock Text="{Binding Name}"
HorizontalAlignment="Center" HorizontalAlignment="Center"
@@ -123,7 +131,6 @@
<ContextMenu> <ContextMenu>
<MenuItem Name="entryCtxMenuCopyUsername" Header="Copy username" Click="EntryContextMenuItem_Click"/> <MenuItem Name="entryCtxMenuCopyUsername" Header="Copy username" Click="EntryContextMenuItem_Click"/>
<MenuItem Name="entryCtxMenuCopyPassword" Header="Copy password" Click="EntryContextMenuItem_Click"/> <MenuItem Name="entryCtxMenuCopyPassword" Header="Copy password" Click="EntryContextMenuItem_Click"/>
<!-- Новый пункт меню "Edit" -->
<MenuItem Name="entryCtxMenuEdit" Header="Edit" Click="EntryContextMenuItem_Click"/> <MenuItem Name="entryCtxMenuEdit" Header="Edit" Click="EntryContextMenuItem_Click"/>
<MenuItem Name="entryCtxMenuDelete" Header="Delete" Click="EntryContextMenuItem_Click"/> <MenuItem Name="entryCtxMenuDelete" Header="Delete" Click="EntryContextMenuItem_Click"/>
</ContextMenu> </ContextMenu>
@@ -146,6 +153,7 @@
HorizontalAlignment="Center" HorizontalAlignment="Center"
VerticalAlignment="Center" VerticalAlignment="Center"
Spacing="10"> Spacing="10">
<TextBlock Text="Enter credentials to unlock" <TextBlock Text="Enter credentials to unlock"
Foreground="#2328C4" Foreground="#2328C4"
FontSize="32" /> FontSize="32" />
@@ -155,6 +163,7 @@
PasswordChar="*" PasswordChar="*"
Width="450" Width="450"
Loaded="UnlockPasswordEdit_Loaded"> Loaded="UnlockPasswordEdit_Loaded">
<TextBox.KeyBindings> <TextBox.KeyBindings>
<KeyBinding Gesture="Return" Command="{Binding TryUnlock}"/> <KeyBinding Gesture="Return" Command="{Binding TryUnlock}"/>
</TextBox.KeyBindings> </TextBox.KeyBindings>