diff --git a/src/KeyKeeper/Views/CreateVaultDialog.axaml b/src/KeyKeeper/Views/CreateVaultDialog.axaml
new file mode 100644
index 0000000..ec10c2e
--- /dev/null
+++ b/src/KeyKeeper/Views/CreateVaultDialog.axaml
@@ -0,0 +1,93 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/KeyKeeper/Views/CreateVaultDialog.axaml.cs b/src/KeyKeeper/Views/CreateVaultDialog.axaml.cs
new file mode 100644
index 0000000..4f908ab
--- /dev/null
+++ b/src/KeyKeeper/Views/CreateVaultDialog.axaml.cs
@@ -0,0 +1,124 @@
+using Avalonia;
+using Avalonia.Controls;
+using Avalonia.Interactivity;
+using Avalonia.Platform.Storage;
+using System;
+using System.Threading.Tasks;
+
+namespace KeyKeeper.Views
+{
+ public partial class CreateVaultFileWindow : Window
+ {
+ public string FilePath { get; private set; } = string.Empty;
+ public string Password { get; private set; } = string.Empty;
+ public bool Success { get; private set; }
+
+ public CreateVaultFileWindow()
+ {
+ InitializeComponent();
+#if DEBUG
+ this.AttachDevTools();
+#endif
+ FilePathTextBox.TextChanged += OnTextChanged;
+ PasswordBox.TextChanged += OnPasswordTextChanged;
+ ConfirmPasswordBox.TextChanged += OnPasswordTextChanged;
+ }
+
+ private async void OnTextChanged(object? sender, TextChangedEventArgs e)
+ {
+ UpdateCreateButtonState();
+ PathWarning.Text = "";
+
+ string path = FilePathTextBox.Text ?? "";
+ if (string.IsNullOrWhiteSpace(path))
+ return;
+
+ try
+ {
+ var storageFile = await StorageProvider.TryGetFileFromPathAsync(path);
+ if (storageFile != null)
+ {
+ PathWarning.Text = "File already exists. It will be overwritten.";
+ }
+ }
+ catch
+ {
+ }
+ }
+
+ private void OnPasswordTextChanged(object? sender, TextChangedEventArgs e)
+ {
+ UpdateCreateButtonState();
+ PasswordErrorText.IsVisible = false;
+ }
+
+ private void UpdateCreateButtonState()
+ {
+ bool pathValid = !string.IsNullOrWhiteSpace(FilePathTextBox.Text);
+ bool passwordsEntered = !string.IsNullOrWhiteSpace(PasswordBox.Text) &&
+ !string.IsNullOrWhiteSpace(ConfirmPasswordBox.Text);
+ CreateButton.IsEnabled = pathValid && passwordsEntered;
+ }
+
+ 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?.TryGetLocalPath() is string path)
+ {
+ FilePathTextBox.Text = path;
+ }
+ }
+
+ private void CreateButton_Click(object? sender, RoutedEventArgs e)
+ {
+ string path = FilePathTextBox.Text ?? "";
+ if (string.IsNullOrWhiteSpace(path))
+ return;
+
+ string password = PasswordBox.Text ?? "";
+ string confirm = ConfirmPasswordBox.Text ?? "";
+
+ if (string.IsNullOrEmpty(password) || string.IsNullOrEmpty(confirm))
+ {
+ ShowPasswordError("Password cannot be empty");
+ return;
+ }
+
+ if (password != confirm)
+ {
+ ShowPasswordError("Passwords don't match");
+ return;
+ }
+
+ FilePath = path;
+ Password = password;
+ Success = true;
+ Close();
+ }
+
+ private void ShowPasswordError(string message)
+ {
+ PasswordErrorText.Text = message;
+ PasswordErrorText.IsVisible = true;
+ }
+
+ private void CancelButton_Click(object? sender, RoutedEventArgs e)
+ {
+ Success = false;
+ Close();
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/KeyKeeper/Views/MainWindow.axaml.cs b/src/KeyKeeper/Views/MainWindow.axaml.cs
index ca63511..ee8549a 100644
--- a/src/KeyKeeper/Views/MainWindow.axaml.cs
+++ b/src/KeyKeeper/Views/MainWindow.axaml.cs
@@ -22,41 +22,26 @@ 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 createVaultDialog = new CreateVaultFileWindow();
+ await createVaultDialog.ShowDialog(this);
- if (file != null)
+ if (createVaultDialog.Success &&
+ !string.IsNullOrEmpty(createVaultDialog.FilePath) &&
+ !string.IsNullOrEmpty(createVaultDialog.Password))
{
- if (file.TryGetLocalPath() is string path)
- {
- var passwordDialog = new PasswordDialog();
- await passwordDialog.ShowDialog(this);
- if (passwordDialog.Created && !string.IsNullOrEmpty(passwordDialog.Password))
+ var path = createVaultDialog.FilePath;
+ var password = createVaultDialog.Password;
+ var compositeKey = new CompositeKey(password, null);
+ var passStoreAccessor = new PassStoreFileAccessor(
+ filename: path,
+ create: true,
+ createOptions: new StoreCreationOptions()
{
- 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);
- }
- }
+ Key = compositeKey,
+ LockTimeoutSeconds = 800
+ });
+ IPassStore passStore = passStoreAccessor;
+ OpenRepositoryWindow(passStore);
}
}
diff --git a/src/KeyKeeper/Views/PasswordDialog.axaml b/src/KeyKeeper/Views/PasswordDialog.axaml
deleted file mode 100644
index 27b58c2..0000000
--- a/src/KeyKeeper/Views/PasswordDialog.axaml
+++ /dev/null
@@ -1,54 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/KeyKeeper/Views/PasswordDialog.axaml.cs b/src/KeyKeeper/Views/PasswordDialog.axaml.cs
deleted file mode 100644
index 7e15c00..0000000
--- a/src/KeyKeeper/Views/PasswordDialog.axaml.cs
+++ /dev/null
@@ -1,65 +0,0 @@
-using Avalonia;
-using Avalonia.Controls;
-using Avalonia.Markup.Xaml;
-using Avalonia.Interactivity;
-
-namespace KeyKeeper.Views
-{
- public partial class PasswordDialog : Window
- {
- public string Password { get; private set; } = "";
- public bool Created { get; private set; } = false;
-
- public PasswordDialog()
- {
- InitializeComponent();
- }
-
- private void InitializeComponent()
- {
- AvaloniaXamlLoader.Load(this);
- }
-
- private void CreateButton_Click(object sender, RoutedEventArgs e)
- {
- var passwordBox = this.FindControl("PasswordBox");
- var confirmBox = this.FindControl("ConfirmPasswordBox");
- var errorText = this.FindControl("ErrorText");
-
- string password = passwordBox?.Text ?? "";
- string confirmPassword = confirmBox?.Text ?? "";
-
- if (string.IsNullOrEmpty(password) || string.IsNullOrEmpty(confirmPassword))
- {
- ShowError("Password cannot be empty");
- return;
- }
-
- if (password != confirmPassword)
- {
- ShowError("Passwords don't match");
- return;
- }
-
- Password = password;
- Created = true;
- Close();
- }
-
- private void ShowError(string message)
- {
- var errorText = this.FindControl("ErrorText");
- if (errorText != null)
- {
- errorText.Text = message;
- errorText.IsVisible = true;
- }
- }
-
- private void CancelButton_Click(object sender, RoutedEventArgs e)
- {
- Created = false;
- Close();
- }
- }
-}
diff --git a/src/KeyKeeper/Views/RepositoryWindow.axaml b/src/KeyKeeper/Views/RepositoryWindow.axaml
index 1bf3b0d..d92b230 100644
--- a/src/KeyKeeper/Views/RepositoryWindow.axaml
+++ b/src/KeyKeeper/Views/RepositoryWindow.axaml
@@ -28,7 +28,7 @@
Margin="0,0,0,20"/>
-
-
+ -->