Tidying up workspace, creating new layers
This commit is contained in:
68
App/UI/MainWindow/MainWindow.cs
Normal file
68
App/UI/MainWindow/MainWindow.cs
Normal file
@@ -0,0 +1,68 @@
|
||||
using Adw;
|
||||
using Keychain.UI.ViewModels;
|
||||
|
||||
namespace Keychain.UI;
|
||||
|
||||
public class MainWindow
|
||||
{
|
||||
public Window Window { get; }
|
||||
private PreferencesGroup shortcutsGroup;
|
||||
private PasswordStoreShortcutCollection shortcuts;
|
||||
|
||||
public MainWindow()
|
||||
{
|
||||
var builder = new Gtk.Builder("Keychain.UI.MainWindow.MainWindow.xml");
|
||||
|
||||
var window = builder.GetObject("main_window") as Window;
|
||||
if (window == null)
|
||||
{
|
||||
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 Gtk.Button;
|
||||
if (addButton == null)
|
||||
{
|
||||
throw new Exception("Failed to load UI element with ID: add_shortcut_button");
|
||||
}
|
||||
addButton.OnClicked += 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"));
|
||||
}
|
||||
|
||||
public void UpdateShortcutName(PasswordStoreShortcut shortcut, string newName)
|
||||
{
|
||||
shortcut.DisplayName = newName; // This will automatically update the UI row
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user