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

Updating navigation tree for settings with groupings #35559

Merged
merged 16 commits into from
Oct 27, 2024
Merged
Show file tree
Hide file tree
Changes from 14 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
264 changes: 144 additions & 120 deletions src/settings-ui/Settings.UI/SettingsXAML/Views/ShellPage.xaml

Large diffs are not rendered by default.

33 changes: 28 additions & 5 deletions src/settings-ui/Settings.UI/SettingsXAML/Views/ShellPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -122,6 +122,8 @@ public sealed partial class ShellPage : UserControl

public static bool IsUserAnAdmin { get; set; }

private static Dictionary<Type, NavigationViewItem> _navViewParentLookup;

/// <summary>
/// Initializes a new instance of the <see cref="ShellPage"/> class.
/// Shell page constructor.
Expand All @@ -138,6 +140,21 @@ public ShellPage()
// shellFrame.Navigate(typeof(GeneralPage));
IPCResponseHandleList.Add(ReceiveMessage);
SetTitleBar();

if (_navViewParentLookup == null)
{
_navViewParentLookup = new Dictionary<Type, NavigationViewItem>();

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)
Expand Down Expand Up @@ -277,7 +294,7 @@ private void OobeButton_Click(object sender, RoutedEventArgs e)

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)
{
Expand All @@ -293,7 +310,7 @@ private void NavigationView_PaneOpened(Microsoft.UI.Xaml.Controls.NavigationView

if (AutomationPeer.ListenerExists(AutomationEvents.MenuOpened))
{
var loader = Helpers.ResourceLoaderInstance.ResourceLoader;
var loader = ResourceLoaderInstance.ResourceLoader;
peer.RaiseNotificationEvent(
AutomationNotificationKind.ActionCompleted,
AutomationNotificationProcessing.ImportantMostRecent,
Expand All @@ -302,7 +319,7 @@ private void NavigationView_PaneOpened(Microsoft.UI.Xaml.Controls.NavigationView
}
}

private void NavigationView_PaneClosed(Microsoft.UI.Xaml.Controls.NavigationView sender, object args)
private void NavigationView_PaneClosed(NavigationView sender, object args)
{
if (!navigationViewInitialStateProcessed)
{
Expand All @@ -318,7 +335,7 @@ private void NavigationView_PaneClosed(Microsoft.UI.Xaml.Controls.NavigationView

if (AutomationPeer.ListenerExists(AutomationEvents.MenuClosed))
{
var loader = Helpers.ResourceLoaderInstance.ResourceLoader;
var loader = ResourceLoaderInstance.ResourceLoader;
peer.RaiseNotificationEvent(
AutomationNotificationKind.ActionCompleted,
AutomationNotificationProcessing.ImportantMostRecent,
Expand Down Expand Up @@ -348,6 +365,12 @@ private void NavigationView_SelectionChanged(NavigationView sender, NavigationVi
if (selectedItem != null)
{
Type pageType = selectedItem.GetValue(NavHelper.NavigateToProperty) as Type;

if (_navViewParentLookup.TryGetValue(pageType, out var parentItem))
{
parentItem.IsExpanded = true;
}

NavigationService.Navigate(pageType);
}
}
Expand Down
22 changes: 17 additions & 5 deletions src/settings-ui/Settings.UI/Strings/en-us/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,7 @@
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root"
xmlns=""
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was VS automatically adjusting this, fyi

<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
Expand Down Expand Up @@ -4563,4 +4560,19 @@ Activate by holding the key for the character you want to add an accent to, then
<data name="GeneralPage_ViewDiagnosticDataViewerInfoButton.Content" xml:space="preserve">
<value>Restart</value>
</data>
</root>
<data name="Shell_TopLevelAdvanced.Content" xml:space="preserve">
<value>Advanced</value>
</data>
<data name="Shell_TopLevelFileManagement.Content" xml:space="preserve">
<value>File Management</value>
</data>
<data name="Shell_TopLevelInputOutput.Content" xml:space="preserve">
<value>Input / Output</value>
</data>
<data name="Shell_TopLevelWindowsAndLayouts.Content" xml:space="preserve">
<value>Windowing &amp; Layouts</value>
</data>
<data name="Shell_TopLevelSystemTools.Content" xml:space="preserve">
<value>System Tools</value>
</data>
</root>
21 changes: 13 additions & 8 deletions src/settings-ui/Settings.UI/ViewModels/ShellViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class ShellViewModel : Observable
private NavigationViewItem selected;
private ICommand loadedCommand;
private ICommand itemInvokedCommand;
private static NavigationViewItem[] _fullListOfNavViewItems;

public bool IsBackEnabled
{
Expand Down Expand Up @@ -76,6 +77,11 @@ public void Initialize(Frame frame, NavigationView navigationView, IList<Keyboar
NavigationService.NavigationFailed += Frame_NavigationFailed;
NavigationService.Navigated += Frame_Navigated;
this.navigationView.BackRequested += OnBackRequested;
if (_fullListOfNavViewItems == null)
{
var topLevelItems = navigationView.MenuItems.OfType<NavigationViewItem>();
_fullListOfNavViewItems = topLevelItems.Union(topLevelItems.SelectMany(menuItem => menuItem.MenuItems.OfType<NavigationViewItem>())).ToArray();
}
}

private static KeyboardAccelerator BuildKeyboardAccelerator(VirtualKey key, VirtualKeyModifiers? modifiers = null)
Expand Down Expand Up @@ -107,11 +113,12 @@ private async void OnLoaded()

private void OnItemInvoked(NavigationViewItemInvokedEventArgs args)
{
var item = navigationView.MenuItems
.OfType<NavigationViewItem>()
.First(menuItem => (string)menuItem.Content == (string)args.InvokedItem);
var pageType = item.GetValue(NavHelper.NavigateToProperty) as Type;
NavigationService.Navigate(pageType);
var pageType = args.InvokedItemContainer.GetValue(NavHelper.NavigateToProperty) as Type;

if (pageType != null)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

without the L1 having a nav target, it would crash

{
NavigationService.Navigate(pageType);
}
}

private void OnBackRequested(NavigationView sender, NavigationViewBackRequestedEventArgs args)
Expand All @@ -127,9 +134,7 @@ private void Frame_NavigationFailed(object sender, NavigationFailedEventArgs e)
private void Frame_Navigated(object sender, NavigationEventArgs e)
{
IsBackEnabled = NavigationService.CanGoBack;
Selected = navigationView.MenuItems
.OfType<NavigationViewItem>()
.FirstOrDefault(menuItem => IsMenuItemForPageType(menuItem, e.SourcePageType));
Selected = _fullListOfNavViewItems.FirstOrDefault(menuItem => IsMenuItemForPageType(menuItem, e.SourcePageType));
}

private static bool IsMenuItemForPageType(NavigationViewItem menuItem, Type sourcePageType)
Expand Down
Loading