diff --git a/README.md b/README.md index 04eb30a..edb8857 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ Traditional photo scenery often requires downloading and building large areas be - **Towns lit at night** — optionally give the photo scenery street lamps and the light of the houses along X-Plane's roads, so towns glow after dark as on X-Plane's own scenery. You can also skip the detailed photos at night to save downloads, keeping the lights. - **Exposure and a live preview** — tone down photos that look too bright next to X-Plane's own scenery, and see any colour change on a photo from your cache before you fly. - **See what happened during your flight** — review download performance, scenery loading, and your flight route. -- **Your scenery list, without Notepad** — switch X-Plane's scenery packages on or off and drag them into order on the X-Plane Custom Scenery page, and leave any of your photo scenery packages out of a flight with one switch on the Home page. +- **Your scenery list, without Notepad** — switch X-Plane's scenery packages on or off and drag them into order on the X-Plane Custom Scenery page (with a search box for long lists), and leave any of your photo scenery packages out of a flight with one switch on the Home page. - **Level airports** — an airport that sits on a bump or in a hollow of the photo scenery's ground can be flattened on the Airports page, one at a time, without changing the airport's own files. Undo puts it back. ### Designed for everyday flying diff --git a/docs/OrthoStreamXP-UserGuide.pdf b/docs/OrthoStreamXP-UserGuide.pdf index 25f1cbe..ada703a 100644 Binary files a/docs/OrthoStreamXP-UserGuide.pdf and b/docs/OrthoStreamXP-UserGuide.pdf differ diff --git a/docs/custom-scenery.md b/docs/custom-scenery.md index d3b8c57..1e8cbea 100644 --- a/docs/custom-scenery.md +++ b/docs/custom-scenery.md @@ -13,13 +13,21 @@ X-Plane keeps a list of its scenery packages in `Custom Scenery\scenery_packs.in - The page needs the **X-Plane folder** to be set in [Settings › Folders](settings.md#folders); until then it says *Choose your X-Plane folder first*. If X-Plane has never started with this folder, the list is empty: X-Plane writes the file the first time it starts. - **Open the folder** opens X-Plane's `Custom Scenery` folder in Explorer. **Refresh** reads the file again, for example after you installed scenery while the page was open. +## Finding a package + +The list can be long. Type part of a package's name or folder in the search box above the list to show only the packages that match, for example `kden` or `D:\Ortho4XP`. Capitals do not matter, and a folder can be typed with `\` or `/`. On the right, the page counts the packages: all of them, or how many match while you search (*3 of 1,623 packages*). **Esc** or the **×** in the box empties it and shows the whole list again; the search stays while the list is read again (**Refresh**, Start, Stop). + +![Searching for kden: three of the packages match, each with Show in list](images/custom-scenery-search.png) + +While you search, the switches work as usual, but packages cannot be dragged: between two packages that match, many others may be hidden. To move a package you found, click **Show in list** in its row. The search is cleared, the page scrolls to the package and marks it with a coloured border, and you can drag it to its new place. + ## Switching packages on or off The switch at the end of each row turns a package on or off in X-Plane. A package switched off stays in its folder and in the list; X-Plane just does not load it. This is the same as X-Plane's own `SCENERY_PACK_DISABLED` lines in the file. ## Changing the order -Drag a package by the handle at the start of its row and drop it where you want it: the other rows move apart to show where it lands. Higher in the list means drawn on top. +Drag a package by the handle at the start of its row and drop it where you want it: the other rows move apart to show where it lands. Higher in the list means drawn on top. To find a package first, see [Finding a package](#finding-a-package). Leave the photo scenery near the end, below airports and overlays. With **Keep the photo scenery below airports and overlays** on (see [Settings › Other](settings.md#other)), OrthoStreamXP moves its packages back to the end at every start anyway. diff --git a/docs/images/custom-scenery-search.png b/docs/images/custom-scenery-search.png new file mode 100644 index 0000000..c2238fd Binary files /dev/null and b/docs/images/custom-scenery-search.png differ diff --git a/docs/images/custom-scenery.png b/docs/images/custom-scenery.png index e1f6b55..7cd04f2 100644 Binary files a/docs/images/custom-scenery.png and b/docs/images/custom-scenery.png differ diff --git a/release-notes/v2.1.0.md b/release-notes/v2.1.0.md new file mode 100644 index 0000000..f69b83e --- /dev/null +++ b/release-notes/v2.1.0.md @@ -0,0 +1,13 @@ +## What's new + +- **Search your scenery list.** The **X-Plane Custom Scenery** page now has a search box above the list. Type part of a package's name or folder, such as *kden* or *D:\Ortho4XP*, and only the packages that match are shown. Capitals don't matter, and a folder can be typed with \ or /. On the right, the page counts the packages: all of them, or how many match, such as *3 of 1,623 packages*. **Esc** or the **×** in the box shows the whole list again. +- **Show in list.** While you search, each package that matches has a **Show in list** button. It clears the search, scrolls to the package and marks it with a coloured border, so you can drag it to a new place. + +## Good to know + +- While you search, the switches work as usual, but packages can't be dragged: between two packages that match, many others may be hidden. Use **Show in list** first, or clear the search. +- The search stays when the list is read again, after **Refresh**, Start or Stop. +- As before, the list can be changed only while OrthoStreamXP is stopped. Searching works at any time. +- Nothing changes for your packages or settings with the update. + +Thanks to andrewcarlberg for this feature. diff --git a/src/OrthoStreamXP/Gui/Scenery/SceneryPackRow.cs b/src/OrthoStreamXP/Gui/Scenery/SceneryPackRow.cs index 8953310..861be6c 100644 --- a/src/OrthoStreamXP/Gui/Scenery/SceneryPackRow.cs +++ b/src/OrthoStreamXP/Gui/Scenery/SceneryPackRow.cs @@ -6,7 +6,7 @@ namespace OrthoStreamXP.Gui; internal sealed class SceneryPackRow : ObservableObject { private readonly Func _switch; - private bool _enabled; + private bool _enabled, _highlighted; /// One of the packages the running mount shows to X-Plane. /// Writes the change; false when it could not, and the switch goes back. @@ -23,6 +23,13 @@ public SceneryPackRow(SceneryPackEntry entry, bool streamed, Func Entry.Path; public bool Streamed { get; } + /// The package last found with "Show in list": marked so it stands out in the whole list. + public bool IsHighlighted + { + get => _highlighted; + set => Set(ref _highlighted, value); + } + /// Whether X-Plane loads it: written to the file as soon as it is switched. public bool IsEnabled { diff --git a/src/OrthoStreamXP/Gui/Scenery/SceneryPackSearch.cs b/src/OrthoStreamXP/Gui/Scenery/SceneryPackSearch.cs new file mode 100644 index 0000000..af4c303 --- /dev/null +++ b/src/OrthoStreamXP/Gui/Scenery/SceneryPackSearch.cs @@ -0,0 +1,31 @@ +using System.Globalization; +using OrthoStreamXP.Scenery; + +namespace OrthoStreamXP.Gui; + +/// +/// What the Scenery page's search box keeps: the packages whose name or path contains the text, ignoring case and whether +/// the path is written with / or \. An empty search keeps every package. +/// +internal sealed class SceneryPackSearch(string? text) +{ + private readonly string _text = Normalize(text?.Trim() ?? ""); + + public bool IsEmpty => _text.Length == 0; + + public bool Matches(SceneryPackEntry entry) => + IsEmpty + || entry.Name.Contains(_text, StringComparison.OrdinalIgnoreCase) + || Normalize(entry.Path).Contains(_text, StringComparison.OrdinalIgnoreCase); + + /// "1,630 packages", or "3 of 1,630 packages" while searching; null for an empty list. + public string? CountText(int shown, int total) + { + if (total == 0) return null; + // Invariant, as the program runs (Program.cs): the same thousands separator on every machine. + string packages = string.Create(CultureInfo.InvariantCulture, $"{total:N0} {(total == 1 ? "package" : "packages")}"); + return IsEmpty ? packages : string.Create(CultureInfo.InvariantCulture, $"{shown:N0} of {packages}"); + } + + private static string Normalize(string path) => path.Replace('\\', '/'); +} diff --git a/src/OrthoStreamXP/Gui/ViewModels/SceneryViewModel.cs b/src/OrthoStreamXP/Gui/ViewModels/SceneryViewModel.cs index a30f6b3..0e72fcf 100644 --- a/src/OrthoStreamXP/Gui/ViewModels/SceneryViewModel.cs +++ b/src/OrthoStreamXP/Gui/ViewModels/SceneryViewModel.cs @@ -1,4 +1,6 @@ using System.Collections.ObjectModel; +using System.ComponentModel; +using System.Windows.Data; using System.Windows.Input; using OrthoStreamXP.Scenery; @@ -13,20 +15,28 @@ internal sealed class SceneryViewModel : ObservableObject, IPage { private readonly MountController _mount; private readonly Func _xplane; + private readonly ICollectionView _shown; private string? _message; + private string _searchText = ""; + private SceneryPackSearch _search = new(null); /// The X-Plane folder of the settings; null while there is none. public SceneryViewModel(MountController mount, Func xplane) { _mount = mount; _xplane = xplane; + // The list on the page shows this view of Rows: the rows the search keeps, in the file's order. + _shown = CollectionViewSource.GetDefaultView(Rows); + _shown.Filter = row => _search.Matches(((SceneryPackRow)row).Entry); Refresh = new RelayCommand(Load); OpenFolder = new RelayCommand(() => Shell.Open(CustomScenery!), () => CustomScenery is { } folder && Directory.Exists(folder)); _mount.PropertyChanged += (_, e) => { if (e.PropertyName != nameof(MountController.State)) return; Raise(nameof(CanEdit)); + Raise(nameof(CanDrag)); Raise(nameof(RunningNote)); + RaiseCount(); RelayCommand.Refresh(); if (_mount.IsRunning || _mount.IsStopped) Load(); }; @@ -39,6 +49,52 @@ public SceneryViewModel(MountController mount, Func xplane) /// The list can be changed only while OrthoStreamXP is stopped: starting and stopping change the file too. public bool CanEdit => _mount.IsStopped; + /// + /// Rows are dragged only while every row is shown: between two rows a search keeps, hundreds may be hidden, so where a + /// drop lands would be a guess. + /// + public bool CanDrag => CanEdit && _search.IsEmpty; + + /// Part of a package's name or path; kept while the list is read again. + public string Search + { + get => _searchText; + set + { + if (!Set(ref _searchText, value ?? "")) return; + _search = new SceneryPackSearch(_searchText); + _shown.Refresh(); + Raise(nameof(IsSearching)); + Raise(nameof(CanDrag)); + RaiseCount(); + } + } + + /// Whether the search hides some rows; then each row offers "Show in list". + public bool IsSearching => !_search.IsEmpty; + + /// + /// Clears the search and highlights , so it can be found in the whole list and dragged to its new + /// place (the page scrolls to it). + /// + public void ShowInList(SceneryPackRow row) + { + foreach (SceneryPackRow other in Rows) other.IsHighlighted = false; + row.IsHighlighted = true; + Search = ""; + } + + /// How many packages the list has, and how many of them the search keeps. + public string? CountText => _search.CountText(Rows.Count(r => _search.Matches(r.Entry)), Rows.Count); + + /// While searching: why the rows cannot be dragged, or that nothing matches. + public string? SearchNote => + _search.IsEmpty || Rows.Count == 0 ? null + : Rows.Any(r => _search.Matches(r.Entry)) ? (CanEdit ? "Clear the search to drag packages into a new order." : null) + : $"No package matches \"{_searchText.Trim()}\"."; + + public bool HasSearchNote => SearchNote is not null; + public string? RunningNote => CanEdit ? null : "OrthoStreamXP is running: stop it to change the list."; public string? CustomScenery => _xplane() is { } xplane ? Path.Join(xplane, "Custom Scenery") : null; @@ -67,7 +123,11 @@ private void Load() Message = null; Raise(nameof(FileText)); RelayCommand.Refresh(); - if (CustomScenery is not { } folder) return; + if (CustomScenery is not { } folder) + { + RaiseCount(); + return; + } var list = new SceneryPackList(folder); try { @@ -80,6 +140,17 @@ private void Load() { Message = $"Could not read {list.FilePath}: {ex.Message}"; } + finally + { + RaiseCount(); + } + } + + private void RaiseCount() + { + Raise(nameof(CountText)); + Raise(nameof(SearchNote)); + Raise(nameof(HasSearchNote)); } private bool Switch(SceneryPackRow row, bool enabled) @@ -105,7 +176,7 @@ private bool Switch(SceneryPackRow row, bool enabled) public void Drop(SceneryPackRow row, int insertAt) { int from = Rows.IndexOf(row); - if (!CanEdit || CustomScenery is not { } folder || from < 0 || insertAt < 0 || insertAt > Rows.Count) return; + if (!CanDrag || CustomScenery is not { } folder || from < 0 || insertAt < 0 || insertAt > Rows.Count) return; int to = insertAt > from ? insertAt - 1 : insertAt; if (to == from) return; try diff --git a/src/OrthoStreamXP/Gui/Views/SceneryView.xaml b/src/OrthoStreamXP/Gui/Views/SceneryView.xaml index cfd4fef..74ac32d 100644 --- a/src/OrthoStreamXP/Gui/Views/SceneryView.xaml +++ b/src/OrthoStreamXP/Gui/Views/SceneryView.xaml @@ -19,6 +19,27 @@ + + + + + + + + + + + + + + + - + + + + + + + Visibility="{Binding DataContext.CanDrag, RelativeSource={RelativeSource AncestorType=ItemsControl}, Converter={StaticResource Visible}}" /> @@ -51,7 +85,11 @@ - + diff --git a/src/OrthoStreamXP/Gui/Views/SceneryView.xaml.cs b/src/OrthoStreamXP/Gui/Views/SceneryView.xaml.cs index 3368181..416d3d0 100644 --- a/src/OrthoStreamXP/Gui/Views/SceneryView.xaml.cs +++ b/src/OrthoStreamXP/Gui/Views/SceneryView.xaml.cs @@ -3,6 +3,7 @@ using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; +using System.Windows.Threading; namespace OrthoStreamXP.Gui; @@ -28,6 +29,31 @@ internal sealed partial class SceneryView private SceneryViewModel? Model => DataContext as SceneryViewModel; + /// + /// "Show in list" on a row the search kept: the search is cleared and the page scrolls so the row, now highlighted, sits in + /// the middle of the whole list, ready to be dragged. + /// + private void OnShowInList(object sender, RoutedEventArgs e) + { + if ((sender as FrameworkElement)?.DataContext is not SceneryPackRow row || Model is not { } model) return; + model.ShowInList(row); + // Once the list has laid out every row again. + Dispatcher.BeginInvoke(DispatcherPriority.Loaded, () => + { + if (List.ItemContainerGenerator.ContainerFromItem(row) is not FrameworkElement container) return; + double top = container.TranslatePoint(default, Scroller).Y; + Scroller.ScrollToVerticalOffset(Scroller.VerticalOffset + top - (Scroller.ActualHeight - container.ActualHeight) / 2); + }); + } + + /// Esc empties the search box, which shows every package again. + private void OnSearchKeyDown(object sender, KeyEventArgs e) + { + if (e.Key != Key.Escape || SearchBox.Text.Length == 0) return; + SearchBox.Clear(); + e.Handled = true; + } + private void OnRowMouseDown(object sender, MouseButtonEventArgs e) { _pressed = IsOnButton(e.OriginalSource as DependencyObject) ? null : (sender as FrameworkElement)?.DataContext as SceneryPackRow; @@ -37,7 +63,7 @@ private void OnRowMouseDown(object sender, MouseButtonEventArgs e) private void OnRowMouseMove(object sender, MouseEventArgs e) { - if (_pressed is not { } row || e.LeftButton != MouseButtonState.Pressed || Model is not { CanEdit: true }) return; + if (_pressed is not { } row || e.LeftButton != MouseButtonState.Pressed || Model is not { CanDrag: true }) return; Vector moved = e.GetPosition(this) - _pressedAt; if (Math.Abs(moved.X) < SystemParameters.MinimumHorizontalDragDistance && Math.Abs(moved.Y) < SystemParameters.MinimumVerticalDragDistance) return; _pressed = null; diff --git a/tests/OrthoStreamXP.Tests/SceneryPackSearchTests.cs b/tests/OrthoStreamXP.Tests/SceneryPackSearchTests.cs new file mode 100644 index 0000000..4968fdc --- /dev/null +++ b/tests/OrthoStreamXP.Tests/SceneryPackSearchTests.cs @@ -0,0 +1,112 @@ +using System.Globalization; +using OrthoStreamXP.Gui; +using OrthoStreamXP.Scenery; + +namespace OrthoStreamXP.Tests; + +public sealed class SceneryPackSearchTests +{ + private static readonly SceneryPackEntry Denver = new("Custom Scenery/KDEN - Denver International Airport/", true); + private static readonly SceneryPackEntry OrthoTile = new(@"D:\Ortho4XP\Tiles\zOrtho4XP_+39-105/", false); + private static readonly SceneryPackEntry GlobalAirports = new("*GLOBAL_AIRPORTS*", true); + + [Theory] + [InlineData(null)] + [InlineData("")] + [InlineData(" ")] + public void An_empty_search_keeps_every_package(string? text) + { + var search = new SceneryPackSearch(text); + + Assert.True(search.IsEmpty); + Assert.True(search.Matches(Denver)); + Assert.True(search.Matches(OrthoTile)); + } + + [Theory] + [InlineData("kden")] + [InlineData(" KDEN ")] + [InlineData("denver international")] + public void The_name_matches_ignoring_case_and_surrounding_spaces(string text) + { + var search = new SceneryPackSearch(text); + + Assert.True(search.Matches(Denver)); + Assert.False(search.Matches(OrthoTile)); + } + + [Theory] + [InlineData(@"D:\Ortho4XP\Tiles")] + [InlineData("d:/ortho4xp/tiles")] + public void The_path_matches_whichever_slashes_it_is_written_with(string text) + { + var search = new SceneryPackSearch(text); + + Assert.True(search.Matches(OrthoTile)); + Assert.False(search.Matches(Denver)); + } + + [Fact] + public void Custom_scenery_paths_match_with_a_backslash_too() + { + Assert.True(new SceneryPackSearch(@"Custom Scenery\KDEN").Matches(Denver)); + } + + [Fact] + public void X_planes_own_entries_match_by_name() + { + Assert.True(new SceneryPackSearch("global_airports").Matches(GlobalAirports)); + } + + [Fact] + public void A_search_that_matches_nothing_keeps_nothing() + { + var search = new SceneryPackSearch("KLAX"); + + Assert.False(search.IsEmpty); + Assert.False(search.Matches(Denver)); + Assert.False(search.Matches(OrthoTile)); + Assert.False(search.Matches(GlobalAirports)); + } + + [Fact] + public void The_count_shows_every_package_without_a_search() + { + var search = new SceneryPackSearch(""); + + Assert.Equal("1,630 packages", search.CountText(1630, 1630)); + Assert.Equal("1 package", search.CountText(1, 1)); + } + + [Fact] + public void The_count_shows_the_matches_out_of_every_package_while_searching() + { + var search = new SceneryPackSearch("kden"); + + Assert.Equal("3 of 1,630 packages", search.CountText(3, 1630)); + Assert.Equal("0 of 1,630 packages", search.CountText(0, 1630)); + } + + [Fact] + public void The_count_is_written_the_same_in_every_windows_language() + { + CultureInfo before = CultureInfo.CurrentCulture; + try + { + CultureInfo.CurrentCulture = CultureInfo.GetCultureInfo("de-DE"); // 1.630 there + + Assert.Equal("3 of 1,630 packages", new SceneryPackSearch("kden").CountText(3, 1630)); + } + finally + { + CultureInfo.CurrentCulture = before; + } + } + + [Fact] + public void An_empty_list_has_no_count() + { + Assert.Null(new SceneryPackSearch("").CountText(0, 0)); + Assert.Null(new SceneryPackSearch("kden").CountText(0, 0)); + } +} diff --git a/tests/OrthoStreamXP.Tests/SceneryViewModelTests.cs b/tests/OrthoStreamXP.Tests/SceneryViewModelTests.cs new file mode 100644 index 0000000..1dcb4a7 --- /dev/null +++ b/tests/OrthoStreamXP.Tests/SceneryViewModelTests.cs @@ -0,0 +1,180 @@ +using System.Windows.Data; +using OrthoStreamXP.Gui; + +namespace OrthoStreamXP.Tests; + +public sealed class SceneryViewModelTests : IDisposable +{ + private const string Packs = + "I\r\n1000 Version\r\nSCENERY\r\n\r\n" + + "SCENERY_PACK Custom Scenery/KDEN - Denver International Airport/\r\n" + + "SCENERY_PACK *GLOBAL_AIRPORTS*\r\n" + + "SCENERY_PACK_DISABLED Custom Scenery/SFD_KLAX_Los_Angeles_HD_2_Mesh/\r\n" + + "SCENERY_PACK Custom Scenery/Z KDEN Mesh/\r\n"; + + private readonly TempTree _tree = new(); + + public SceneryViewModelTests() => _tree.WriteText("X-Plane 12/Custom Scenery/scenery_packs.ini", Packs); + + public void Dispose() => _tree.Dispose(); + + private string FileText => File.ReadAllText(_tree.PathOf("X-Plane 12/Custom Scenery/scenery_packs.ini")); + + private SceneryViewModel Page() + { + var page = new SceneryViewModel(new MountController(), () => _tree.PathOf("X-Plane 12")); + page.OnShown(); + return page; + } + + /// The rows the page's list shows: the view of Rows the search filters. + private static List Shown(SceneryViewModel page) => + [.. CollectionViewSource.GetDefaultView(page.Rows).Cast().Select(r => r.Name)]; + + private static SceneryPackRow Row(SceneryViewModel page, string name) => page.Rows.Single(r => r.Name == name); + + [Fact] + public void Without_a_search_every_package_is_shown_and_can_be_dragged() + { + SceneryViewModel page = Page(); + + Assert.Equal(["KDEN - Denver International Airport", "*GLOBAL_AIRPORTS*", "SFD_KLAX_Los_Angeles_HD_2_Mesh", "Z KDEN Mesh"], Shown(page)); + Assert.Equal("4 packages", page.CountText); + Assert.False(page.IsSearching); + Assert.True(page.CanDrag); + Assert.Null(page.SearchNote); + } + + [Fact] + public void A_search_shows_only_the_matching_packages_in_the_files_order() + { + SceneryViewModel page = Page(); + + page.Search = "kden"; + + Assert.Equal(["KDEN - Denver International Airport", "Z KDEN Mesh"], Shown(page)); + Assert.Equal(4, page.Rows.Count); // nothing is taken out of the list itself + Assert.Equal("2 of 4 packages", page.CountText); + Assert.True(page.IsSearching); + } + + [Fact] + public void While_searching_rows_cannot_be_dragged_and_a_drop_changes_nothing() + { + SceneryViewModel page = Page(); + page.Search = "kden"; + + page.Drop(Row(page, "Z KDEN Mesh"), 0); + + Assert.False(page.CanDrag); + Assert.Equal("Clear the search to drag packages into a new order.", page.SearchNote); + Assert.Equal(Packs, FileText); + Assert.Equal("Z KDEN Mesh", page.Rows[^1].Name); + } + + [Fact] + public void Once_the_search_is_cleared_a_drop_moves_the_package() + { + SceneryViewModel page = Page(); + page.Search = "kden"; + page.Search = ""; + + page.Drop(Row(page, "Z KDEN Mesh"), 0); + + Assert.True(page.CanDrag); + Assert.Equal("Z KDEN Mesh", page.Rows[0].Name); + Assert.StartsWith("I\r\n1000 Version\r\nSCENERY\r\n\r\nSCENERY_PACK Custom Scenery/Z KDEN Mesh/", FileText, StringComparison.Ordinal); + } + + [Fact] + public void A_search_that_matches_nothing_says_so() + { + SceneryViewModel page = Page(); + + page.Search = " KSEZ "; + + Assert.Empty(Shown(page)); + Assert.Equal("0 of 4 packages", page.CountText); + Assert.Equal("No package matches \"KSEZ\".", page.SearchNote); + } + + [Fact] + public void The_search_stays_when_the_list_is_read_again() + { + SceneryViewModel page = Page(); + page.Search = "mesh"; + + page.Refresh.Execute(null); + + Assert.Equal(["SFD_KLAX_Los_Angeles_HD_2_Mesh", "Z KDEN Mesh"], Shown(page)); + Assert.Equal("2 of 4 packages", page.CountText); + } + + [Fact] + public void A_switch_flipped_while_searching_changes_that_package_alone() + { + SceneryViewModel page = Page(); + page.Search = "kden"; + + // Second of the rows shown, fourth in the file: the switch must find it by the package, not by where it is shown. + Assert.Equal(["KDEN - Denver International Airport", "Z KDEN Mesh"], Shown(page)); + Row(page, "Z KDEN Mesh").IsEnabled = false; + + Assert.Equal(Packs.Replace("SCENERY_PACK Custom Scenery/Z KDEN Mesh/", "SCENERY_PACK_DISABLED Custom Scenery/Z KDEN Mesh/", StringComparison.Ordinal), FileText); + Assert.False(Row(page, "Z KDEN Mesh").IsEnabled); + Assert.True(Row(page, "KDEN - Denver International Airport").IsEnabled); + } + + [Fact] + public void Reading_the_list_again_removes_the_highlight() + { + SceneryViewModel page = Page(); + page.ShowInList(Row(page, "Z KDEN Mesh")); + + page.Refresh.Execute(null); + + Assert.DoesNotContain(page.Rows, r => r.IsHighlighted); + } + + [Fact] + public void The_search_keeps_packages_added_to_the_file_since_it_was_read() + { + SceneryViewModel page = Page(); + page.Search = "kden"; + _tree.WriteText("X-Plane 12/Custom Scenery/scenery_packs.ini", Packs + "SCENERY_PACK Custom Scenery/Y KDEN Overlay/\r\n"); + + page.Refresh.Execute(null); + + Assert.Equal(["KDEN - Denver International Airport", "Z KDEN Mesh", "Y KDEN Overlay"], Shown(page)); + Assert.Equal("3 of 5 packages", page.CountText); + } + + [Fact] + public void Without_an_x_plane_folder_a_search_shows_nothing_and_no_count() + { + var page = new SceneryViewModel(new MountController(), () => null); + page.OnShown(); + + page.Search = "kden"; + + Assert.Empty(Shown(page)); + Assert.Null(page.CountText); + Assert.Null(page.SearchNote); + } + + [Fact] + public void Show_in_list_clears_the_search_and_highlights_only_that_package() + { + SceneryViewModel page = Page(); + page.Search = "kden"; + page.ShowInList(Row(page, "KDEN - Denver International Airport")); + page.Search = "kden"; + + page.ShowInList(Row(page, "Z KDEN Mesh")); + + Assert.Equal("", page.Search); + Assert.Equal(4, Shown(page).Count); + Assert.True(page.CanDrag); + Assert.Equal(["Z KDEN Mesh"], page.Rows.Where(r => r.IsHighlighted).Select(r => r.Name)); + } +}