Skip to content

Commit

Permalink
Merge pull request #1526 from erri120/feat/1255-ephermeral-context
Browse files Browse the repository at this point in the history
Add ephemeral page context
erri120 authored Jun 4, 2024
2 parents c6ad98e + ee086d1 commit d99eabe
Showing 7 changed files with 35 additions and 7 deletions.
5 changes: 5 additions & 0 deletions src/NexusMods.App.UI/Extensions/EnumerableExtensions.cs
Original file line number Diff line number Diff line change
@@ -4,6 +4,11 @@ namespace NexusMods.App.UI.Extensions;

public static class EnumerableExtensions
{
public static IEnumerable<T> NotNull<T>(this IEnumerable<T?> source) where T : class
{
return source.Where(x => x is not null).Select(x => x!);
}

/// <summary>
/// Creates a new <see cref="ObservableCollection{T}"/> from an <see cref="IEnumerable{T}"/>.
/// </summary>
3 changes: 3 additions & 0 deletions src/NexusMods.App.UI/NexusMods.App.UI.csproj
Original file line number Diff line number Diff line change
@@ -556,6 +556,9 @@
<Compile Update="Pages\LoadoutGrid\LoadoutGridDesignViewModel.cs">
<DependentUpon>ILoadoutGridViewModel.cs</DependentUpon>
</Compile>
<Compile Update="WorkspaceSystem\WorkspaceController\WorkspaceController.cs">
<DependentUpon>IWorkspaceController.cs</DependentUpon>
</Compile>
</ItemGroup>

<ItemGroup>
Original file line number Diff line number Diff line change
@@ -9,6 +9,9 @@ namespace NexusMods.App.UI.Pages.Diagnostics;
public record DiagnosticDetailsPageContext : IPageFactoryContext
{
public required Diagnostic Diagnostic { get; init; }

/// <inheritdoc/>
public bool IsEphemeral => true;
}

[UsedImplicitly]
Original file line number Diff line number Diff line change
@@ -3,4 +3,11 @@ namespace NexusMods.App.UI.WorkspaceSystem;
/// <summary>
/// Interface for contexts used by the <see cref="IPageFactory"/>.
/// </summary>
public interface IPageFactoryContext { }
public interface IPageFactoryContext
{
/// <summary>
/// Gets whether the context is ephemeral in nature and should not be
/// persisted.
/// </summary>
bool IsEphemeral => false;
}
14 changes: 11 additions & 3 deletions src/NexusMods.App.UI/WorkspaceSystem/Panel/PanelViewModel.cs
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@
using DynamicData;
using DynamicData.Aggregation;
using DynamicData.Kernel;
using NexusMods.App.UI.Extensions;
using NexusMods.App.UI.Windows;
using NexusMods.Extensions.BCL;
using ReactiveUI;
@@ -204,8 +205,8 @@ public PanelData ToData()
return new PanelData
{
LogicalBounds = LogicalBounds,
Tabs = _tabs.Select(tab => tab.ToData()).ToArray(),
SelectedTabId = SelectedTabId
Tabs = _tabs.Select(tab => tab.ToData()).NotNull().ToArray(),
SelectedTabId = SelectedTabId,
};
}

@@ -237,6 +238,13 @@ public void FromData(PanelData data)
}
});

SelectedTabId = data.SelectedTabId;
if (data.Tabs.Length == 0)
{
AddDefaultTab();
}
else
{
SelectedTabId = data.SelectedTabId;
}
}
}
Original file line number Diff line number Diff line change
@@ -25,5 +25,5 @@ public interface IPanelTabViewModel : IViewModelInterface
/// <summary>
/// Transforms the current state of the tab into a serializable data format.
/// </summary>
public TabData ToData();
public TabData? ToData();
}
Original file line number Diff line number Diff line change
@@ -21,12 +21,14 @@ public PanelTabViewModel()
Header = new PanelTabHeaderViewModel(Id);
}

public TabData ToData()
public TabData? ToData()
{
if (Contents.PageData.Context.IsEphemeral) return null;

return new TabData
{
Id = Id,
PageData = Contents.PageData
PageData = Contents.PageData,
};
}
}

0 comments on commit d99eabe

Please sign in to comment.