Tidying up workspace, creating new layers

This commit is contained in:
2025-09-18 07:14:29 +02:00
parent b5be0db52b
commit e65f6c94af
13 changed files with 76 additions and 72 deletions

View 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
}
}

View File

@@ -0,0 +1,118 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<object class="AdwWindow" id="main_window">
<property name="width-request">350</property>
<property name="height-request">300</property>
<property name="default-width">800</property>
<property name="default-height">500</property>
<child>
<object class="AdwBreakpoint">
<condition>max-width: 500sp</condition>
<setter object="split_view" property="collapsed">True</setter>
<setter object="show_sidebar_button" property="visible">True</setter>
</object>
</child>
<property name="content">
<object class="AdwOverlaySplitView" id="split_view">
<property name="min-sidebar-width">300</property>
<property name="max-sidebar-width">300</property>
<property name="show-sidebar"
bind-source="show_sidebar_button"
bind-property="active"
bind-flags="sync-create|bidirectional"/>
<property name="sidebar">
<object class="AdwNavigationPage">
<property name="title" translatable="yes" context="label" comments="Noun. Marks a list of password collections.">Stores</property>
<property name="child">
<object class="AdwToolbarView">
<child type="top">
<object class="AdwHeaderBar">
<child type="start">
<object class="GtkButton" id="add_shortcut_button">
<property name="icon-name">list-add-symbolic</property>
<property name="valign">center</property>
<style>
<class name="flat" />
</style>
</object>
</child>
</object>
</child>
<property name="content">
<object class="AdwPreferencesPage">
<child>
<object class="AdwPreferencesGroup" id="shortcuts_group">
<!-- Dynamic rows will be added here via model binding -->
</object>
</child>
</object>
</property>
</object>
</property>
</object>
</property>
<property name="content">
<object class="AdwNavigationPage">
<property name="title" translatable="yes" context="label" comments="Noun, plural. Indicates the location of the actual decryptable passwords">Passwords</property>
<property name="child">
<object class="AdwToolbarView">
<child type="top">
<object class="AdwHeaderBar">
<child type="start">
<object class="GtkBox">
<property name="orientation">horizontal</property>
<property name="spacing">6</property>
<child>
<object class="GtkToggleButton" id="search_button">
<property name="icon-name">system-search-symbolic</property>
<!--<signal name="notify::active" handler="search_button_toggled_cb"/> -->
</object>
</child>
<child>
<object class="GtkToggleButton" id="show_sidebar_button">
<property name="icon-name">sidebar-show-symbolic</property>
<property name="active">True</property>
<property name="visible">False</property>
</object>
</child>
</object>
</child>
</object>
</child>
<property name="content">
<object class="AdwPreferencesPage">
<child>
<object class="AdwPreferencesGroup">
<property name="title">Default</property>
<property name="description">/home/typo/.password-store</property>
<property name="header-suffix">
<object class="GtkButton">
<property name="icon-name">list-add-symbolic</property>
<property name="valign">center</property>
<style>
<class name="flat" />
</style>
</object>
</property>
<child>
<object class="AdwActionRow">
<property name="title">Sample password</property>
</object>
</child>
<child>
<object class="AdwActionRow">
<property name="title">Sample password 2</property>
</object>
</child>
</object>
</child>
</object>
</property>
</object>
</property>
</object>
</property>
</object>
</property>
</object>
</interface>