Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add DebuggerTypeProxy for Shell #27989

Merged
merged 4 commits into from
Feb 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/Controls/src/Core/Shell/BaseShellItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace Microsoft.Maui.Controls
{
/// <include file="../../../docs/Microsoft.Maui.Controls/BaseShellItem.xml" path="Type[@FullName='Microsoft.Maui.Controls.BaseShellItem']/Docs/*" />
[DebuggerDisplay("Title = {Title}, Route = {Route}")]
[DebuggerTypeProxy(typeof(BaseShellItemDebugView))]
public class BaseShellItem : NavigableElement, IPropertyPropagationController, IVisualController, IFlowDirectionController, IWindowController
{
public event EventHandler Appearing;
Expand Down Expand Up @@ -558,6 +559,22 @@ internal static DataTemplate CreateDefaultFlyoutItemCell(BindableObject bo)
});
}


/// <summary>
/// Provides a debug view for the <see cref="BaseShellItem"/> class.
/// </summary>
/// <param name="baseShellItem">The <see cref="BaseShellItem"/> instance to debug.</param>
private protected class BaseShellItemDebugView(BaseShellItem baseShellItem)
{
public ImageSource Icon => baseShellItem.Icon;

public ImageSource FlyoutIcon => baseShellItem.FlyoutIcon;

public bool FlyoutItemIsVisible => baseShellItem.FlyoutItemIsVisible;

public string Route => baseShellItem.Route;
}

#if NETSTANDARD
sealed class OperatingSystem
{
Expand Down
22 changes: 22 additions & 0 deletions src/Controls/src/Core/Shell/Shell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
Expand All @@ -21,6 +22,7 @@ namespace Microsoft.Maui.Controls
{
/// <include file="../../../docs/Microsoft.Maui.Controls/Shell.xml" path="Type[@FullName='Microsoft.Maui.Controls.Shell']/Docs/*" />
[ContentProperty(nameof(Items))]
[DebuggerTypeProxy(typeof(ShellDebugView))]
public partial class Shell : Page, IShellController, IPropertyPropagationController, IPageContainer<Page>, IFlyoutView
{
/// <summary>
Expand Down Expand Up @@ -2150,5 +2152,25 @@ public NavigationImplWrapper(INavigation proxy, INavigation shellProxy)
protected override Task OnPushModal(Page modal, bool animated) => _shellProxy.PushModalAsync(modal, animated);
}
}


/// <summary>
/// Provides a debug view for the Shell class.
/// </summary>
/// <param name="shell">The Shell instance to debug.</param>
private sealed class ShellDebugView(Shell shell)
{
public Page CurrentPage => shell.CurrentPage;

public ShellNavigationState CurrentState => shell.CurrentState;

public Uri AbsoluteUrl => shell.CurrentState.FullLocation;

public FlyoutBehavior FlyoutBehavior => shell.FlyoutBehavior;

public IEnumerable FlyoutItems => shell.FlyoutItems;

public Window Windows => shell.Window;
}
}
}
15 changes: 15 additions & 0 deletions src/Controls/src/Core/Shell/ShellContentCollection.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
#nullable disable
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Diagnostics;
using System.Linq;

namespace Microsoft.Maui.Controls
{
[DebuggerDisplay("{GetDebuggerDisplay(), nq}")]
[DebuggerTypeProxy(typeof(ShellContentCollectionDebugView))]
internal sealed class ShellContentCollection : ShellElementCollection<ShellContent>
{
public ShellContentCollection() : base()
Expand Down Expand Up @@ -37,5 +41,16 @@ protected override void OnElementControllerRemoving(IElementController element)
if (element is IShellContentController controller)
controller.IsPageVisibleChanged -= OnIsPageVisibleChanged;
}

string GetDebuggerDisplay() => $"Count = {Count}";

/// <summary>
/// Provides a debug view for the <see cref="ShellContentCollection"/> class.
/// </summary>
/// <param name="collection">The <see cref="ShellSectionCollection"/> instance to debug.</param>
private sealed class ShellContentCollectionDebugView(ShellContentCollection collection)
{
public IReadOnlyCollection<ShellContent> VisibleItemsReadOnly => collection.VisibleItemsReadOnly;
}
}
}
15 changes: 15 additions & 0 deletions src/Controls/src/Core/Shell/ShellItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Linq;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using System.Diagnostics;
using Microsoft.Maui.Controls.Internals;

