Skip to content

Commit

Permalink
refactor(ui): expose PageService pages
Browse files Browse the repository at this point in the history
This allows switching between pages and modifying stuff from outside of
that page. Used by Entity Review page's SwitchToEntityEditor method to
switch to the Entity Editor and set its filters.
  • Loading branch information
tsa96 committed Feb 8, 2025
1 parent 86cc86a commit ef2b133
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/Lumper.UI/Services/PageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public sealed class PageService : ReactiveObject
// Collection of all available pages.
// For performance, ViewModels are only constructed when the pages are accessed.
// When a new BSP is loaded, any inactive ephemeral viewmodels are discarded.
private readonly Dictionary<Page, ILazyPage<ViewModel>> _pageVms = new()
public Dictionary<Page, ILazyPage<ViewModel>> Pages { get; } =
new()
{
{ Page.EntityEditor, new LazyPage<EntityEditorViewModel>(true) },
Expand Down Expand Up @@ -68,7 +68,7 @@ private PageService() =>
.ObserveOn(RxApp.MainThreadScheduler)
.Subscribe(_ =>
{
foreach ((Page page, ILazyPage<ViewModel> pageVm) in _pageVms)
foreach ((Page page, ILazyPage<ViewModel> pageVm) in Pages)
{
// When active BSP file changes (incl. closing), reset any page that is
// - loaded
Expand All @@ -91,7 +91,7 @@ public void ViewPage(Page page)
if (page == ActivePage)
return;

if (!_pageVms.TryGetValue(page, out ILazyPage<ViewModel>? pageVm))
if (!Pages.TryGetValue(page, out ILazyPage<ViewModel>? pageVm))
throw new ArgumentException($"Bad page name {page}");

PreviousPage = ActivePage;
Expand All @@ -111,7 +111,7 @@ public void ViewPage(Page page)

// This wrapper interface + class is required because we need a covariant type for Get(),
// so that e.g. LazyPage<VtfBrowserViewModel> is assignable to LazyPage<ViewModel>.
private interface ILazyPage<out T>
public interface ILazyPage<out T>
{
public bool Ephemeral { get; }

Expand Down

0 comments on commit ef2b133

Please sign in to comment.