Adding new window for adding password stores

This commit is contained in:
2025-09-18 14:46:25 +02:00
parent e65f6c94af
commit a2f19dc189
4 changed files with 145 additions and 14 deletions

View File

@@ -14,6 +14,7 @@
<ItemGroup>
<EmbeddedResource Include="UI/MainWindow/MainWindow.xml" />
<EmbeddedResource Include="UI/AddShortcutWindow/AddShortcutWindow.xml" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,41 @@
using Adw;
namespace Keychain.UI;
public class AddShortcutWindow
{
public Window Window { get; }
private EntryRow? pathEntry;
private Gtk.Button? browseButton;
public AddShortcutWindow()
{
var builder = new Gtk.Builder("Keychain.UI.AddShortcutWindow.AddShortcutWindow.xml");
var window = builder.GetObject("add_shortcut_window") as Window;
if (window == null)
{
throw new Exception("Failed to load embedded resource AddShortcutWindow.xml");
}
Window = window;
browseButton = builder.GetObject("folder_browse_button") as Gtk.Button;
if (browseButton == null)
{
throw new Exception("Failed to load UI element with ID: folder_browse_button");
}
browseButton.OnClicked += BrowseFolder;
}
private async void BrowseFolder(object sender, EventArgs e)
{
var fileDialog = new Gtk.FileDialog();
var selectedFolder = await fileDialog.SelectFolderAsync(Window);
if (selectedFolder != null)
{
var buttonContent = (ButtonContent)browseButton.Child;
buttonContent.Label = selectedFolder.GetPath();
}
}
}

View File

@@ -0,0 +1,87 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<object class="AdwWindow" id="add_shortcut_window">
<property name="width-request">350</property>
<property name="height-request">300</property>
<property name="default-width">500</property>
<property name="default-height">600</property>
<child>
<object class="AdwBreakpoint">
<condition>max-width: 500sp</condition>
</object>
</child>
<property name="content">
<object class="AdwToolbarView">
<child type="top">
<object class="AdwHeaderBar">
</object>
</child>
<property name="content">
<object class="AdwPreferencesPage">
<child>
<object class="AdwPreferencesGroup" id="shortcuts_group">
<property name="title" translatable="yes" context="label" comments="Verb. Marks a preferences page where the user can add new password stores. Store as in storage">Add New Store</property>
<child>
<object class="AdwEntryRow">
<property name="title" translatable="yes" context="Input field placeholder" comments="Noun. Tells the user that the display name of the new password store is to be supplied here">Name</property>
</object>
</child>
<child>
<object class="AdwActionRow">
<property name="title">Icon</property>
<child>
<object class="GtkButton" id="icon_picker_button">
<property name="valign">center</property>
<child>
<object class="AdwButtonContent">
<property name="icon-name">emoji-symbols-symbolic</property>
</object>
</child>
</object>
</child>
</object>
</child>
<child>
<object class="AdwActionRow">
<property name="title" translatable="yes" context="Label" comments="Noun. Marks a button that allows the user to pick a folder where the new store will be.">Location</property>
<child>
<object class="GtkBox">
<property name="orientation">horizontal</property>
<property name="spacing">6</property>
<child>
<object class="GtkButton" id="folder_browse_button">
<property name="valign">center</property>
<child>
<object class="AdwButtonContent">
<property name="icon-name">document-open-symbolic</property>
<property name="label">Browse</property>
</object>
</child>
</object>
</child>
<child>
<object class="GtkButton" id="clear_selected_folder_button">
<property name="valign">center</property>
<property name="sensitive">0</property>
<style>
<class name="flat" />
</style>
<child>
<object class="AdwButtonContent">
<property name="icon-name">user-trash-symbolic</property>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</property>
</object>
</property>
</object>
</interface>

View File

@@ -7,11 +7,11 @@ public class MainWindow
{
public Window Window { get; }
private PreferencesGroup shortcutsGroup;
private PasswordStoreShortcutCollection shortcuts;
private PasswordStoreShortcutCollection shortcuts;
public MainWindow()
{
var builder = new Gtk.Builder("Keychain.UI.MainWindow.MainWindow.xml");
public MainWindow()
{
var builder = new Gtk.Builder("Keychain.UI.MainWindow.MainWindow.xml");
var window = builder.GetObject("main_window") as Window;
if (window == null)
@@ -19,30 +19,32 @@ public class MainWindow
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)
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;
}
addButton.OnClicked += OnAddShortcutClicked;
// Initialize the observable collection with property binding
shortcuts = new PasswordStoreShortcutCollection(shortcutsGroup);
LoadDefaultShortcuts();
shortcuts = new PasswordStoreShortcutCollection(shortcutsGroup);
LoadDefaultShortcuts();
}
private void OnAddShortcutClicked(object sender, EventArgs e)
{
AddShortcut("/path/to/location");
var window = new AddShortcutWindow().Window;
window.Application = Window.Application;
window.Show();
}
public void AddShortcut(string path)