Skip to content

Commit 606e6bd

Browse files
committed
Refactor to make more readable.
1 parent 1f21bdb commit 606e6bd

File tree

1 file changed

+20
-24
lines changed

1 file changed

+20
-24
lines changed

Source/Menu/MainForm.cs

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1397,33 +1397,21 @@ void UpdateFromMenuSelection<T>(ComboBox comboBox, UserSettings.Menu_SelectionIn
13971397
{
13981398
SetToDefault(comboBox, index, map, defaultValue);
13991399
}
1400+
else if (index == UserSettings.Menu_SelectionIndex.Path && SelectedActivity != null && SelectedActivity is ExploreActivity)
1401+
{
1402+
// Is this ever called? Theoretically from ShowHeadToList(), but breakpoint was never hit.
1403+
searchInComboBoxAndSet(comboBoxStartAt, valueComboboxToSetTo);
1404+
searchInComboBoxAndSet(comboBoxHeadTo, valueComboboxToSetTo);
1405+
}
14001406
else
14011407
{
1402-
bool found = false;
1403-
if ((index != UserSettings.Menu_SelectionIndex.Path) ||
1404-
(SelectedActivity == null) || (!(SelectedActivity is ExploreActivity)))
1408+
if (comboBox.DropDownStyle == ComboBoxStyle.DropDown)
14051409
{
1406-
if (comboBox.DropDownStyle == ComboBoxStyle.DropDown)
1407-
{
1408-
comboBox.Text = valueComboboxToSetTo;
1409-
found = true;
1410-
}
1411-
else
1412-
{
1413-
found = searchInComboBox(comboBox, valueComboboxToSetTo);
1414-
}
1410+
comboBox.Text = valueComboboxToSetTo;
14151411
}
14161412
else
14171413
{
1418-
found = searchInComboBox(comboBoxStartAt, valueComboboxToSetTo);
1419-
found = searchInComboBox(comboBoxHeadTo, valueComboboxToSetTo);
1420-
}
1421-
if (!found)
1422-
{
1423-
if (comboBox.Items.Count > 0)
1424-
{
1425-
comboBox.SelectedIndex = 0;
1426-
}
1414+
searchInComboBoxAndSet(comboBox, valueComboboxToSetTo);
14271415
}
14281416
}
14291417
}
@@ -1434,17 +1422,25 @@ void UpdateFromMenuSelection<T>(ComboBox comboBox, UserSettings.Menu_SelectionIn
14341422
}
14351423
}
14361424

1437-
bool searchInComboBox(ComboBox comboBox, string valueComboboxToSetTo)
1425+
/// <summary>
1426+
/// Search the combobox for the specified value. When found, set the combobox to the value.
1427+
/// When not found, set it to the first defined value.
1428+
/// Leave empty when there are no defined values.
1429+
/// </summary>
1430+
void searchInComboBoxAndSet(ComboBox comboBox, string valueComboboxToSetTo)
14381431
{
14391432
for (var i = 0; i < comboBox.Items.Count; i++)
14401433
{
14411434
if ((string)comboBox.Items[i].ToString() == valueComboboxToSetTo)
14421435
{
14431436
comboBox.SelectedIndex = i;
1444-
return true;
1437+
return;
14451438
}
14461439
}
1447-
return false;
1440+
if (comboBox.Items.Count > 0)
1441+
{
1442+
comboBox.SelectedIndex = 0;
1443+
}
14481444
}
14491445

14501446
void SetToDefault<T>(ComboBox comboBox, UserSettings.Menu_SelectionIndex index, Func<T, string> map, T defaultValue)

0 commit comments

Comments
 (0)