This commit is contained in:
2023-03-27 09:30:41 +02:00
parent 1352624172
commit 60c6982663
6 changed files with 81 additions and 67 deletions

View File

@@ -31,9 +31,9 @@
SearchBox = new TextBox();
ResultList = new PasswordListBox();
ProfileSelection = new ComboBox();
addProfile = new Button();
removeProfile = new Button();
generatePassword = new Button();
AddProfile = new Button();
DeleteProfile = new Button();
GeneratePassword = new Button();
SuspendLayout();
//
// searchBox
@@ -123,11 +123,11 @@
#endregion
protected override TextBox SearchBox { get; }
protected override PasswordListBox ResultList { get; }
protected override ComboBox ProfileSelection { get; }
protected override Button AddProfile { get; }
protected override Button DeleteProfile { get; }
protected override Button GeneratePassword { get; }
protected override TextBox SearchBox { get; set; }
protected override PasswordListBox ResultList { get; set; }
protected override ComboBox ProfileSelection { get; set; }
protected override Button AddProfile { get; set; }
protected override Button DeleteProfile { get; set; }
protected override Button GeneratePassword { get; set; }
}
}

View File

@@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Password_Manager
{
public sealed partial class MainForm : PasswordManagerForm
{
public override event ProfileDataRequest CurrentProfilePathRequest;
public override event ProfileDataRequest CurrentProfileNameRequest;
public override event ProfileList CurrentProfileListRequest;
public override event ProfileChange CurrentProfileChanged;
public override event Save SaveRequest;
public override event NewProfile NewProfileRequest;
public MainForm(
ProfileDataRequest CurrentProfileNameRequest,
ProfileDataRequest CurrentProfilePathRequest,
ProfileList CurrentProfileListRequest,
ProfileChange CurrentProfileChanged,
Save SaveRequest,
NewProfile NewProfileRequest)
{
this.CurrentProfileNameRequest = CurrentProfileNameRequest;
this.CurrentProfilePathRequest = CurrentProfilePathRequest;
this.CurrentProfileListRequest = CurrentProfileListRequest;
this.CurrentProfileChanged = CurrentProfileChanged;
this.SaveRequest = SaveRequest;
this.NewProfileRequest = NewProfileRequest;
InitializeComponent();
RefreshCurrentProfile();
SaveRequest();
}
}
}

View File

@@ -1,22 +1,9 @@
using System.ComponentModel.Design;
namespace Password_Manager
{
sealed public partial class MainForm : PasswordManagerForm
{
public override event ProfileDataRequest CurrentProfilePathRequest;
public override event ProfileDataRequest CurrentProfileNameRequest;
public override event ProfileList CurrentProfileListRequest;
public override event ProfileChange CurrentProfileChanged;
public override event Save SaveRequest;
public override event NewProfile NewProfileRequest;
public MainForm(ProfileDataRequest CurrentProfileNameRequest, ProfileDataRequest CurrentProfilePathRequest, ProfileList CurrentProfileListRequest, ProfileChange CurrentProfileChanged, Save SaveRequest, NewProfile NewProfileRequest)
: base(CurrentProfileNameRequest, CurrentProfilePathRequest, CurrentProfileListRequest, CurrentProfileChanged, SaveRequest, NewProfileRequest)
{
InitializeComponent();
RefreshCurrentProfile();
SaveRequest();
}
private void OpenProfileCreator(object sender, EventArgs e)
{
NewProfileForm npf = new NewProfileForm();
@@ -39,5 +26,26 @@ namespace Password_Manager
MessageBox.Show("No path specified", "Event error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
protected override void ChangeProfile(object sender, EventArgs e)
{
CurrentProfileChanged(ProfileSelection.Text);
}
public override void RefreshCurrentProfile()
{
ProfileSelection.SelectedIndex = -1;
string[] items = CurrentProfileListRequest();
for (int i = 0; i < items.Length; i++)
{
ProfileSelection.Items.Add(items[i]);
if (items[i] == CurrentProfileNameRequest())
{
ProfileSelection.SelectedIndex = i;
}
}
this.Text = CurrentProfileNameRequest();
ResultList.ReloadResults();
}
}
}

View File

@@ -9,8 +9,6 @@
public NewProfileForm()
{
//test
MessageBox.Show(this.Parent.Text, this.Parent.Text);
InitializeComponent();
}

View File

@@ -7,6 +7,9 @@
<Compile Update="MainForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Update="MainForm.Events.cs">
<SubType>Form</SubType>
</Compile>
<Compile Update="NewProfileForm.cs">
<SubType>Form</SubType>
</Compile>

View File

@@ -7,12 +7,12 @@
public abstract class PasswordManagerForm : Form
{
protected abstract ComboBox ProfileSelection { get; }
protected abstract PasswordListBox ResultList { get; }
protected abstract TextBox SearchBox { get; }
protected abstract Button AddProfile { get; }
protected abstract Button DeleteProfile { get; }
protected abstract Button GeneratePassword { get; }
protected abstract ComboBox ProfileSelection { get; set; }
protected abstract PasswordListBox ResultList { get; set; }
protected abstract TextBox SearchBox { get; set; }
protected abstract Button AddProfile { get; set; }
protected abstract Button DeleteProfile { get; set; }
protected abstract Button GeneratePassword { get; set; }
public abstract event ProfileDataRequest CurrentProfilePathRequest;
public abstract event ProfileDataRequest CurrentProfileNameRequest;
@@ -21,41 +21,8 @@
public abstract event Save SaveRequest;
public abstract event NewProfile NewProfileRequest;
public PasswordManagerForm(
ProfileDataRequest CurrentProfileNameRequest,
ProfileDataRequest CurrentProfilePathRequest,
ProfileList CurrentProfileListRequest,
ProfileChange CurrentProfileChanged,
Save SaveRequest,
NewProfile NewProfileRequest)
{
this.CurrentProfileNameRequest = CurrentProfileNameRequest;
this.CurrentProfilePathRequest = CurrentProfilePathRequest;
this.CurrentProfileListRequest = CurrentProfileListRequest;
this.CurrentProfileChanged = CurrentProfileChanged;
this.SaveRequest = SaveRequest;
this.NewProfileRequest = NewProfileRequest;
}
protected virtual void ChangeProfile(object sender, EventArgs e)
{
CurrentProfileChanged(ProfileSelection.Text);
}
public virtual void RefreshCurrentProfile()
{
ProfileSelection.SelectedIndex = -1;
string[] items = CurrentProfileListRequest();
for (int i = 0; i < items.Length; i++)
{
ProfileSelection.Items.Add(items[i]);
if (items[i] == CurrentProfileNameRequest())
{
ProfileSelection.SelectedIndex = i;
}
}
this.Text = CurrentProfileNameRequest();
ResultList.ReloadResults();
}
protected abstract void ChangeProfile(object sender, EventArgs e);
public abstract void RefreshCurrentProfile();
}
}