Sidebar shortcuts bound
This commit is contained in:
@@ -1,21 +1,69 @@
|
||||
namespace App.UI;
|
||||
using Adw;
|
||||
using App.UI.Models;
|
||||
|
||||
public class MainWindow
|
||||
{
|
||||
public Adw.Window Window { get; }
|
||||
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");
|
||||
|
||||
public MainWindow()
|
||||
{
|
||||
var assembly = typeof(MainWindow).Assembly;
|
||||
using var stream = assembly.GetManifestResourceStream("App.UI.MainWindow.xml");
|
||||
if (stream == null)
|
||||
throw new Exception("Failed to load embedded resource MainWindow.xml");
|
||||
using var reader = new System.IO.StreamReader(stream);
|
||||
var xml = reader.ReadToEnd();
|
||||
var builder = Gtk.Builder.NewFromString(xml, -1);
|
||||
var window = builder.GetObject("main_window") as Adw.Window;
|
||||
var window = builder.GetObject("main_window") as Window;
|
||||
if (window == null)
|
||||
throw new Exception("Failed to load main_window from MainWindow.ui");
|
||||
{
|
||||
throw new Exception("Failed to load embedded resource MainWindow.xml");
|
||||
}
|
||||
Window = window;
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user