using Avalonia; using Avalonia.Controls; using Avalonia.Interactivity; using Avalonia.Media; using Project.Controller; using Project.Model; using Project.Persistence; namespace Project.View; public partial class MenuView : Window { readonly AppController? _controller; public MenuView() { InitializeComponent(); CreateEntryButtons(); } public MenuView(AppController controller) { InitializeComponent(); _controller = controller; } private async void NewEntryButton_OnClick(object? sender, Avalonia.Interactivity.RoutedEventArgs e) { var newEntryWindow = new NewEntry(); newEntryWindow.Show(); } private void CreateEntryButtons() { // dynamically creating buttons for each entry entriesContainer.Children.Clear(); // Clear existing buttons var entries = SQLite.GetEntries(AppController._currentUser); foreach (var entry in entries) { var button = new Button { Content = entry.Name, // Display the entry name on the button Margin = new Thickness(5), Padding = new Thickness(10), Width = 200, Background = Brushes.SlateGray, }; // add click handler for the button button.Click += (object? sender, Avalonia.Interactivity.RoutedEventArgs e) => EntryDetails(entry); // Add the button to your container entriesContainer.Children.Add(button); } } //refreshing the buttons when saving a new entry public void AfterSavingNewEntry() { CreateEntryButtons(); } public void EntryDetails(SavedEntries entry) { ShowEntryDetails.Children.Clear(); ShowEntryDetails.Children.Add(new TextBlock { Text = $"Name: {entry.Name}", Margin = new Thickness(0, 0, 0, 5) }); ShowEntryDetails.Children.Add(new TextBlock { Text = $"Email/Username: {entry.MailUsername}", Margin = new Thickness(0, 0, 0, 5) }); ShowEntryDetails.Children.Add(new TextBlock { Text = $"URL: {entry.Url}", Margin = new Thickness(0, 0, 0, 5) }); ShowEntryDetails.Children.Add(new TextBlock { Text = $"Password: {Crypto.DecryptPassword(entry.Pass)}", Margin = new Thickness(0, 0, 0, 5) }); if (!string.IsNullOrEmpty(entry.Note)) { ShowEntryDetails.Children.Add(new TextBlock { Text = $"Note: {entry.Note}", Margin = new Thickness(0, 0, 0, 5) }); } } }