From daed253eb4c64d24a36c58cb334eae0de311e072 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miskolczi=20Rich=C3=A1rd?= Date: Tue, 30 Sep 2025 19:10:26 +0200 Subject: [PATCH] Split MainWindow.cs based on purpose --- src/App/UI/MainWindow/MainWindow.cs | 80 +++++++++--------------- src/App/UI/MainWindow/ShortcutSidebar.cs | 31 +++++++++ 2 files changed, 62 insertions(+), 49 deletions(-) create mode 100644 src/App/UI/MainWindow/ShortcutSidebar.cs diff --git a/src/App/UI/MainWindow/MainWindow.cs b/src/App/UI/MainWindow/MainWindow.cs index a71b361..2249962 100644 --- a/src/App/UI/MainWindow/MainWindow.cs +++ b/src/App/UI/MainWindow/MainWindow.cs @@ -4,22 +4,16 @@ using Logic; namespace Keychain.UI; -public class MainWindow +public partial class MainWindow { - public Window Window { get; } - private PreferencesGroup shortcutsGroup; + public Window Window { get; private set; } private PasswordList passwordCollection; - private PasswordStoreShortcutCollection shortcuts; + private PreferencesGroup passwordList; private Gtk.ToggleButton searchToggleButton; private Gtk.Stack titleStack; private Gtk.SearchEntry searchEntry; - private PreferencesGroup passwordList; - - private readonly IPasswordStoreService passwordStoreService; private const string windowId = "main_window"; - private const string shortcutsGroupId = "shortcuts_group"; - private const string addShortcutButtonId = "add_shortcut_button"; private const string searchToggleButtonId = "search_button"; private const string titleStackId = "title_stack"; private const string searchEntryId = "search_entry"; @@ -28,9 +22,35 @@ public class MainWindow public MainWindow(IPasswordStoreService passwordStoreService) { this.passwordStoreService = passwordStoreService; + + BindUIElements(); + + // Initialize the observable collection with property binding + shortcuts = new PasswordStoreShortcutCollection(shortcutsGroup, passwordStoreService); + if (shortcuts.Count == 0) + { + LoadDefaultShortcuts(); + } + + passwordCollection = new PasswordList(passwordList); + } + + private void SetSearchBarVisible(object sender, EventArgs e) + { + if (searchToggleButton.Active) + { + titleStack.SetVisibleChildName("Search"); + searchEntry.GrabFocus(); + } + else + { + titleStack.SetVisibleChildName("Passwords"); + } + } + + private void BindUIElements() + { var builder = new Gtk.Builder("Keychain.UI.MainWindow.MainWindow.xml"); - - Window = builder.GetObject(windowId) as Window; if (Window == null) { @@ -88,43 +108,5 @@ public class MainWindow { throw new Exception("Failed to load UI element with ID: " + e.Message); } - - // Initialize the observable collection with property binding - shortcuts = new PasswordStoreShortcutCollection(shortcutsGroup, passwordStoreService); - if (shortcuts.Count == 0) - { - LoadDefaultShortcuts(); - } - - passwordCollection = new PasswordList(passwordList); - } - - private void OnAddShortcutClicked(object sender, EventArgs e) - { - var dialog = new AddShortcutWindow(shortcuts).Dialog; - dialog.Present(Window); - } - - private void LoadDefaultShortcuts() - { - shortcuts.Add(new PasswordStoreViewModel(displayName: "Default", path: Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + "/.password_store")); - } - - // private void UpdateShortcutName(PasswordStoreViewModel shortcut, string newName) - // { - // shortcut.DisplayName = newName; // This will automatically update the UI row - // } - - private void SetSearchBarVisible(object sender, EventArgs e) - { - if (searchToggleButton.Active) - { - titleStack.SetVisibleChildName("Search"); - searchEntry.GrabFocus(); - } - else - { - titleStack.SetVisibleChildName("Passwords"); - } } } \ No newline at end of file diff --git a/src/App/UI/MainWindow/ShortcutSidebar.cs b/src/App/UI/MainWindow/ShortcutSidebar.cs new file mode 100644 index 0000000..5e39436 --- /dev/null +++ b/src/App/UI/MainWindow/ShortcutSidebar.cs @@ -0,0 +1,31 @@ +using Adw; +using Keychain.ViewModels; +using Logic; + +namespace Keychain.UI; + +public partial class MainWindow +{ + private readonly IPasswordStoreService passwordStoreService; + + private PreferencesGroup shortcutsGroup; + private PasswordStoreShortcutCollection shortcuts; + private const string shortcutsGroupId = "shortcuts_group"; + private const string addShortcutButtonId = "add_shortcut_button"; + + private void OnAddShortcutClicked(object sender, EventArgs e) + { + var dialog = new AddShortcutWindow(shortcuts).Dialog; + dialog.Present(Window); + } + + private void LoadDefaultShortcuts() + { + shortcuts.Add(new PasswordStoreViewModel(displayName: "Default", path: Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + "/.password_store")); + } + + // private void UpdateShortcutName(PasswordStoreViewModel shortcut, string newName) + // { + // shortcut.DisplayName = newName; // This will automatically update the UI row + // } +}