@@ -1333,39 +1333,30 @@ void UpdateFromMenuSelection<T>(ComboBox comboBox, UserSettings.Menu_SelectionIn
13331333 UpdateFromMenuSelection < T > ( comboBox , index , map , default ( T ) ) ;
13341334 }
13351335
1336+ /// <summary>
1337+ /// Update the combobox with the selection stored in the menu selection settings (from the previous run).
1338+ /// If the menu selection settings do not match the current selection use the default; except for
1339+ /// "Explore in Activity Mode" also try the content route settings (for the route).
1340+ /// </summary>
13361341 void UpdateFromMenuSelection < T > ( ComboBox comboBox , UserSettings . Menu_SelectionIndex index , Func < T , string > map , T defaultValue )
13371342 {
1338- // if folder field, or the selected folder matches the menu selection setting
1339- // and there is a value in the menu selection setting
1340- if ( ( ( index == UserSettings . Menu_SelectionIndex . Folder ) ||
1341- ( ( comboBoxFolder . Items . Count > 0 ) && ( SelectedFolder != null ) &&
1342- ( Settings . Menu_Selection . Count ( ) > 0 ) &&
1343- ( SelectedFolder . Path == Settings . Menu_Selection [ ( int ) UserSettings . Menu_SelectionIndex . Folder ] ) ) ) &&
1344- ( Settings . Menu_Selection . Length > ( int ) index ) &&
1345- ( Settings . Menu_Selection [ ( int ) index ] != "" ) )
1343+ string value = GetValueFromMenuSelection ( index ) ;
1344+ if ( ! string . IsNullOrEmpty ( value ) )
13461345 {
1347- if ( comboBox . DropDownStyle == ComboBoxStyle . DropDown )
1348- {
1349- comboBox . Text = Settings . Menu_Selection [ ( int ) index ] ;
1350- }
1351- else
1352- {
1353- SelectComboBoxItem < T > ( comboBox , item => map ( item ) == Settings . Menu_Selection [ ( int ) index ] ) ;
1354- }
1346+ if ( comboBox . DropDownStyle == ComboBoxStyle . DropDown ) { comboBox . Text = value ; }
1347+ else { SelectComboBoxItem < T > ( comboBox , item => map ( item ) == value ) ; }
13551348 }
13561349 else
13571350 {
1358- // if selected folder is in the content routes setting and has a start route
1359- // and the selected activity is explore in activit mode
1351+ // when explore in activit mode, try the content route info
13601352 var routes = Settings . Content . ContentRouteSettings . Routes ;
1361- if ( ( SelectedFolder != null ) &&
1362- routes . ContainsKey ( SelectedFolder . Name ) &&
1363- routes [ SelectedFolder . Name ] . Installed &&
1364- ! string . IsNullOrEmpty ( routes [ SelectedFolder . Name ] . Start . Route ) &&
1365- SelectedActivity != null && SelectedActivity is ExploreThroughActivity )
1353+ if ( ( SelectedActivity != null && SelectedActivity is ExploreThroughActivity ) &&
1354+ ( SelectedFolder != null && routes . ContainsKey ( SelectedFolder . Name ) && routes [ SelectedFolder . Name ] . Installed ) &&
1355+ ( ! string . IsNullOrEmpty ( routes [ SelectedFolder . Name ] . Start . Route ) ) )
13661356 {
13671357 var route = routes [ SelectedFolder . Name ] ;
13681358 string valueComboboxToSetTo = "" ;
1359+ string conditionalSecondValue = "" ;
13691360 switch ( index )
13701361 {
13711362 case UserSettings . Menu_SelectionIndex . Route :
@@ -1382,6 +1373,7 @@ void UpdateFromMenuSelection<T>(ComboBox comboBox, UserSettings.Menu_SelectionIn
13821373 break ;
13831374 case UserSettings . Menu_SelectionIndex . Path :
13841375 valueComboboxToSetTo = route . Start . StartingAt ;
1376+ conditionalSecondValue = route . Start . HeadingTo ;
13851377 break ;
13861378 case UserSettings . Menu_SelectionIndex . Time :
13871379 valueComboboxToSetTo = route . Start . Time ;
@@ -1395,26 +1387,29 @@ void UpdateFromMenuSelection<T>(ComboBox comboBox, UserSettings.Menu_SelectionIn
13951387 default :
13961388 break ;
13971389 }
1398- if ( string . IsNullOrEmpty ( valueComboboxToSetTo ) )
1399- {
1400- SetToDefault ( comboBox , index , map , defaultValue ) ;
1401- }
1402- else if ( index == UserSettings . Menu_SelectionIndex . Path && SelectedActivity != null && SelectedActivity is ExploreActivity )
1390+
1391+ if ( index == UserSettings . Menu_SelectionIndex . Path )
14031392 {
1404- // Is this ever called? Theoretically from ShowHeadToList(), but breakpoint was never hit.
1405- searchInComboBoxAndSet ( comboBoxStartAt , valueComboboxToSetTo ) ;
1406- searchInComboBoxAndSet ( comboBoxHeadTo , valueComboboxToSetTo ) ;
1393+ if ( ! string . IsNullOrEmpty ( valueComboboxToSetTo ) )
1394+ searchInComboBoxAndSet ( comboBoxStartAt , valueComboboxToSetTo ) ;
1395+ else
1396+ SetToDefault ( comboBoxStartAt , index , map , defaultValue ) ;
1397+
1398+ if ( ! string . IsNullOrEmpty ( conditionalSecondValue ) )
1399+ searchInComboBoxAndSet ( comboBoxHeadTo , conditionalSecondValue ) ;
1400+ else
1401+ SetToDefault ( comboBoxHeadTo , index , map , defaultValue ) ;
14071402 }
1408- else
1403+ else if ( ! string . IsNullOrEmpty ( valueComboboxToSetTo ) )
14091404 {
1410- if ( comboBox . DropDownStyle == ComboBoxStyle . DropDown )
1411- {
1405+ if ( comboBox . DropDownStyle == ComboBoxStyle . DropDown )
14121406 comboBox . Text = valueComboboxToSetTo ;
1413- }
14141407 else
1415- {
14161408 searchInComboBoxAndSet ( comboBox , valueComboboxToSetTo ) ;
1417- }
1409+ }
1410+ else
1411+ {
1412+ SetToDefault ( comboBox , index , map , defaultValue ) ;
14181413 }
14191414 }
14201415 else
@@ -1425,9 +1420,56 @@ void UpdateFromMenuSelection<T>(ComboBox comboBox, UserSettings.Menu_SelectionIn
14251420 }
14261421
14271422 /// <summary>
1428- /// Search the combobox for the specified value. When found, set the combobox to the value.
1429- /// When not found, set it to the first defined value.
1430- /// Leave empty when there are no defined values.
1423+ /// Get the combobox's value from the menu selection in the settings.
1424+ /// Checks that folder, route and activity/timetable-set match.
1425+ /// Returns the value from the settings, or an empty string.
1426+ /// </summary>
1427+ string GetValueFromMenuSelection ( UserSettings . Menu_SelectionIndex index )
1428+ {
1429+ if ( Settings . Menu_Selection . Length <= ( int ) index )
1430+ return "" ; // not in menu selection settings
1431+
1432+ else if ( index == UserSettings . Menu_SelectionIndex . Folder )
1433+ return Settings . Menu_Selection [ ( int ) index ] ;
1434+
1435+ else if ( SelectedFolder == null )
1436+ return "" ; // no current folder to match to
1437+
1438+ else if ( SelectedFolder . Path != Settings . Menu_Selection [ ( int ) UserSettings . Menu_SelectionIndex . Folder ] )
1439+ return "" ; // current folder and menu selection settings folder don't match
1440+
1441+ else if ( index == UserSettings . Menu_SelectionIndex . Route )
1442+ return Settings . Menu_Selection [ ( int ) index ] ;
1443+
1444+ else if ( SelectedRoute == null )
1445+ return "" ; // no current route to match to
1446+
1447+ else if ( SelectedRoute . Path != Settings . Menu_Selection [ ( int ) UserSettings . Menu_SelectionIndex . Route ] )
1448+ return "" ; // current route and menu selection settings route don't match
1449+
1450+ else if ( index == UserSettings . Menu_SelectionIndex . Activity || index == UserSettings . Menu_SelectionIndex . TimetableSet )
1451+ return Settings . Menu_Selection [ ( int ) index ] ;
1452+
1453+ else if ( radioButtonModeActivity . Checked && SelectedActivity == null )
1454+ return "" ; // no current activity to match to
1455+
1456+ else if ( radioButtonModeTimetable . Checked && SelectedTimetableSet == null )
1457+ return "" ; // no current timetable set to match to
1458+
1459+ else if ( radioButtonModeActivity . Checked && SelectedActivity . Name != Settings . Menu_Selection [ ( int ) UserSettings . Menu_SelectionIndex . Activity ] )
1460+ return "" ; // current activity and menu selection settings activity don't match
1461+
1462+ else if ( radioButtonModeTimetable . Checked && SelectedTimetableSet . fileName != Settings . Menu_Selection [ ( int ) UserSettings . Menu_SelectionIndex . TimetableSet ] )
1463+ return "" ; // current timetable set is different from timetable set in menu selection setting
1464+
1465+ else
1466+ return Settings . Menu_Selection [ ( int ) index ] ;
1467+ }
1468+
1469+ /// <summary>
1470+ /// Search the DropDown combobox (editable) for the specified string value.
1471+ /// When found, set the combobox to the value, otherwise to the first defined value.
1472+ /// Leave unselected when there are no defined values.
14311473 /// </summary>
14321474 void searchInComboBoxAndSet ( ComboBox comboBox , string valueComboboxToSetTo )
14331475 {
@@ -1445,6 +1487,9 @@ void searchInComboBoxAndSet(ComboBox comboBox, string valueComboboxToSetTo)
14451487 }
14461488 }
14471489
1490+ /// <summary>
1491+ /// Set the combobox to the specified default (item).
1492+ /// </summary>
14481493 void SetToDefault < T > ( ComboBox comboBox , UserSettings . Menu_SelectionIndex index , Func < T , string > map , T defaultValue )
14491494 {
14501495 if ( comboBox . DropDownStyle == ComboBoxStyle . DropDown )
@@ -1467,6 +1512,11 @@ void SetToDefault<T>(ComboBox comboBox, UserSettings.Menu_SelectionIndex index,
14671512 }
14681513 }
14691514
1515+ /// <summary>
1516+ /// Select the the specified item in the combobox (not editable).
1517+ /// When not found, set it to the first item.
1518+ /// Leave unselected when there are no defined items.
1519+ /// </summary>
14701520 void SelectComboBoxItem < T > ( ComboBox comboBox , Func < T , bool > predicate )
14711521 {
14721522 if ( comboBox . Items . Count == 0 )
0 commit comments