Design/Add CreateValutWindow

This commit is contained in:
Быстров Михаил Евгеньевич
2026-02-25 18:45:18 +03:00
parent 90e583dfc9
commit 74e80c8485
3 changed files with 163 additions and 31 deletions

View File

@@ -0,0 +1,69 @@
<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="600" d:DesignHeight="400"
x:Class="KeyKeeper.Views.CreateVaultFileWindow"
Title="Create New Vault"
Background="#fff"
Icon="/Assets/icon.ico"
Width="600" Height="400"
WindowStartupLocation="CenterOwner"
CanResize="False"
x:Name="ThisWindow">
<Grid ColumnDefinitions="1.5*, 2*">
<!-- <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> (<28><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>) -->
<Border Background="#2328C4" Grid.Column="0">
<StackPanel VerticalAlignment="Center" Margin="20">
<TextBlock Text="Choose where to save your password database"
TextWrapping="Wrap"
Foreground="#E0E0FF"
FontSize="20"
TextAlignment="Center"/>
</StackPanel>
</Border>
<!-- <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> -->
<StackPanel Grid.Column="1" Margin="30" VerticalAlignment="Center" Spacing="20">
<TextBlock Text="File location"
FontSize="22"
FontWeight="Bold"
Foreground="#2328C4"/>
<Grid ColumnDefinitions="*, Auto" RowDefinitions="Auto" ColumnSpacing="10">
<TextBox x:Name="FilePathTextBox"
Grid.Column="0"
Watermark="Select file path..."
Text="{Binding #ThisWindow.FilePath, Mode=TwoWay}"
Padding="10,8"/>
<Button x:Name="BrowseButton"
Grid.Column="1"
Content="Browse..."
Classes="secondaryButton"
Padding="15,8"
Click="BrowseButton_Click"/>
</Grid>
<!-- <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> -->
<TextBlock x:Name="PathWarning"
FontSize="12"
Foreground="Orange"
Text=" " />
<!-- <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> -->
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Spacing="10" Margin="0,20,0,0">
<Button Content="Cancel"
Classes="secondaryButton"
Width="80"
Click="CancelButton_Click"/>
<Button x:Name="CreateButton"
Content="Next"
Classes="accentButton"
Width="80"
IsEnabled="False"
Click="CreateButton_Click"/>
</StackPanel>
</StackPanel>
</Grid>
</Window>

View File

@@ -0,0 +1,76 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Platform.Storage;
using System;
using System.IO;
namespace KeyKeeper.Views
{
public partial class CreateVaultFileWindow : Window
{
public string FilePath { get; private set; } = string.Empty;
public bool Success { get; private set; }
public CreateVaultFileWindow()
{
InitializeComponent();
#if DEBUG
this.AttachDevTools();
#endif
FilePathTextBox.TextChanged += OnTextChanged;
}
private void OnTextChanged(object? sender, TextChangedEventArgs e)
{
string path = FilePathTextBox.Text ?? "";
CreateButton.IsEnabled = !string.IsNullOrWhiteSpace(path);
if (!string.IsNullOrWhiteSpace(path) && File.Exists(path))
{
PathWarning.Text = "File already exists. It will be overwritten.";
}
else
{
PathWarning.Text = "";
}
}
private async void BrowseButton_Click(object? sender, RoutedEventArgs e)
{
var file = await StorageProvider.SaveFilePickerAsync(new FilePickerSaveOptions
{
Title = "Create new password store",
SuggestedFileName = "passwords.kkp",
DefaultExtension = "kkp",
FileTypeChoices = new[]
{
new FilePickerFileType("KeyKeeper files")
{
Patterns = new[] { "*.kkp" }
}
}
});
if (file != null && file.TryGetLocalPath() is string path)
{
FilePathTextBox.Text = path;
}
}
private void CreateButton_Click(object? sender, RoutedEventArgs e)
{
FilePath = FilePathTextBox.Text ?? "";
if (string.IsNullOrWhiteSpace(FilePath)) return;
Success = true;
Close();
}
private void CancelButton_Click(object? sender, RoutedEventArgs e)
{
Success = false;
Close();
}
}
}

View File

@@ -22,40 +22,27 @@ namespace KeyKeeper.Views
private async void CreateNewVault_Click(object sender, RoutedEventArgs e)
{
var file = await StorageProvider.SaveFilePickerAsync(new FilePickerSaveOptions
{
Title = "Create new password store",
SuggestedFileName = "passwords.kkp",
DefaultExtension = "kkp",
FileTypeChoices = new[]
{
new FilePickerFileType("KeyKeeper files")
{
Patterns = new[] { "*.kkp" }
}
}
});
var fileDialog = new CreateVaultFileWindow();
await fileDialog.ShowDialog(this);
if (file != null)
if (fileDialog.Success && !string.IsNullOrEmpty(fileDialog.FilePath))
{
if (file.TryGetLocalPath() is string path)
var path = fileDialog.FilePath;
var passwordDialog = new PasswordDialog();
await passwordDialog.ShowDialog(this);
if (passwordDialog.Created && !string.IsNullOrEmpty(passwordDialog.Password))
{
var passwordDialog = new PasswordDialog();
await passwordDialog.ShowDialog(this);
if (passwordDialog.Created && !string.IsNullOrEmpty(passwordDialog.Password))
{
var compositeKey = new CompositeKey(passwordDialog.Password, null);
var passStoreAccessor = new PassStoreFileAccessor(
filename: path,
create: true,
createOptions: new StoreCreationOptions()
{
Key = compositeKey,
LockTimeoutSeconds = 800
});
IPassStore passStore = passStoreAccessor;
OpenRepositoryWindow(passStore);
}
var compositeKey = new CompositeKey(passwordDialog.Password, null);
var passStoreAccessor = new PassStoreFileAccessor(
filename: path,
create: true,
createOptions: new StoreCreationOptions()
{
Key = compositeKey,
LockTimeoutSeconds = 800
});
IPassStore passStore = passStoreAccessor;
OpenRepositoryWindow(passStore);
}
}
}