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

[Settings] Sort Navigation-Pane items alphabetically #31183

Closed
wants to merge 2 commits into from
Closed
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
39 changes: 39 additions & 0 deletions src/settings-ui/Settings.UI/Helpers/ShellPageHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Linq;
using Microsoft.UI.Xaml.Controls;

namespace Microsoft.PowerToys.Settings.UI.Helpers
{
public static class ShellPageHelper
{
/// <summary>
/// Sort the Navigation-Pane items alphabetically based on their display names
/// </summary>
public static void SortNavigationPaneItems(NavigationView navigationView)
{
// We want to sort the items after the separator
int separatorIndex = navigationView.MenuItems.IndexOf(
navigationView.MenuItems.OfType<NavigationViewItemSeparator>().FirstOrDefault());

var itemsToSort = navigationView.MenuItems
.OfType<NavigationViewItem>()
.Skip(separatorIndex)
.OrderBy(item => item.Content.ToString())
.ToList();

// Arrange the items in the sorted order
for (int i = navigationView.MenuItems.Count - 1; i > separatorIndex; i--)
{
navigationView.MenuItems.RemoveAt(i);
}

foreach (var sortedItem in itemsToSort)
{
navigationView.MenuItems.Add(sortedItem);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
x:Uid="Shell_General"
Icon="{ui:BitmapIcon Source=/Assets/Settings/FluentIcons/FluentIconsPowerToys.png}"
Tag="Overview" />
<NavigationViewItemSeparator />
<NavigationViewItem
x:Uid="Shell_AlwaysOnTop"
Icon="{ui:BitmapIcon Source=/Assets/Settings/FluentIcons/FluentIconsAlwaysOnTop.png}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Globalization;
using AllExperiments;
using global::PowerToys.GPOWrapper;
using Microsoft.PowerToys.Settings.UI.Helpers;
using Microsoft.PowerToys.Settings.UI.Library;
using Microsoft.PowerToys.Settings.UI.OOBE.Enums;
using Microsoft.PowerToys.Settings.UI.OOBE.ViewModel;
Expand Down Expand Up @@ -63,6 +64,7 @@ public OobeShellPage()
DataContext = ViewModel;
OobeShellHandler = this;
Modules = new ObservableCollection<OobePowerToysModule>();
ShellPageHelper.SortNavigationPaneItems(navigationView);

Modules.Insert((int)PowerToysModules.Overview, new OobePowerToysModule()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +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 @@ -132,6 +133,7 @@ public ShellPage()
DataContext = ViewModel;
ShellHandler = this;
ViewModel.Initialize(shellFrame, navigationView, KeyboardAccelerators);
ShellPageHelper.SortNavigationPaneItems(navigationView);

// NL moved navigation to general page to the moment when the window is first activated (to not make flyout window disappear)
// shellFrame.Navigate(typeof(GeneralPage));
Expand Down
Loading