Pass recipient to PasswordGenerator.cs

This commit is contained in:
2023-03-28 10:35:23 +02:00
parent b71c11249d
commit 037ca44b2b
2 changed files with 17 additions and 5 deletions

View File

@@ -5,10 +5,12 @@ namespace Password_Manager
sealed public partial class MainForm : Form
{
public event DataRequest PathRequest;
public event DataRequest? RecipientRequest;
public MainForm(DataRequest PathRequest)
public MainForm(DataRequest PathRequest, DataRequest RecipientRequest = null)
{
this.PathRequest = PathRequest;
this.RecipientRequest = RecipientRequest;
InitializeComponent();
ResultList.SearchQueryRequest += () => SearchBox.Text;
@@ -22,8 +24,15 @@ namespace Password_Manager
private void OpenPasswordGenerator(object sender, EventArgs e)
{
GeneratePassword gp = new GeneratePassword(SearchBox.Text, PathRequest());
gp.ShowDialog();
if (RecipientRequest != null)
{
GeneratePassword gp = new GeneratePassword(SearchBox.Text, PathRequest(), RecipientRequest());
gp.ShowDialog();
}
else
{
throw new InvalidOperationExpression("You cannot use the OpenPasswordGenerator method if you instantiated this form without a RecipientRequest event handler.");
}
}
private void CancelPressed(object sender, EventArgs e)
@@ -64,4 +73,4 @@ namespace Password_Manager
Close();
}
}
}
}