Split MainWindow.cs based on purpose
This commit is contained in:
@@ -4,22 +4,16 @@ using Logic;
|
|||||||
|
|
||||||
namespace Keychain.UI;
|
namespace Keychain.UI;
|
||||||
|
|
||||||
public class MainWindow
|
public partial class MainWindow
|
||||||
{
|
{
|
||||||
public Window Window { get; }
|
public Window Window { get; private set; }
|
||||||
private PreferencesGroup shortcutsGroup;
|
|
||||||
private PasswordList passwordCollection;
|
private PasswordList passwordCollection;
|
||||||
private PasswordStoreShortcutCollection shortcuts;
|
private PreferencesGroup passwordList;
|
||||||
private Gtk.ToggleButton searchToggleButton;
|
private Gtk.ToggleButton searchToggleButton;
|
||||||
private Gtk.Stack titleStack;
|
private Gtk.Stack titleStack;
|
||||||
private Gtk.SearchEntry searchEntry;
|
private Gtk.SearchEntry searchEntry;
|
||||||
private PreferencesGroup passwordList;
|
|
||||||
|
|
||||||
private readonly IPasswordStoreService passwordStoreService;
|
|
||||||
|
|
||||||
private const string windowId = "main_window";
|
private const string windowId = "main_window";
|
||||||
private const string shortcutsGroupId = "shortcuts_group";
|
|
||||||
private const string addShortcutButtonId = "add_shortcut_button";
|
|
||||||
private const string searchToggleButtonId = "search_button";
|
private const string searchToggleButtonId = "search_button";
|
||||||
private const string titleStackId = "title_stack";
|
private const string titleStackId = "title_stack";
|
||||||
private const string searchEntryId = "search_entry";
|
private const string searchEntryId = "search_entry";
|
||||||
@@ -28,9 +22,35 @@ public class MainWindow
|
|||||||
public MainWindow(IPasswordStoreService passwordStoreService)
|
public MainWindow(IPasswordStoreService passwordStoreService)
|
||||||
{
|
{
|
||||||
this.passwordStoreService = passwordStoreService;
|
this.passwordStoreService = passwordStoreService;
|
||||||
|
|
||||||
|
BindUIElements();
|
||||||
|
|
||||||
|
// Initialize the observable collection with property binding
|
||||||
|
shortcuts = new PasswordStoreShortcutCollection(shortcutsGroup, passwordStoreService);
|
||||||
|
if (shortcuts.Count == 0)
|
||||||
|
{
|
||||||
|
LoadDefaultShortcuts();
|
||||||
|
}
|
||||||
|
|
||||||
|
passwordCollection = new PasswordList(passwordList);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetSearchBarVisible(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (searchToggleButton.Active)
|
||||||
|
{
|
||||||
|
titleStack.SetVisibleChildName("Search");
|
||||||
|
searchEntry.GrabFocus();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
titleStack.SetVisibleChildName("Passwords");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void BindUIElements()
|
||||||
|
{
|
||||||
var builder = new Gtk.Builder("Keychain.UI.MainWindow.MainWindow.xml");
|
var builder = new Gtk.Builder("Keychain.UI.MainWindow.MainWindow.xml");
|
||||||
|
|
||||||
|
|
||||||
Window = builder.GetObject(windowId) as Window;
|
Window = builder.GetObject(windowId) as Window;
|
||||||
if (Window == null)
|
if (Window == null)
|
||||||
{
|
{
|
||||||
@@ -88,43 +108,5 @@ public class MainWindow
|
|||||||
{
|
{
|
||||||
throw new Exception("Failed to load UI element with ID: " + e.Message);
|
throw new Exception("Failed to load UI element with ID: " + e.Message);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize the observable collection with property binding
|
|
||||||
shortcuts = new PasswordStoreShortcutCollection(shortcutsGroup, passwordStoreService);
|
|
||||||
if (shortcuts.Count == 0)
|
|
||||||
{
|
|
||||||
LoadDefaultShortcuts();
|
|
||||||
}
|
|
||||||
|
|
||||||
passwordCollection = new PasswordList(passwordList);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnAddShortcutClicked(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
var dialog = new AddShortcutWindow(shortcuts).Dialog;
|
|
||||||
dialog.Present(Window);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void LoadDefaultShortcuts()
|
|
||||||
{
|
|
||||||
shortcuts.Add(new PasswordStoreViewModel(displayName: "Default", path: Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + "/.password_store"));
|
|
||||||
}
|
|
||||||
|
|
||||||
// private void UpdateShortcutName(PasswordStoreViewModel shortcut, string newName)
|
|
||||||
// {
|
|
||||||
// shortcut.DisplayName = newName; // This will automatically update the UI row
|
|
||||||
// }
|
|
||||||
|
|
||||||
private void SetSearchBarVisible(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
if (searchToggleButton.Active)
|
|
||||||
{
|
|
||||||
titleStack.SetVisibleChildName("Search");
|
|
||||||
searchEntry.GrabFocus();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
titleStack.SetVisibleChildName("Passwords");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
31
src/App/UI/MainWindow/ShortcutSidebar.cs
Normal file
31
src/App/UI/MainWindow/ShortcutSidebar.cs
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
using Adw;
|
||||||
|
using Keychain.ViewModels;
|
||||||
|
using Logic;
|
||||||
|
|
||||||
|
namespace Keychain.UI;
|
||||||
|
|
||||||
|
public partial class MainWindow
|
||||||
|
{
|
||||||
|
private readonly IPasswordStoreService passwordStoreService;
|
||||||
|
|
||||||
|
private PreferencesGroup shortcutsGroup;
|
||||||
|
private PasswordStoreShortcutCollection shortcuts;
|
||||||
|
private const string shortcutsGroupId = "shortcuts_group";
|
||||||
|
private const string addShortcutButtonId = "add_shortcut_button";
|
||||||
|
|
||||||
|
private void OnAddShortcutClicked(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var dialog = new AddShortcutWindow(shortcuts).Dialog;
|
||||||
|
dialog.Present(Window);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LoadDefaultShortcuts()
|
||||||
|
{
|
||||||
|
shortcuts.Add(new PasswordStoreViewModel(displayName: "Default", path: Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + "/.password_store"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// private void UpdateShortcutName(PasswordStoreViewModel shortcut, string newName)
|
||||||
|
// {
|
||||||
|
// shortcut.DisplayName = newName; // This will automatically update the UI row
|
||||||
|
// }
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user