2023-03-24 10:17:54 +01:00
|
|
|
namespace Password_Manager
|
|
|
|
|
{
|
2023-03-27 00:19:30 +02:00
|
|
|
public delegate void ProfileChanges(string profileName);
|
|
|
|
|
public delegate string[] ProfileList();
|
|
|
|
|
public delegate void Save();
|
2023-03-24 11:14:49 +01:00
|
|
|
public partial class MainForm : Form
|
2023-03-24 10:17:54 +01:00
|
|
|
{
|
2023-03-27 00:19:30 +02:00
|
|
|
public event ProfileDataRequest? CurrentProfilePathRequest;
|
|
|
|
|
public event ProfileDataRequest? CurrentProfileNameRequest;
|
|
|
|
|
public event ProfileList? CurrentProfileListRequest;
|
|
|
|
|
public event ProfileChanges? CurrentProfileChanged;
|
|
|
|
|
public event Save? SaveRequest;
|
|
|
|
|
|
|
|
|
|
public MainForm(ProfileDataRequest CurrentProfileNameRequest, ProfileDataRequest CurrentProfilePathRequest, ProfileList CurrentProfileListRequest, ProfileChanges CurrentProfileChanged)
|
2023-03-24 10:17:54 +01:00
|
|
|
{
|
2023-03-27 00:19:30 +02:00
|
|
|
this.CurrentProfileNameRequest = CurrentProfileNameRequest;
|
|
|
|
|
this.CurrentProfilePathRequest = CurrentProfilePathRequest;
|
|
|
|
|
this.CurrentProfileListRequest = CurrentProfileListRequest;
|
|
|
|
|
this.CurrentProfileChanged = CurrentProfileChanged;
|
2023-03-24 10:17:54 +01:00
|
|
|
InitializeComponent();
|
2023-03-27 00:19:30 +02:00
|
|
|
LoadCurrentProfile();
|
|
|
|
|
|
|
|
|
|
foreach (string s in CurrentProfileListRequest?.Invoke())
|
|
|
|
|
{
|
|
|
|
|
profileSelection.Items.Add(s);
|
|
|
|
|
}
|
|
|
|
|
profileSelection.SelectedIndex = 0;
|
|
|
|
|
|
|
|
|
|
SaveRequest?.Invoke();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void LoadCurrentProfile()
|
|
|
|
|
{
|
|
|
|
|
this.Text = CurrentProfileNameRequest?.Invoke();
|
|
|
|
|
resultList.ReloadResults();
|
2023-03-24 10:17:54 +01:00
|
|
|
}
|
2023-03-24 11:14:49 +01:00
|
|
|
|
|
|
|
|
private void ChangeProfile(object sender, EventArgs e)
|
|
|
|
|
{
|
2023-03-27 00:19:30 +02:00
|
|
|
CurrentProfileChanged?.Invoke(profileSelection.Text);
|
|
|
|
|
|
|
|
|
|
foreach (string s in CurrentProfileListRequest?.Invoke())
|
|
|
|
|
{
|
|
|
|
|
profileSelection.Items.Add(s);
|
|
|
|
|
}
|
2023-03-24 12:39:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void AddProfile(object sender, EventArgs e)
|
|
|
|
|
{
|
2023-03-24 13:01:49 +01:00
|
|
|
NewProfileForm npf = new NewProfileForm();
|
2023-03-27 00:19:30 +02:00
|
|
|
npf.ReloadPasswordsRequest += () => resultList.ReloadResults();
|
2023-03-24 13:01:49 +01:00
|
|
|
npf.Show();
|
2023-03-24 11:14:49 +01:00
|
|
|
}
|
2023-03-27 00:19:30 +02:00
|
|
|
|
|
|
|
|
private void Generate(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
GeneratePassword gp = new GeneratePassword(searchBox.Text, CurrentProfilePathRequest?.Invoke());
|
|
|
|
|
gp.Show();
|
|
|
|
|
}
|
2023-03-24 10:17:54 +01:00
|
|
|
}
|
|
|
|
|
}
|