mirror of https://github.com/icsharpcode/ILSpy.git
Browse Source
Generalises NavigationHistory<SharpTreeNode> into NavigationHistory<NavigationEntry> with two subtypes — TreeNodeEntry (a tree-node selection in a specific tab) and StaticPageEntry (a static page like About in a specific tab) — mirroring the WPF host's NavigationState/ViewState pair. Assisted-by: Claude:claude-opus-4-7:Claude Codepull/3755/head
8 changed files with 298 additions and 48 deletions
@ -0,0 +1,111 @@
@@ -0,0 +1,111 @@
|
||||
// Copyright (c) 2026 AlphaSierraPapa for the SharpDevelop Team
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
||||
// software and associated documentation files (the "Software"), to deal in the Software
|
||||
// without restriction, including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
|
||||
// to whom the Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all copies or
|
||||
// substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
||||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
using System; |
||||
using System.Runtime.CompilerServices; |
||||
|
||||
using Avalonia.Media; |
||||
|
||||
using ICSharpCode.ILSpyX.TreeView; |
||||
|
||||
using ILSpy.ViewModels; |
||||
|
||||
namespace ILSpy.Navigation |
||||
{ |
||||
/// <summary>
|
||||
/// One stop on the back/forward stack: a (tab, target) pair where the target is either a
|
||||
/// tree-node selection or a static-page URI. The tab pointer lets navigation jump back to
|
||||
/// the document the user was viewing when this entry was recorded.
|
||||
/// </summary>
|
||||
public abstract class NavigationEntry : IEquatable<NavigationEntry?> |
||||
{ |
||||
public TabPageModel Tab { get; } |
||||
|
||||
protected NavigationEntry(TabPageModel tab) |
||||
{ |
||||
Tab = tab ?? throw new ArgumentNullException(nameof(tab)); |
||||
} |
||||
|
||||
/// <summary>Header text shown in the back/forward dropdown.</summary>
|
||||
public abstract object DisplayText { get; } |
||||
|
||||
/// <summary>Icon shown next to the entry in the back/forward dropdown.</summary>
|
||||
public virtual IImage? DisplayIcon => null; |
||||
|
||||
public abstract bool Equals(NavigationEntry? other); |
||||
|
||||
public override bool Equals(object? obj) => Equals(obj as NavigationEntry); |
||||
|
||||
public abstract override int GetHashCode(); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// History entry for a tree-node selection. Replaying activates the recorded tab and sets
|
||||
/// the assembly-tree selection to <see cref="Node"/>.
|
||||
/// </summary>
|
||||
public sealed class TreeNodeEntry : NavigationEntry |
||||
{ |
||||
public SharpTreeNode Node { get; } |
||||
|
||||
public TreeNodeEntry(TabPageModel tab, SharpTreeNode node) |
||||
: base(tab) |
||||
{ |
||||
Node = node ?? throw new ArgumentNullException(nameof(node)); |
||||
} |
||||
|
||||
public override object DisplayText => Node.Text ?? string.Empty; |
||||
|
||||
public override IImage? DisplayIcon => Node.Icon as IImage; |
||||
|
||||
public override bool Equals(NavigationEntry? other) => |
||||
other is TreeNodeEntry t |
||||
&& ReferenceEquals(t.Tab, Tab) |
||||
&& ReferenceEquals(t.Node, Node); |
||||
|
||||
public override int GetHashCode() => HashCode.Combine( |
||||
RuntimeHelpers.GetHashCode(Tab), |
||||
RuntimeHelpers.GetHashCode(Node)); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// History entry for a static page (e.g. the About tab). Replaying just reactivates the
|
||||
/// recorded tab — the tab keeps its content because static pages opt out of being
|
||||
/// targeted by tree-node decompilation.
|
||||
/// </summary>
|
||||
public sealed class StaticPageEntry : NavigationEntry |
||||
{ |
||||
public Uri Uri { get; } |
||||
|
||||
public StaticPageEntry(TabPageModel tab, Uri uri) |
||||
: base(tab) |
||||
{ |
||||
Uri = uri ?? throw new ArgumentNullException(nameof(uri)); |
||||
} |
||||
|
||||
public override object DisplayText => Tab.Title ?? Uri.ToString(); |
||||
|
||||
public override bool Equals(NavigationEntry? other) => |
||||
other is StaticPageEntry s |
||||
&& ReferenceEquals(s.Tab, Tab) |
||||
&& Equals(s.Uri, Uri); |
||||
|
||||
public override int GetHashCode() => HashCode.Combine( |
||||
RuntimeHelpers.GetHashCode(Tab), |
||||
Uri); |
||||
} |
||||
} |
||||
Loading…
Reference in new issue