From 22ad11add1e5c49d75528a06cabf53722aac287a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miskolczi=20Rich=C3=A1rd?= Date: Fri, 26 Sep 2025 11:02:37 +0200 Subject: [PATCH] Started implementing proper ViewModels now that the backend is mostly done --- App/UI/MainWindow/MainWindow.cs | 4 +- App/ViewModels/PasswordStoreShortcut.cs | 46 ------------------- .../PasswordStoreShortcutCollection.cs | 12 ++--- App/ViewModels/PasswordStoreViewModel.cs | 30 ++++++++++++ 4 files changed, 38 insertions(+), 54 deletions(-) delete mode 100644 App/ViewModels/PasswordStoreShortcut.cs create mode 100644 App/ViewModels/PasswordStoreViewModel.cs diff --git a/App/UI/MainWindow/MainWindow.cs b/App/UI/MainWindow/MainWindow.cs index fece2e9..664728b 100644 --- a/App/UI/MainWindow/MainWindow.cs +++ b/App/UI/MainWindow/MainWindow.cs @@ -92,7 +92,7 @@ public class MainWindow shortcuts.Add(newShortcut); // This will automatically update the UI } - private void RemoveShortcut(PasswordStoreShortcut shortcut) + private void RemoveShortcut(PasswordStoreViewModel shortcut) { shortcuts.Remove(shortcut); // This will automatically update the UI } @@ -102,7 +102,7 @@ public class MainWindow shortcuts.Add(new PasswordStoreShortcut(displayName: "Default", path: Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + "/.password_store")); } - private void UpdateShortcutName(PasswordStoreShortcut shortcut, string newName) + private void UpdateShortcutName(PasswordStoreViewModel shortcut, string newName) { shortcut.DisplayName = newName; // This will automatically update the UI row } diff --git a/App/ViewModels/PasswordStoreShortcut.cs b/App/ViewModels/PasswordStoreShortcut.cs deleted file mode 100644 index 6437ae0..0000000 --- a/App/ViewModels/PasswordStoreShortcut.cs +++ /dev/null @@ -1,46 +0,0 @@ -using System.ComponentModel; -using Logic; - -namespace Keychain.ViewModels; - -public class PasswordStoreShortcut : INotifyPropertyChanged -{ - private IPasswordStoreService passwordService; - public event PropertyChangedEventHandler? PropertyChanged; - - public string DisplayName - { - get => displayName; - set - { - displayName = value; - displayNameSet = true; - PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(DisplayName))); - } - } - - public string? IconName - { - get => iconName; - set { iconName = value; PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(IconName))); } - } - - public string Path - { - get => path; - } - - public PasswordStoreShortcut(string path, string iconName = "text-x-generic-symbolic", string? displayName = null) - { - this.path = path; - - this.iconName = iconName; - - this.displayName = path; - - if (displayName != null) - { - DisplayName = displayName; - } - } -} diff --git a/App/ViewModels/PasswordStoreShortcutCollection.cs b/App/ViewModels/PasswordStoreShortcutCollection.cs index ba79899..d81d041 100644 --- a/App/ViewModels/PasswordStoreShortcutCollection.cs +++ b/App/ViewModels/PasswordStoreShortcutCollection.cs @@ -5,10 +5,10 @@ using Gtk; using System.Collections.ObjectModel; using System.Collections.Specialized; -public class PasswordStoreShortcutCollection : ObservableCollection +public class PasswordStoreShortcutCollection : ObservableCollection { private readonly PreferencesGroup shortcutsGroup; - private readonly Dictionary itemToRowMap = new(); + private readonly Dictionary itemToRowMap = new(); public PasswordStoreShortcutCollection(PreferencesGroup shortcutsGroup) { @@ -21,7 +21,7 @@ public class PasswordStoreShortcutCollection : ObservableCollection _model.DisplayName; + } + + public string? IconName + { + get => _model.IconName; + } + + public string Path + { + get => _model.Path; + } + + public PasswordStoreViewModel(PasswordStore item) + { + _model = item; + } +}