@@ -1333,39 +1333,30 @@ void UpdateFromMenuSelection<T>(ComboBox comboBox, UserSettings.Menu_SelectionIn
1333
1333
UpdateFromMenuSelection < T > ( comboBox , index , map , default ( T ) ) ;
1334
1334
}
1335
1335
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>
1336
1341
void UpdateFromMenuSelection < T > ( ComboBox comboBox , UserSettings . Menu_SelectionIndex index , Func < T , string > map , T defaultValue )
1337
1342
{
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 ) )
1346
1345
{
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 ) ; }
1355
1348
}
1356
1349
else
1357
1350
{
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
1360
1352
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 ) ) )
1366
1356
{
1367
1357
var route = routes [ SelectedFolder . Name ] ;
1368
1358
string valueComboboxToSetTo = "" ;
1359
+ string conditionalSecondValue = "" ;
1369
1360
switch ( index )
1370
1361
{
1371
1362
case UserSettings . Menu_SelectionIndex . Route :
@@ -1382,6 +1373,7 @@ void UpdateFromMenuSelection<T>(ComboBox comboBox, UserSettings.Menu_SelectionIn
1382
1373
break ;
1383
1374
case UserSettings . Menu_SelectionIndex . Path :
1384
1375
valueComboboxToSetTo = route . Start . StartingAt ;
1376
+ conditionalSecondValue = route . Start . HeadingTo ;
1385
1377
break ;
1386
1378
case UserSettings . Menu_SelectionIndex . Time :
1387
1379
valueComboboxToSetTo = route . Start . Time ;
@@ -1395,26 +1387,29 @@ void UpdateFromMenuSelection<T>(ComboBox comboBox, UserSettings.Menu_SelectionIn
1395
1387
default :
1396
1388
break ;
1397
1389
}
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 )
1403
1392
{
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 ) ;
1407
1402
}
1408
- else
1403
+ else if ( ! string . IsNullOrEmpty ( valueComboboxToSetTo ) )
1409
1404
{
1410
- if ( comboBox . DropDownStyle == ComboBoxStyle . DropDown )
1411
- {
1405
+ if ( comboBox . DropDownStyle == ComboBoxStyle . DropDown )
1412
1406
comboBox . Text = valueComboboxToSetTo ;
1413
- }
1414
1407
else
1415
- {
1416
1408
searchInComboBoxAndSet ( comboBox , valueComboboxToSetTo ) ;
1417
- }
1409
+ }
1410
+ else
1411
+ {
1412
+ SetToDefault ( comboBox , index , map , defaultValue ) ;
1418
1413
}
1419
1414
}
1420
1415
else
@@ -1425,9 +1420,56 @@ void UpdateFromMenuSelection<T>(ComboBox comboBox, UserSettings.Menu_SelectionIn
1425
1420
}
1426
1421
1427
1422
/// <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.
1431
1473
/// </summary>
1432
1474
void searchInComboBoxAndSet ( ComboBox comboBox , string valueComboboxToSetTo )
1433
1475
{
@@ -1445,6 +1487,9 @@ void searchInComboBoxAndSet(ComboBox comboBox, string valueComboboxToSetTo)
1445
1487
}
1446
1488
}
1447
1489
1490
+ /// <summary>
1491
+ /// Set the combobox to the specified default (item).
1492
+ /// </summary>
1448
1493
void SetToDefault < T > ( ComboBox comboBox , UserSettings . Menu_SelectionIndex index , Func < T , string > map , T defaultValue )
1449
1494
{
1450
1495
if ( comboBox . DropDownStyle == ComboBoxStyle . DropDown )
@@ -1467,6 +1512,11 @@ void SetToDefault<T>(ComboBox comboBox, UserSettings.Menu_SelectionIndex index,
1467
1512
}
1468
1513
}
1469
1514
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>
1470
1520
void SelectComboBoxItem < T > ( ComboBox comboBox , Func < T , bool > predicate )
1471
1521
{
1472
1522
if ( comboBox . Items . Count == 0 )
0 commit comments