Refactor thumbnail options to enum and ComboBox UI

Replaced multiple mutually-exclusive boolean properties for thumbnail text options with a single enum (`ThumbnailOption`) in the data model. Updated WinForms UI to use a ComboBox instead of radio buttons for selecting thumbnail mode. Adjusted designer, mapping profile, settings DTO, and settings service for enum support and backward compatibility. Simplified thumbnail generation logic and improved maintainability by ensuring only one mode can be selected at a time.
This commit is contained in:
MaddoScientisto 2026-02-16 19:55:37 +01:00
commit d13ec8abdf
7 changed files with 214 additions and 289 deletions

View file

@ -83,54 +83,21 @@ public partial class MainForm
// Watch for model changes so we can reflect external updates
Model.PropertyChanged += Model_PropertyChanged;
// Fix thumbnail radio buttons: clear designer bindings to avoid binding vs click conflicts
RadioButton3.DataBindings.Clear();
RadioButton4.DataBindings.Clear();
RadioButton5.DataBindings.Clear();
RadioButton6.DataBindings.Clear();
RadioButton7.DataBindings.Clear();
// Thumbnail options moved to ComboBox to avoid conflicting bindings with multiple radio buttons
// Initialize radio state from model (thumbnail options)
try
{
_suppressRadioUpdates = true;
RadioButton3.Checked = Model.AddTextToThumbnails;
RadioButton4.Checked = Model.AddTimeToThumbnails;
RadioButton6.Checked = Model.ShowPhotoNumber;
RadioButton7.Checked = Model.AddNumberAndTimeToThumbnails;
RadioButton5.Checked = Model.AddRaceTimeToThumbnails;
}
finally
{
_suppressRadioUpdates = false;
}
// Initialize ComboBox with Italian descriptions
comboThumbnailOption.Items.Clear();
comboThumbnailOption.Items.AddRange(new object[] {
"Nessuna",
"Aggiungi scritta",
"Nome file",
"Aggiungi orario",
"Nome+Orario",
"Tempo gara"
});
// Use CheckedChanged handlers to set the authoritative ThumbnailMode on the model
RadioButton3.CheckedChanged += (s, ev) =>
{
if (_suppressRadioUpdates) return;
if (RadioButton3.Checked) Model.ThumbnailMode = "Text";
};
RadioButton4.CheckedChanged += (s, ev) =>
{
if (_suppressRadioUpdates) return;
if (RadioButton4.Checked) Model.ThumbnailMode = "Time";
};
RadioButton6.CheckedChanged += (s, ev) =>
{
if (_suppressRadioUpdates) return;
if (RadioButton6.Checked) Model.ThumbnailMode = "Number";
};
RadioButton7.CheckedChanged += (s, ev) =>
{
if (_suppressRadioUpdates) return;
if (RadioButton7.Checked) Model.ThumbnailMode = "NumberAndTime";
};
RadioButton5.CheckedChanged += (s, ev) =>
{
if (_suppressRadioUpdates) return;
if (RadioButton5.Checked) Model.ThumbnailMode = "RaceTime";
};
// Bind to model via helper index property ThumbnailOptionIndex
comboThumbnailOption.DataBindings.Add(new Binding("SelectedIndex", bindingSource1, "ThumbnailOptionIndex", true, DataSourceUpdateMode.OnPropertyChanged));
// Save user preferences on form close instead of immediately when dialogs are used
this.FormClosing += MainForm_FormClosing;
@ -185,22 +152,15 @@ public partial class MainForm
}
}
// Thumbnail mode changes - reflect back to radio buttons
// Thumbnail mode changes - reflect back to combo box index
if (e.PropertyName == nameof(Model.ThumbnailMode) ||
e.PropertyName == nameof(Model.AddTextToThumbnails) ||
e.PropertyName == nameof(Model.AddTimeToThumbnails) ||
e.PropertyName == nameof(Model.ShowPhotoNumber) ||
e.PropertyName == nameof(Model.AddNumberAndTimeToThumbnails) ||
e.PropertyName == nameof(Model.AddRaceTimeToThumbnails))
e.PropertyName == nameof(Model.ThumbnailOption) ||
e.PropertyName == nameof(Model.ThumbnailOptionIndex))
{
try
{
_suppressRadioUpdates = true;
RadioButton3.Checked = Model.AddTextToThumbnails;
RadioButton4.Checked = Model.AddTimeToThumbnails;
RadioButton6.Checked = Model.ShowPhotoNumber;
RadioButton7.Checked = Model.AddNumberAndTimeToThumbnails;
RadioButton5.Checked = Model.AddRaceTimeToThumbnails;
comboThumbnailOption.SelectedIndex = Model.ThumbnailOptionIndex;
}
finally
{