namespace Password_Manager { public delegate void ProfileChange(string profileName); //Fires when we want to change the CurrentProfile field of ProfileHandler based on the combobox selection public delegate string[] ProfileList(); //Fires when we need a list of Profile names, like for the combobox items public delegate void Save(); //Fire whenever we want to save the current state of profiles public delegate void NewProfile(string profileName, string profilePath); //Fires whenever a NewProfileForm has requested the creation of a new profile. This just forwards that request to ProfileHandler 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; } public abstract event ProfileDataRequest CurrentProfilePathRequest; public abstract event ProfileDataRequest CurrentProfileNameRequest; public abstract event ProfileList CurrentProfileListRequest; public abstract event ProfileChange CurrentProfileChanged; 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(); } } }