Skip to content

Commit

Permalink
Updating navigation tree for settings with groupings (microsoft#35559)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

* expanding code that @davidegiacometti suggestedion.  🔥

* ensure parent is always expanded when page is changed

* don't use static

---------

Co-authored-by: Ethan Fang <[email protected]>
Co-authored-by: Jeremy Sinclair <[email protected]>
Co-authored-by: Davide Giacometti <[email protected]>
Co-authored-by: Jaime Bernardo <[email protected]>
  • Loading branch information
5 people authored Oct 27, 2024
1 parent 83d3c85 commit 64845b7
Show file tree
Hide file tree
Showing 9 changed files with 199 additions and 139 deletions.
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 Dictionary<Type, NavigationViewItem> _navViewParentLookup = new Dictionary<Type, NavigationViewItem>();

/// <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.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)
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)
{
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">
<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>
19 changes: 10 additions & 9 deletions src/settings-ui/Settings.UI/ViewModels/ShellViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Abstractions;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Input;
Expand All @@ -32,6 +31,7 @@ public class ShellViewModel : Observable
private NavigationViewItem selected;
private ICommand loadedCommand;
private ICommand itemInvokedCommand;
private NavigationViewItem[] _fullListOfNavViewItems;

public bool IsBackEnabled
{
Expand Down Expand Up @@ -76,6 +76,8 @@ public void Initialize(Frame frame, NavigationView navigationView, IList<Keyboar
NavigationService.NavigationFailed += Frame_NavigationFailed;
NavigationService.Navigated += Frame_Navigated;
this.navigationView.BackRequested += OnBackRequested;
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 +109,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)
{
NavigationService.Navigate(pageType);
}
}

private void OnBackRequested(NavigationView sender, NavigationViewBackRequestedEventArgs args)
Expand All @@ -127,9 +130,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

0 comments on commit 64845b7

Please sign in to comment.