| | | 1 | | // ----------------------------------------------------------------------- |
| | | 2 | | // <copyright file="NavigationJournal.cs" company="Stéphane ANDRE"> |
| | | 3 | | // Copyright (c) Stéphane ANDRE. All rights reserved. |
| | | 4 | | // </copyright> |
| | | 5 | | // ----------------------------------------------------------------------- |
| | | 6 | | |
| | | 7 | | using System.Collections.Generic; |
| | | 8 | | using MyNet.UI.Navigation.Models; |
| | | 9 | | |
| | | 10 | | namespace MyNet.UI.Navigation; |
| | | 11 | | |
| | | 12 | | /// <inheritdoc /> |
| | | 13 | | public sealed class NavigationJournal : INavigationJournal |
| | | 14 | | { |
| | 42 | 15 | | private readonly Stack<NavigationContext> _back = new(); |
| | 42 | 16 | | private readonly Stack<NavigationContext> _forward = new(); |
| | | 17 | | |
| | | 18 | | /// <inheritdoc /> |
| | 21 | 19 | | public IReadOnlyList<NavigationContext> BackStack => [.. _back]; |
| | | 20 | | |
| | | 21 | | /// <inheritdoc /> |
| | 18 | 22 | | public IReadOnlyList<NavigationContext> ForwardStack => [.. _forward]; |
| | | 23 | | |
| | | 24 | | /// <inheritdoc /> |
| | 12 | 25 | | public NavigationContext? PeekBack() => _back.Count > 0 ? _back.Peek() : null; |
| | | 26 | | |
| | | 27 | | /// <inheritdoc /> |
| | 9 | 28 | | public NavigationContext? PeekForward() => _forward.Count > 0 ? _forward.Peek() : null; |
| | | 29 | | |
| | | 30 | | /// <inheritdoc /> |
| | 24 | 31 | | public void PushBack(NavigationContext context) => _back.Push(context); |
| | | 32 | | |
| | | 33 | | /// <inheritdoc /> |
| | 9 | 34 | | public void PushForward(NavigationContext context) => _forward.Push(context); |
| | | 35 | | |
| | | 36 | | /// <inheritdoc /> |
| | 9 | 37 | | public NavigationContext? PopBack() => _back.Count > 0 ? _back.Pop() : null; |
| | | 38 | | |
| | | 39 | | /// <inheritdoc /> |
| | 9 | 40 | | public NavigationContext? PopForward() => _forward.Count > 0 ? _forward.Pop() : null; |
| | | 41 | | |
| | | 42 | | /// <inheritdoc /> |
| | | 43 | | public void Clear() |
| | | 44 | | { |
| | 6 | 45 | | _back.Clear(); |
| | 6 | 46 | | _forward.Clear(); |
| | 6 | 47 | | } |
| | | 48 | | |
| | | 49 | | /// <inheritdoc /> |
| | 45 | 50 | | public void ClearForward() => _forward.Clear(); |
| | | 51 | | } |
| | | 52 | | |