mirror of https://github.com/icsharpcode/ILSpy.git
Browse Source
Tree-node selection now updates the inner Content of one persistent ContentTabPage instead of swapping the dockable in the dock. The wrapper view (ContentTabPageView) keeps both inner views — the decompiler text editor and the metadata grid — pre-realised in the visual tree from construction time and toggles which is visible based on Content's runtime type. Assisted-by: Claude:claude-opus-4-7:Claude Codepull/3755/head
12 changed files with 314 additions and 190 deletions
@ -0,0 +1,64 @@ |
|||||||
|
// 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.ComponentModel; |
||||||
|
|
||||||
|
using CommunityToolkit.Mvvm.ComponentModel; |
||||||
|
|
||||||
|
namespace ILSpy.ViewModels |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// The single Document the docking host puts in its document area. <see cref="Content"/>
|
||||||
|
/// holds the active inner viewmodel (decompiler text or metadata grid). The wrapper
|
||||||
|
/// view (<c>ContentTabPageView</c>) keeps both possible inner views pre-realised and
|
||||||
|
/// toggles which is visible — Dock.Avalonia's add+close-in-the-same-tick semantics
|
||||||
|
/// otherwise leave the previous view rendered when the tab type changes.
|
||||||
|
/// </summary>
|
||||||
|
public sealed partial class ContentTabPage : TabPageModel |
||||||
|
{ |
||||||
|
[ObservableProperty] |
||||||
|
private object? content; |
||||||
|
|
||||||
|
// Bubble the inner content's Title up to the Document's Title so the tab strip
|
||||||
|
// reflects whatever the active page chose (e.g. the decompiler tab's spinner glyph
|
||||||
|
// or "DOS Header" for a metadata grid).
|
||||||
|
partial void OnContentChanged(object? oldValue, object? newValue) |
||||||
|
{ |
||||||
|
if (oldValue is INotifyPropertyChanged oldNotify) |
||||||
|
oldNotify.PropertyChanged -= OnContentPropertyChanged; |
||||||
|
if (newValue is INotifyPropertyChanged newNotify) |
||||||
|
newNotify.PropertyChanged += OnContentPropertyChanged; |
||||||
|
SyncTitleFromContent(); |
||||||
|
} |
||||||
|
|
||||||
|
void OnContentPropertyChanged(object? sender, PropertyChangedEventArgs e) |
||||||
|
{ |
||||||
|
if (e.PropertyName == nameof(Title)) |
||||||
|
SyncTitleFromContent(); |
||||||
|
} |
||||||
|
|
||||||
|
void SyncTitleFromContent() |
||||||
|
{ |
||||||
|
if (Content is null) |
||||||
|
return; |
||||||
|
var titleProp = Content.GetType().GetProperty(nameof(Title), typeof(string)); |
||||||
|
if (titleProp?.GetValue(Content) is string s) |
||||||
|
Title = s; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,22 @@ |
|||||||
|
<UserControl xmlns="https://github.com/avaloniaui" |
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
||||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" |
||||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" |
||||||
|
xmlns:vm="using:ILSpy.ViewModels" |
||||||
|
xmlns:textView="using:ILSpy.TextView" |
||||||
|
xmlns:metaViews="using:ILSpy.Views" |
||||||
|
mc:Ignorable="d" d:DesignWidth="600" d:DesignHeight="400" |
||||||
|
x:Class="ILSpy.Views.ContentTabPageView" |
||||||
|
x:DataType="vm:ContentTabPage"> |
||||||
|
|
||||||
|
<!-- Both inner views are pre-realised; only the one matching Content's runtime type |
||||||
|
is visible. Code-behind toggles IsVisible and DataContext on Content change. |
||||||
|
Avoids Dock's add+close-in-the-same-tick visual-staleness when the tab type |
||||||
|
changes (the previous view would otherwise stay rendered until the next layout |
||||||
|
pass). --> |
||||||
|
<Panel> |
||||||
|
<textView:DecompilerTextView Name="DecompilerView" /> |
||||||
|
<metaViews:MetadataTablePage Name="MetadataView" /> |
||||||
|
</Panel> |
||||||
|
|
||||||
|
</UserControl> |
||||||
@ -0,0 +1,94 @@ |
|||||||
|
// 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.ComponentModel; |
||||||
|
|
||||||
|
using Avalonia.Controls; |
||||||
|
using Avalonia.Markup.Xaml; |
||||||
|
|
||||||
|
using ILSpy.TextView; |
||||||
|
using ILSpy.ViewModels; |
||||||
|
|
||||||
|
namespace ILSpy.Views |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// View for <see cref="ContentTabPage"/>. Toggles which pre-realised inner view shows
|
||||||
|
/// (decompiler text or metadata grid) based on <see cref="ContentTabPage.Content"/>'s
|
||||||
|
/// runtime type — both inner views live in the visual tree from construction time so
|
||||||
|
/// the dock's visual swap is just a visibility flip.
|
||||||
|
/// </summary>
|
||||||
|
public partial class ContentTabPageView : UserControl |
||||||
|
{ |
||||||
|
ContentTabPage? boundPage; |
||||||
|
DecompilerTextView decompilerView = null!; |
||||||
|
MetadataTablePage metadataView = null!; |
||||||
|
|
||||||
|
public ContentTabPageView() |
||||||
|
{ |
||||||
|
InitializeComponent(); |
||||||
|
decompilerView = this.FindControl<DecompilerTextView>("DecompilerView")!; |
||||||
|
metadataView = this.FindControl<MetadataTablePage>("MetadataView")!; |
||||||
|
DataContextChanged += (_, _) => RebindPage(); |
||||||
|
} |
||||||
|
|
||||||
|
void InitializeComponent() => AvaloniaXamlLoader.Load(this); |
||||||
|
|
||||||
|
void RebindPage() |
||||||
|
{ |
||||||
|
if (boundPage != null) |
||||||
|
boundPage.PropertyChanged -= OnPagePropertyChanged; |
||||||
|
boundPage = DataContext as ContentTabPage; |
||||||
|
if (boundPage != null) |
||||||
|
boundPage.PropertyChanged += OnPagePropertyChanged; |
||||||
|
ApplyContent(); |
||||||
|
} |
||||||
|
|
||||||
|
void OnPagePropertyChanged(object? sender, PropertyChangedEventArgs e) |
||||||
|
{ |
||||||
|
if (e.PropertyName == nameof(ContentTabPage.Content)) |
||||||
|
ApplyContent(); |
||||||
|
} |
||||||
|
|
||||||
|
void ApplyContent() |
||||||
|
{ |
||||||
|
var content = boundPage?.Content; |
||||||
|
|
||||||
|
if (content is DecompilerTabPageModel decompiler) |
||||||
|
{ |
||||||
|
decompilerView.DataContext = decompiler; |
||||||
|
decompilerView.IsVisible = true; |
||||||
|
} |
||||||
|
else |
||||||
|
{ |
||||||
|
decompilerView.IsVisible = false; |
||||||
|
decompilerView.DataContext = null; |
||||||
|
} |
||||||
|
|
||||||
|
if (content is MetadataTablePageModel metadata) |
||||||
|
{ |
||||||
|
metadataView.DataContext = metadata; |
||||||
|
metadataView.IsVisible = true; |
||||||
|
} |
||||||
|
else |
||||||
|
{ |
||||||
|
metadataView.IsVisible = false; |
||||||
|
metadataView.DataContext = null; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue