mirror of
https://github.com/KeyKeeperApp/KeyKeeper.git
synced 2026-05-12 03:16:29 +03:00
Design/Add CreateValutWindow
This commit is contained in:
69
src/KeyKeeper/Views/CreateVaultDialog.axaml
Normal file
69
src/KeyKeeper/Views/CreateVaultDialog.axaml
Normal 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>
|
||||||
76
src/KeyKeeper/Views/CreateVaultDialog.axaml.cs
Normal file
76
src/KeyKeeper/Views/CreateVaultDialog.axaml.cs
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -22,40 +22,27 @@ namespace KeyKeeper.Views
|
|||||||
|
|
||||||
private async void CreateNewVault_Click(object sender, RoutedEventArgs e)
|
private async void CreateNewVault_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
var file = await StorageProvider.SaveFilePickerAsync(new FilePickerSaveOptions
|
var fileDialog = new CreateVaultFileWindow();
|
||||||
{
|
await fileDialog.ShowDialog(this);
|
||||||
Title = "Create new password store",
|
|
||||||
SuggestedFileName = "passwords.kkp",
|
|
||||||
DefaultExtension = "kkp",
|
|
||||||
FileTypeChoices = new[]
|
|
||||||
{
|
|
||||||
new FilePickerFileType("KeyKeeper files")
|
|
||||||
{
|
|
||||||
Patterns = new[] { "*.kkp" }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
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();
|
var compositeKey = new CompositeKey(passwordDialog.Password, null);
|
||||||
await passwordDialog.ShowDialog(this);
|
var passStoreAccessor = new PassStoreFileAccessor(
|
||||||
if (passwordDialog.Created && !string.IsNullOrEmpty(passwordDialog.Password))
|
filename: path,
|
||||||
{
|
create: true,
|
||||||
var compositeKey = new CompositeKey(passwordDialog.Password, null);
|
createOptions: new StoreCreationOptions()
|
||||||
var passStoreAccessor = new PassStoreFileAccessor(
|
{
|
||||||
filename: path,
|
Key = compositeKey,
|
||||||
create: true,
|
LockTimeoutSeconds = 800
|
||||||
createOptions: new StoreCreationOptions()
|
});
|
||||||
{
|
IPassStore passStore = passStoreAccessor;
|
||||||
Key = compositeKey,
|
OpenRepositoryWindow(passStore);
|
||||||
LockTimeoutSeconds = 800
|
|
||||||
});
|
|
||||||
IPassStore passStore = passStoreAccessor;
|
|
||||||
OpenRepositoryWindow(passStore);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user