Fixed ProfileSettingsForm logic

This commit is contained in:
Terry MacDonald 2021-08-28 21:24:39 +12:00
parent 93c85d7d87
commit bb1fa73c7f
3 changed files with 43 additions and 14 deletions

View File

@ -539,7 +539,11 @@ namespace DisplayMagician.UIForms
ProfileSettingsForm profileSettingsForm = new ProfileSettingsForm(); ProfileSettingsForm profileSettingsForm = new ProfileSettingsForm();
profileSettingsForm.Profile = _selectedProfile; profileSettingsForm.Profile = _selectedProfile;
profileSettingsForm.ShowDialog(this); profileSettingsForm.ShowDialog(this);
//_selectedProfile = profileSettingsForm.Profile; // If the profile was changed then save all the profiles
if (profileSettingsForm.ProfileSettingChanged)
{
ProfileRepository.SaveProfiles();
}
} }
} }
} }

View File

@ -86,6 +86,7 @@ namespace DisplayMagician.UIForms
this.btn_select_wallpaper.TabIndex = 16; this.btn_select_wallpaper.TabIndex = 16;
this.btn_select_wallpaper.Text = "&Select"; this.btn_select_wallpaper.Text = "&Select";
this.btn_select_wallpaper.UseVisualStyleBackColor = true; this.btn_select_wallpaper.UseVisualStyleBackColor = true;
this.btn_select_wallpaper.Click += new System.EventHandler(this.btn_select_wallpaper_Click);
// //
// txt_wallpaper_filename // txt_wallpaper_filename
// //
@ -107,6 +108,7 @@ namespace DisplayMagician.UIForms
this.cb_set_wallpaper.TabIndex = 14; this.cb_set_wallpaper.TabIndex = 14;
this.cb_set_wallpaper.Text = "Set wallpaper when applying this profile"; this.cb_set_wallpaper.Text = "Set wallpaper when applying this profile";
this.cb_set_wallpaper.UseVisualStyleBackColor = true; this.cb_set_wallpaper.UseVisualStyleBackColor = true;
this.cb_set_wallpaper.CheckedChanged += new System.EventHandler(this.cb_set_wallpaper_CheckedChanged);
// //
// label1 // label1
// //
@ -123,10 +125,6 @@ namespace DisplayMagician.UIForms
// //
this.cmb_wallpaper_display_mode.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.cmb_wallpaper_display_mode.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.cmb_wallpaper_display_mode.FormattingEnabled = true; this.cmb_wallpaper_display_mode.FormattingEnabled = true;
this.cmb_wallpaper_display_mode.Items.AddRange(new object[] {
"Centered",
"Stretched",
"Tiled"});
this.cmb_wallpaper_display_mode.Location = new System.Drawing.Point(203, 108); this.cmb_wallpaper_display_mode.Location = new System.Drawing.Point(203, 108);
this.cmb_wallpaper_display_mode.Name = "cmb_wallpaper_display_mode"; this.cmb_wallpaper_display_mode.Name = "cmb_wallpaper_display_mode";
this.cmb_wallpaper_display_mode.Size = new System.Drawing.Size(219, 24); this.cmb_wallpaper_display_mode.Size = new System.Drawing.Size(219, 24);

View File

