2025-09-17 12:49:05 +02:00
|
|
|
using Adw;
|
|
|
|
|
using App.UI.Models;
|
2025-09-13 17:36:46 +02:00
|
|
|
|
2025-09-17 12:49:05 +02:00
|
|
|
namespace App.UI;
|
|
|
|
|
|
|
|
|
|
public class MainWindow
|
|
|
|
|
{
|
|
|
|
|
public Window Window { get; }
|
|
|
|
|
private PreferencesGroup shortcutsGroup;
|
|
|
|
|
private PasswordStoreShortcutCollection shortcuts;
|
|
|
|
|
|
|
|
|
|
public MainWindow()
|
|
|
|
|
{
|
|
|
|
|
var builder = new Gtk.Builder("App.UI.MainWindow.xml");
|
2025-09-13 17:36:46 +02:00
|
|
|
|
2025-09-17 12:49:05 +02:00
|
|
|
var window = builder.GetObject("main_window") as Window;
|
2025-09-13 17:36:46 +02:00
|
|
|
if (window == null)
|
2025-09-17 12:49:05 +02:00
|
|
|
{
|
|
|
|
|
throw new Exception("Failed to load embedded resource MainWindow.xml");
|
|
|
|
|
}
|
2025-09-13 17:36:46 +02:00
|
|
|
Window = window;
|
2025-09-17 12:49:05 +02:00
|
|
|
|
|
|
|
|
var group = builder.GetObject("shortcuts_group") as PreferencesGroup;
|
|
|
|
|
if (group == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Failed to load UI element with ID: shortcuts_group");
|
|
|
|
|
}
|
|
|
|
|
shortcutsGroup = group;
|
|
|
|
|
|
|
|
|
|
var addButton = builder.GetObject("add_shortcut_button") as ActionRow;
|
|
|
|
|
if (addButton == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Failed to load UI element with ID: add_shortcut_button");
|
|
|
|
|
}
|
|
|
|
|
addButton.OnActivated += OnAddShortcutClicked;
|
|
|
|
|
|
|
|
|
|
// Initialize the observable collection with property binding
|
|
|
|
|
shortcuts = new PasswordStoreShortcutCollection(shortcutsGroup);
|
|
|
|
|
|
|
|
|
|
LoadDefaultShortcuts();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnAddShortcutClicked(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
AddShortcut("/path/to/location");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void AddShortcut(string path)
|
|
|
|
|
{
|
|
|
|
|
var newShortcut = new PasswordStoreShortcut(path:path);
|
|
|
|
|
shortcuts.Add(newShortcut); // This will automatically update the UI
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RemoveShortcut(PasswordStoreShortcut shortcut)
|
|
|
|
|
{
|
|
|
|
|
shortcuts.Remove(shortcut); // This will automatically update the UI
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void LoadDefaultShortcuts()
|
|
|
|
|
{
|
|
|
|
|
shortcuts.Add(new PasswordStoreShortcut(displayName:"Default", path:Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)+"/.password_store"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Example of reactive property updates
|
|
|
|
|
public void UpdateShortcutName(PasswordStoreShortcut shortcut, string newName)
|
|
|
|
|
{
|
|
|
|
|
shortcut.DisplayName = newName; // This will automatically update the UI row
|
|
|
|
|
}
|
2025-09-13 17:36:46 +02:00
|
|
|
}
|