namespace Microsoft.Maui.Controls
Expand Down Expand Up @@ -51,6 +52,7 @@ public TabBar()
[ContentProperty(nameof(Items))]
[EditorBrowsable(EditorBrowsableState.Never)]
[TypeConverter(typeof(ShellItemConverter))]
[DebuggerTypeProxy(typeof(ShellItemDebugView))]
public class ShellItem : ShellGroupItem, IShellItemController, IElementConfiguration<ShellItem>, IPropertyPropagationController, IVisualTreeElement
{
#region PropertyKeys
Expand Down Expand Up @@ -368,5 +370,18 @@ public override object ConvertFrom(ITypeDescriptorContext context, System.Global
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
=> throw new NotSupportedException();
}

/// <summary>
/// Provides a debug view for the <see cref="ShellItem"/> class.
/// </summary>
/// <param name="shellItem">The <see cref="ShellItem"/> instance to debug.</param>
private sealed class ShellItemDebugView(ShellItem shellItem) : BaseShellItemDebugView(shellItem)
{
public ShellSection CurrentItem => shellItem.CurrentItem;

public IList<ShellSection> Items => shellItem.Items;

public Window Window => shellItem.Window;
}
}
}
15 changes: 15 additions & 0 deletions src/Controls/src/Core/Shell/ShellSection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Threading.Tasks;
Expand All @@ -22,6 +23,7 @@ public class Tab : ShellSection
[ContentProperty(nameof(Items))]
[EditorBrowsable(EditorBrowsableState.Never)]
[TypeConverter(typeof(ShellSectionTypeConverter))]
[DebuggerTypeProxy(typeof(ShellSectionDebugView))]
public partial class ShellSection : ShellGroupItem, IShellSectionController, IPropertyPropagationController, IVisualTreeElement, IStackNavigation
{
#region PropertyKeys
Expand Down Expand Up @@ -1270,5 +1272,18 @@ public override object ConvertFrom(ITypeDescriptorContext context, System.Global
_ => throw new NotSupportedException(),
};
}

/// <summary>
/// Provides a debug view for the <see cref="ShellSection"/> class.
/// </summary>
/// <param name="section">The <see cref="ShellSection"/> instance to debug.</param>
private sealed class ShellSectionDebugView(ShellSection section)
{
public ShellSection CurrentItem => section.CurrentItem;

public IList<ShellContent> Items => section.Items;

public IReadOnlyList<Page> Stack => section.Stack;
}
}
}
18 changes: 18 additions & 0 deletions src/Controls/src/Core/Shell/ShellSectionCollection.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Diagnostics;

namespace Microsoft.Maui.Controls
{

[DebuggerDisplay("{GetDebuggerDisplay(), nq}")]
[DebuggerTypeProxy(typeof(ShellSectionCollectionDebugView))]
internal sealed class ShellSectionCollection : ShellElementCollection<ShellSection>
{
public ShellSectionCollection() : base() { }

string GetDebuggerDisplay() => $"Count = {Count}";

/// <summary>
/// Provides a debug view for the <see cref="ShellSectionCollection"/> class.
/// </summary>
/// <param name="collection">The <see cref="ShellSectionCollection"/> instance to debug.</param>
private sealed class ShellSectionCollectionDebugView(ShellSectionCollection collection)
{
public IList VisibleItems => collection.VisibleItems;

public IReadOnlyCollection<ShellSection> VisibleItemsReadOnly => collection.VisibleItemsReadOnly;
}
}
}
Loading