@ -16,6 +16,7 @@ namespace DisplayMagician.UIForms
private static readonly NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger(); private static readonly NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
private Dictionary<Wallpaper.Style, string> wallpaperStyleText = new Dictionary<Wallpaper.Style, string>(); private Dictionary<Wallpaper.Style, string> wallpaperStyleText = new Dictionary<Wallpaper.Style, string>();
private bool _profileSettingChanged = false;
public ProfileSettingsForm() public ProfileSettingsForm()
{ {
@ -28,10 +29,9 @@ namespace DisplayMagician.UIForms
wallpaperStyleText.Add(Wallpaper.Style.Stretched, "Stretch the Wallpaper"); wallpaperStyleText.Add(Wallpaper.Style.Stretched, "Stretch the Wallpaper");
wallpaperStyleText.Add(Wallpaper.Style.Tiled, "Tile the Wallpaper"); wallpaperStyleText.Add(Wallpaper.Style.Tiled, "Tile the Wallpaper");
// Now use it to populate the Style Dropdown cmb_wallpaper_display_mode.DisplayMember = "Value";
cmb_wallpaper_display_mode.Items.Clear(); cmb_wallpaper_display_mode.ValueMember = "Text";
cmb_wallpaper_display_mode.Items.AddRange(wallpaperStyleText.Values.ToArray()); cmb_wallpaper_display_mode.DataSource = new BindingSource(wallpaperStyleText, null);
cmb_wallpaper_display_mode.SelectedIndex = 0;
} }
public ProfileItem Profile public ProfileItem Profile
@ -40,36 +40,63 @@ namespace DisplayMagician.UIForms
set; set;
} }
public bool ProfileSettingChanged
{
get
{
return _profileSettingChanged;
}
set
{
_profileSettingChanged = value;
}
}
private void ProfileSettingsForm_Load(object sender, EventArgs e) private void ProfileSettingsForm_Load(object sender, EventArgs e)
{ {
if (Profile.SetWallpaper) if (Profile.SetWallpaper)
{ {
logger.Info($"ProfileSettingsForm/ProfileSettingsForm_Load: Profile {Profile.Name} has loaded with Set Wallpaper enabled and Wallpaper Style {Profile.WallpaperStyle.ToString("G")} and Wallpaper Filename of {Profile.WallpaperBitmapFilename}."); logger.Info($"ProfileSettingsForm/ProfileSettingsForm_Load: Profile {Profile.Name} has loaded with Set Wallpaper enabled and Wallpaper Style {Profile.WallpaperStyle.ToString("G")} and Wallpaper Filename of {Profile.WallpaperBitmapFilename}.");
cb_set_wallpaper.Checked = true;
cmb_wallpaper_display_mode.SelectedIndex = cmb_wallpaper_display_mode.FindStringExact(wallpaperStyleText[Profile.WallpaperStyle]); cmb_wallpaper_display_mode.SelectedIndex = cmb_wallpaper_display_mode.FindStringExact(wallpaperStyleText[Profile.WallpaperStyle]);
if (Profile.WallpaperBitmapFilename != "") if (Profile.WallpaperBitmapFilename != "")
{ {
txt_wallpaper_filename.Text = Profile.WallpaperBitmapFilename; txt_wallpaper_filename.Text = Profile.WallpaperBitmapFilename;
} }
} }
else
{
cb_set_wallpaper.Checked = false;
}
} }
private void ProfileSettingsForm_FormClosing(object sender, FormClosingEventArgs e) private void ProfileSettingsForm_FormClosing(object sender, FormClosingEventArgs e)
{ {
Profile.SetWallpaper = cb_set_wallpaper.Checked;
Profile.WallpaperStyle = ((KeyValuePair<Wallpaper.Style, string>)cmb_wallpaper_display_mode.SelectedItem).Key;
Profile.WallpaperBitmapFilename = txt_wallpaper_filename.Text;
} }
private void btn_back_Click(object sender, EventArgs e) private void btn_back_Click(object sender, EventArgs e)
{ {
Profile.SetWallpaper = cb_set_wallpaper.Checked;
Profile.WallpaperStyle = (Wallpaper.Style)cmb_wallpaper_display_mode.SelectedValue;
Profile.WallpaperBitmapFilename = txt_wallpaper_filename.Text;
this.Close(); this.Close();
} }
private void cb_set_wallpaper_CheckedChanged(object sender, EventArgs e)
{
_profileSettingChanged = true;
}
private void cmb_wallpaper_display_mode_SelectedIndexChanged(object sender, EventArgs e) private void cmb_wallpaper_display_mode_SelectedIndexChanged(object sender, EventArgs e)
{ {
_profileSettingChanged = true;
}
private void btn_select_wallpaper_Click(object sender, EventArgs e)
{
_profileSettingChanged = true;
} }
} }
} }