From 6ea0d63eb3563c4b9301b0388abcca6da107c042 Mon Sep 17 00:00:00 2001 From: InspectorIT Date: Tue, 18 Nov 2025 17:05:06 +0300 Subject: [PATCH] Update MainWindow.axaml.cs --- src/KeyKeeper/Views/MainWindow.axaml.cs | 104 ++++++++++++++++++++++-- 1 file changed, 99 insertions(+), 5 deletions(-) diff --git a/src/KeyKeeper/Views/MainWindow.axaml.cs b/src/KeyKeeper/Views/MainWindow.axaml.cs index cf65309..4bd8192 100644 --- a/src/KeyKeeper/Views/MainWindow.axaml.cs +++ b/src/KeyKeeper/Views/MainWindow.axaml.cs @@ -1,11 +1,105 @@ +using Avalonia; using Avalonia.Controls; +using Avalonia.Input; +using Avalonia.Interactivity; +using Avalonia.Platform.Storage; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; -namespace KeyKeeper.Views; - -public partial class MainWindow : Window +namespace KeyKeeper.Views { - public MainWindow() + public partial class MainWindow : Window { - InitializeComponent(); + public MainWindow() + { + InitializeComponent(); + + LoadRecentVaults(); + } + + private void LoadRecentVaults() + { + var recentFiles = new List + { + new RecentVault { Path = "C:\\Users\\User\\Documents\\passwords.kdbx", LastOpened = DateTime.Now.AddDays(-1) }, + new RecentVault { Path = "C:\\Users\\User\\Desktop\\work_passwords.kdbx", LastOpened = DateTime.Now.AddDays(-3) } + }; + + RecentVaultsList.ItemsSource = recentFiles; + } + + private async void CreateNewVault_Click(object sender, RoutedEventArgs e) + { + var topLevel = TopLevel.GetTopLevel(this); + if (topLevel == null) return; + + var file = await topLevel.StorageProvider.SaveFilePickerAsync(new FilePickerSaveOptions + { + Title = "Создать новое хранилище паролей", + SuggestedFileName = "passwords.kdbx", + DefaultExtension = "kdbx", + FileTypeChoices = new[] + { + new FilePickerFileType("KeyKeeper Database") + { + Patterns = new[] { "*.kdbx" } + } + } + }); + + if (file != null) + { + // Здесь будет логика создания нового хранилища + ShowMessage($"Создание нового хранилища: {file.Name}"); + } + } + + private async void OpenExistingVault_Click(object sender, RoutedEventArgs e) + { + var topLevel = TopLevel.GetTopLevel(this); + if (topLevel == null) return; + + var files = await topLevel.StorageProvider.OpenFilePickerAsync(new FilePickerOpenOptions + { + Title = "Открыть хранилище паролей", + AllowMultiple = false, + FileTypeFilter = new[] + { + new FilePickerFileType("KeyKeeper Database") + { + Patterns = new[] { "*.kdbx", "*.kkdb" } + }, + new FilePickerFileType("KeePass Database") + { + Patterns = new[] { "*.kdbx" } + }, + new FilePickerFileType("All Files") + { + Patterns = new[] { "*.*" } + } + } + }); + + if (files.Count > 0) + { + var file = files[0]; + ShowMessage($"Открытие хранилища: {file.Name}"); + } + } + + private void ShowMessage(string message) + { + // Временное решение для показа сообщений + var messageBox = new Window + { + Title = "KeyKeeper", + Content = new TextBlock { Text = message, Margin = new Thickness(20) }, + SizeToContent = SizeToContent.WidthAndHeight, + WindowStartupLocation = WindowStartupLocation.CenterOwner + }; + messageBox.ShowDialog(this); + } } } \ No newline at end of file