Updating navigation tree for settings with groupings (#35559)

* adjusting stuff from here to there

* No longer crashing!  a win!

* Resources now

* spelling

* adjusting comments for xaml formatting

* added in new top level icons

* Fixing

* adjusting the core container logic based on feedback.  this is actually simplier and just leverages the builti in stuff as well

* getting frame_nav functional again, thanks @davidegiacometti

* making a one time hit for union

* Update src/settings-ui/Settings.UI/ViewModels/ShellViewModel.cs

Co-authored-by: Jeremy Sinclair <4016293+snickler@users.noreply.github.com>

* expanding code that @davidegiacometti suggestedion.  🔥

* ensure parent is always expanded when page is changed

* don't use static

---------

Co-authored-by: Ethan Fang <ethanfang@microsoft.com>
Co-authored-by: Jeremy Sinclair <4016293+snickler@users.noreply.github.com>
Co-authored-by: Davide Giacometti <davide.giacometti@outlook.it>
Co-authored-by: Jaime Bernardo <jaime@janeasystems.com>
This commit is contained in:
Clint Rutkas
2024-10-27 15:21:27 -07:00
committed by GitHub
parent 83d3c85f3e
commit 64845b7fd8
9 changed files with 199 additions and 139 deletions

View File

@@ -4,7 +4,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using ManagedCommon;
using Microsoft.PowerToys.Settings.UI.Helpers;
using Microsoft.PowerToys.Settings.UI.Services;
@@ -122,6 +122,8 @@ namespace Microsoft.PowerToys.Settings.UI.Views
public static bool IsUserAnAdmin { get; set; }
private Dictionary<Type, NavigationViewItem> _navViewParentLookup = new Dictionary<Type, NavigationViewItem>();
/// <summary>
/// Initializes a new instance of the <see cref="ShellPage"/> class.
/// Shell page constructor.
@@ -138,6 +140,21 @@ namespace Microsoft.PowerToys.Settings.UI.Views
// shellFrame.Navigate(typeof(GeneralPage));
IPCResponseHandleList.Add(ReceiveMessage);
SetTitleBar();
if (_navViewParentLookup.Count > 0)
{
_navViewParentLookup.Clear();
}
var topLevelItems = navigationView.MenuItems.OfType<NavigationViewItem>().ToArray();
foreach (var parent in topLevelItems)
{
foreach (var child in parent.MenuItems.OfType<NavigationViewItem>())
{
_navViewParentLookup.TryAdd(child.GetValue(NavHelper.NavigateToProperty) as Type, parent);
}
}
}
public static int SendDefaultIPCMessage(string msg)
@@ -277,7 +294,7 @@ namespace Microsoft.PowerToys.Settings.UI.Views
private bool navigationViewInitialStateProcessed; // avoid announcing initial state of the navigation pane.
private void NavigationView_PaneOpened(Microsoft.UI.Xaml.Controls.NavigationView sender, object args)
private void NavigationView_PaneOpened(NavigationView sender, object args)
{
if (!navigationViewInitialStateProcessed)
{
@@ -293,7 +310,7 @@ namespace Microsoft.PowerToys.Settings.UI.Views
if (AutomationPeer.ListenerExists(AutomationEvents.MenuOpened))
{
var loader = Helpers.ResourceLoaderInstance.ResourceLoader;
var loader = ResourceLoaderInstance.ResourceLoader;
peer.RaiseNotificationEvent(
AutomationNotificationKind.ActionCompleted,
AutomationNotificationProcessing.ImportantMostRecent,
@@ -302,7 +319,7 @@ namespace Microsoft.PowerToys.Settings.UI.Views
}
}
private void NavigationView_PaneClosed(Microsoft.UI.Xaml.Controls.NavigationView sender, object args)
private void NavigationView_PaneClosed(NavigationView sender, object args)
{
if (!navigationViewInitialStateProcessed)
{
@@ -318,7 +335,7 @@ namespace Microsoft.PowerToys.Settings.UI.Views
if (AutomationPeer.ListenerExists(AutomationEvents.MenuClosed))
{
var loader = Helpers.ResourceLoaderInstance.ResourceLoader;
var loader = ResourceLoaderInstance.ResourceLoader;
peer.RaiseNotificationEvent(
AutomationNotificationKind.ActionCompleted,
AutomationNotificationProcessing.ImportantMostRecent,
@@ -348,6 +365,12 @@ namespace Microsoft.PowerToys.Settings.UI.Views
if (selectedItem != null)
{
Type pageType = selectedItem.GetValue(NavHelper.NavigateToProperty) as Type;
if (_navViewParentLookup.TryGetValue(pageType, out var parentItem) && !parentItem.IsExpanded)
{
parentItem.IsExpanded = true;
}
NavigationService.Navigate(pageType);
}
}