[UX] Dashboard utilities sorting (#42065)

## Summary of the Pull Request

This PR adds a sorting button to the module list so it can be sorted
alphabetically (default) or by status.

Fixes: #41837

<img width="760" height="933" alt="image"
src="https://github.com/user-attachments/assets/69c831a9-ae9e-4849-b630-772d03e4a4b1"
/>


@yeelam-gordon When running the runner, I do see the settings value is
being updated. But when running the runner again the setting doesn't
seem to be saved? Is that because of a bug in my implementation, or am I
testing it wrong :)?

<img width="286" height="86" alt="image"
src="https://github.com/user-attachments/assets/3a90997f-c40c-4f50-8361-b1ae3aa02052"
/>



<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist

- [x] Closes: #xxx
- [ ] **Communication:** I've discussed this with core contributors
already. If the work hasn't been agreed, this work might be rejected
- [ ] **Tests:** Added/updated and all pass
- [ ] **Localization:** All end-user-facing strings can be localized
- [ ] **Dev docs:** Added/updated
- [ ] **New binaries:** Added on the required places
- [ ] [JSON for
signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json)
for new binaries
- [ ] [WXS for
installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs)
for new binaries and localization folder
- [ ] [YML for CI
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml)
for new test projects
- [ ] [YML for signed
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml)
- [ ] **Documentation updated:** If checked, please file a pull request
on [our docs
repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys)
and link it here: #xxx

<!-- Provide a more detailed description of the PR, other things fixed,
or any additional comments/features here -->
## Detailed Description of the Pull Request / Additional comments

<!-- Describe how you validated the behavior. Add automated tests
wherever possible, but list manual validation steps taken as well -->
## Validation Steps Performed

---------

Signed-off-by: Shawn Yuan (from Dev Box) <shuaiyuan@microsoft.com>
Co-authored-by: Shawn Yuan (from Dev Box) <shuaiyuan@microsoft.com>
This commit is contained in:
Niels Laute
2025-11-05 10:42:24 +01:00
committed by GitHub
parent 3176eb94a9
commit 1ad468641b
8 changed files with 182 additions and 19 deletions

View File

@@ -35,6 +35,31 @@ namespace
ensure_ignored_conflict_properties_shape(obj); ensure_ignored_conflict_properties_shape(obj);
return obj; return obj;
} }
DashboardSortOrder parse_dashboard_sort_order(const json::JsonObject& obj, DashboardSortOrder fallback)
{
if (json::has(obj, L"dashboard_sort_order", json::JsonValueType::Number))
{
const auto raw_value = static_cast<int>(obj.GetNamedNumber(L"dashboard_sort_order", static_cast<double>(static_cast<int>(fallback))));
return raw_value == static_cast<int>(DashboardSortOrder::ByStatus) ? DashboardSortOrder::ByStatus : DashboardSortOrder::Alphabetical;
}
if (json::has(obj, L"dashboard_sort_order", json::JsonValueType::String))
{
const auto raw = obj.GetNamedString(L"dashboard_sort_order");
if (raw == L"ByStatus")
{
return DashboardSortOrder::ByStatus;
}
if (raw == L"Alphabetical")
{
return DashboardSortOrder::Alphabetical;
}
}
return fallback;
}
} }
// TODO: would be nice to get rid of these globals, since they're basically cached json settings // TODO: would be nice to get rid of these globals, since they're basically cached json settings
@@ -46,6 +71,7 @@ static bool download_updates_automatically = true;
static bool show_whats_new_after_updates = true; static bool show_whats_new_after_updates = true;
static bool enable_experimentation = true; static bool enable_experimentation = true;
static bool enable_warnings_elevated_apps = true; static bool enable_warnings_elevated_apps = true;
static DashboardSortOrder dashboard_sort_order = DashboardSortOrder::Alphabetical;
static json::JsonObject ignored_conflict_properties = create_default_ignored_conflict_properties(); static json::JsonObject ignored_conflict_properties = create_default_ignored_conflict_properties();
json::JsonObject GeneralSettings::to_json() json::JsonObject GeneralSettings::to_json()
@@ -75,6 +101,7 @@ json::JsonObject GeneralSettings::to_json()
result.SetNamedValue(L"download_updates_automatically", json::value(downloadUpdatesAutomatically)); result.SetNamedValue(L"download_updates_automatically", json::value(downloadUpdatesAutomatically));
result.SetNamedValue(L"show_whats_new_after_updates", json::value(showWhatsNewAfterUpdates)); result.SetNamedValue(L"show_whats_new_after_updates", json::value(showWhatsNewAfterUpdates));
result.SetNamedValue(L"enable_experimentation", json::value(enableExperimentation)); result.SetNamedValue(L"enable_experimentation", json::value(enableExperimentation));
result.SetNamedValue(L"dashboard_sort_order", json::value(static_cast<int>(dashboardSortOrder)));
result.SetNamedValue(L"is_admin", json::value(isAdmin)); result.SetNamedValue(L"is_admin", json::value(isAdmin));
result.SetNamedValue(L"enable_warnings_elevated_apps", json::value(enableWarningsElevatedApps)); result.SetNamedValue(L"enable_warnings_elevated_apps", json::value(enableWarningsElevatedApps));
result.SetNamedValue(L"theme", json::value(theme)); result.SetNamedValue(L"theme", json::value(theme));
@@ -99,6 +126,7 @@ json::JsonObject load_general_settings()
show_whats_new_after_updates = loaded.GetNamedBoolean(L"show_whats_new_after_updates", true); show_whats_new_after_updates = loaded.GetNamedBoolean(L"show_whats_new_after_updates", true);
enable_experimentation = loaded.GetNamedBoolean(L"enable_experimentation", true); enable_experimentation = loaded.GetNamedBoolean(L"enable_experimentation", true);
enable_warnings_elevated_apps = loaded.GetNamedBoolean(L"enable_warnings_elevated_apps", true); enable_warnings_elevated_apps = loaded.GetNamedBoolean(L"enable_warnings_elevated_apps", true);
dashboard_sort_order = parse_dashboard_sort_order(loaded, dashboard_sort_order);
if (json::has(loaded, L"ignored_conflict_properties", json::JsonValueType::Object)) if (json::has(loaded, L"ignored_conflict_properties", json::JsonValueType::Object))
{ {
@@ -128,6 +156,7 @@ GeneralSettings get_general_settings()
.downloadUpdatesAutomatically = download_updates_automatically && is_user_admin, .downloadUpdatesAutomatically = download_updates_automatically && is_user_admin,
.showWhatsNewAfterUpdates = show_whats_new_after_updates, .showWhatsNewAfterUpdates = show_whats_new_after_updates,
.enableExperimentation = enable_experimentation, .enableExperimentation = enable_experimentation,
.dashboardSortOrder = dashboard_sort_order,
.theme = settings_theme, .theme = settings_theme,
.systemTheme = WindowsColors::is_dark_mode() ? L"dark" : L"light", .systemTheme = WindowsColors::is_dark_mode() ? L"dark" : L"light",
.powerToysVersion = get_product_version(), .powerToysVersion = get_product_version(),
@@ -159,6 +188,7 @@ void apply_general_settings(const json::JsonObject& general_configs, bool save)
show_whats_new_after_updates = general_configs.GetNamedBoolean(L"show_whats_new_after_updates", true); show_whats_new_after_updates = general_configs.GetNamedBoolean(L"show_whats_new_after_updates", true);
enable_experimentation = general_configs.GetNamedBoolean(L"enable_experimentation", true); enable_experimentation = general_configs.GetNamedBoolean(L"enable_experimentation", true);
dashboard_sort_order = parse_dashboard_sort_order(general_configs, dashboard_sort_order);
// apply_general_settings is called by the runner's WinMain, so we can just force the run at startup gpo rule here. // apply_general_settings is called by the runner's WinMain, so we can just force the run at startup gpo rule here.
auto gpo_run_as_startup = powertoys_gpo::getConfiguredRunAtStartupValue(); auto gpo_run_as_startup = powertoys_gpo::getConfiguredRunAtStartupValue();

View File

@@ -2,6 +2,12 @@
#include <common/utils/json.h> #include <common/utils/json.h>
enum class DashboardSortOrder
{
Alphabetical = 0,
ByStatus = 1,
};
struct GeneralSettings struct GeneralSettings
{ {
bool isStartupEnabled; bool isStartupEnabled;
@@ -16,6 +22,7 @@ struct GeneralSettings
bool downloadUpdatesAutomatically; bool downloadUpdatesAutomatically;
bool showWhatsNewAfterUpdates; bool showWhatsNewAfterUpdates;
bool enableExperimentation; bool enableExperimentation;
DashboardSortOrder dashboardSortOrder;
std::wstring theme; std::wstring theme;
std::wstring systemTheme; std::wstring systemTheme;
std::wstring powerToysVersion; std::wstring powerToysVersion;

View File

@@ -13,6 +13,12 @@ using Settings.UI.Library.Attributes;
namespace Microsoft.PowerToys.Settings.UI.Library namespace Microsoft.PowerToys.Settings.UI.Library
{ {
public enum DashboardSortOrder
{
Alphabetical,
ByStatus,
}
public class GeneralSettings : ISettingsConfig public class GeneralSettings : ISettingsConfig
{ {
// Gets or sets a value indicating whether run powertoys on start-up. // Gets or sets a value indicating whether run powertoys on start-up.
@@ -76,6 +82,9 @@ namespace Microsoft.PowerToys.Settings.UI.Library
[JsonPropertyName("enable_experimentation")] [JsonPropertyName("enable_experimentation")]
public bool EnableExperimentation { get; set; } public bool EnableExperimentation { get; set; }
[JsonPropertyName("dashboard_sort_order")]
public DashboardSortOrder DashboardSortOrder { get; set; }
[JsonPropertyName("ignored_conflict_properties")] [JsonPropertyName("ignored_conflict_properties")]
public ShortcutConflictProperties IgnoredConflictProperties { get; set; } public ShortcutConflictProperties IgnoredConflictProperties { get; set; }
@@ -89,6 +98,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library
ShowNewUpdatesToastNotification = true; ShowNewUpdatesToastNotification = true;
AutoDownloadUpdates = false; AutoDownloadUpdates = false;
EnableExperimentation = true; EnableExperimentation = true;
DashboardSortOrder = DashboardSortOrder.Alphabetical;
Theme = "system"; Theme = "system";
SystemTheme = "light"; SystemTheme = "light";
try try

View File

@@ -0,0 +1,31 @@
// 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;
using Microsoft.UI.Xaml.Data;
namespace Microsoft.PowerToys.Settings.UI.Converters
{
public partial class EnumToBooleanConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
if (value == null || parameter == null)
{
return false;
}
// Get the enum value as string
var enumString = value.ToString();
var parameterString = parameter.ToString();
return enumString.Equals(parameterString, StringComparison.OrdinalIgnoreCase);
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
}
}

View File

@@ -19,6 +19,7 @@
x:Key="ModuleItemTemplateSelector" x:Key="ModuleItemTemplateSelector"
ActivationTemplate="{StaticResource ModuleItemActivationTemplate}" ActivationTemplate="{StaticResource ModuleItemActivationTemplate}"
ShortcutTemplate="{StaticResource ModuleItemShortcutTemplate}" /> ShortcutTemplate="{StaticResource ModuleItemShortcutTemplate}" />
<converters:EnumToBooleanConverter x:Key="EnumToBooleanConverter" />
<DataTemplate x:Key="ModuleItemShortcutTemplate" x:DataType="viewmodels:DashboardModuleShortcutItem"> <DataTemplate x:Key="ModuleItemShortcutTemplate" x:DataType="viewmodels:DashboardModuleShortcutItem">
<Grid MinHeight="36" ColumnSpacing="12"> <Grid MinHeight="36" ColumnSpacing="12">
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
@@ -276,9 +277,36 @@
Padding="0" Padding="0"
VerticalAlignment="Top" VerticalAlignment="Top"
DividerVisibility="Collapsed"> DividerVisibility="Collapsed">
<controls:Card.TitleContent>
<Button
x:Uid="Dashboard_SortBy"
Margin="0,0,4,0"
VerticalAlignment="Center"
Style="{StaticResource SubtleButtonStyle}">
<ToolTipService.ToolTip>
<TextBlock x:Uid="Dashboard_SortBy_ToolTip" />
</ToolTipService.ToolTip>
<Button.Content>
<FontIcon FontSize="16" Glyph="&#xE8CB;" />
</Button.Content>
<Button.Flyout>
<MenuFlyout>
<ToggleMenuFlyoutItem
x:Uid="Dashboard_SortAlphabetical"
Click="SortAlphabetical_Click"
IsChecked="{x:Bind ViewModel.DashboardSortOrder, Mode=OneWay, Converter={StaticResource EnumToBooleanConverter}, ConverterParameter=Alphabetical}" />
<ToggleMenuFlyoutItem
x:Uid="Dashboard_SortByStatus"
Click="SortByStatus_Click"
IsChecked="{x:Bind ViewModel.DashboardSortOrder, Mode=OneWay, Converter={StaticResource EnumToBooleanConverter}, ConverterParameter=ByStatus}" />
</MenuFlyout>
</Button.Flyout>
</Button>
</controls:Card.TitleContent>
<ItemsRepeater <ItemsRepeater
x:Name="DashboardView" x:Name="DashboardView"
Grid.Row="2" Grid.Row="1"
ItemsSource="{x:Bind ViewModel.AllModules, Mode=OneWay}"> ItemsSource="{x:Bind ViewModel.AllModules, Mode=OneWay}">
<ItemsRepeater.Layout> <ItemsRepeater.Layout>
<StackLayout Orientation="Vertical" Spacing="0" /> <StackLayout Orientation="Vertical" Spacing="0" />

View File

@@ -66,5 +66,15 @@ namespace Microsoft.PowerToys.Settings.UI.Views
App.GetOobeWindow().Activate(); App.GetOobeWindow().Activate();
} }
private void SortAlphabetical_Click(object sender, RoutedEventArgs e)
{
ViewModel.DashboardSortOrder = DashboardSortOrder.Alphabetical;
}
private void SortByStatus_Click(object sender, RoutedEventArgs e)
{
ViewModel.DashboardSortOrder = DashboardSortOrder.ByStatus;
}
} }
} }

View File

@@ -2999,7 +2999,7 @@ Right-click to remove the key combination, thereby deactivating the shortcut.</v
<value>Crosshairs fixed length (px)</value> <value>Crosshairs fixed length (px)</value>
<comment>px = pixels</comment> <comment>px = pixels</comment>
</data> </data>
<data name="MouseUtils_MousePointerCrosshairs_CrosshairsOrientation.Header" xml:space="preserve"> <data name="MouseUtils_MousePointerCrosshairs_CrosshairsOrientation.Header" xml:space="preserve">
<value>Crosshairs orientation</value> <value>Crosshairs orientation</value>
</data> </data>
<data name="MouseUtils_MousePointerCrosshairs_CrosshairsOrientation_Both.Content" xml:space="preserve"> <data name="MouseUtils_MousePointerCrosshairs_CrosshairsOrientation_Both.Content" xml:space="preserve">
@@ -4462,6 +4462,18 @@ Activate by holding the key for the character you want to add an accent to, then
<data name="Shell_Dashboard.Content" xml:space="preserve"> <data name="Shell_Dashboard.Content" xml:space="preserve">
<value>Home</value> <value>Home</value>
</data> </data>
<data name="Dashboard_SortBy_ToolTip.Text" xml:space="preserve">
<value>Sort utilities</value>
</data>
<data name="Dashboard_SortAlphabetical.Text" xml:space="preserve">
<value>Alphabetically</value>
</data>
<data name="Dashboard_SortByStatus.Text" xml:space="preserve">
<value>By status</value>
</data>
<data name="Dashboard_SortBy.[using:Microsoft.UI.Xaml.Automation]AutomationProperties.Name" xml:space="preserve">
<value>Sort utilities</value>
</data>
<data name="Peek_Preview_GroupSettings.Header" xml:space="preserve"> <data name="Peek_Preview_GroupSettings.Header" xml:space="preserve">
<value>Preview</value> <value>Preview</value>
</data> </data>
@@ -4770,7 +4782,7 @@ Copy a zoomed screen with Ctrl+C or save it by typing Ctrl+S. Crop the copy or s
</data> </data>
<data name="ZoomIt_Toggle_SmoothZoomedImage.Header" xml:space="preserve"> <data name="ZoomIt_Toggle_SmoothZoomedImage.Header" xml:space="preserve">
<value>Smooth zoomed image</value> <value>Smooth zoomed image</value>
</data> </data>
<data name="ZoomIt_Slider_InitialMagnification.Header" xml:space="preserve"> <data name="ZoomIt_Slider_InitialMagnification.Header" xml:space="preserve">
<value>Specify the initial level of magnification when zooming in</value> <value>Specify the initial level of magnification when zooming in</value>
</data> </data>

View File

@@ -62,6 +62,23 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
} }
} }
private DashboardSortOrder _dashboardSortOrder = DashboardSortOrder.Alphabetical;
public DashboardSortOrder DashboardSortOrder
{
get => generalSettingsConfig.DashboardSortOrder;
set
{
if (Set(ref _dashboardSortOrder, value))
{
generalSettingsConfig.DashboardSortOrder = value;
OutGoingGeneralSettings outgoing = new OutGoingGeneralSettings(generalSettingsConfig);
SendConfigMSG(outgoing.ToString());
RefreshModuleList();
}
}
}
private ISettingsRepository<GeneralSettings> _settingsRepository; private ISettingsRepository<GeneralSettings> _settingsRepository;
private GeneralSettings generalSettingsConfig; private GeneralSettings generalSettingsConfig;
private Windows.ApplicationModel.Resources.ResourceLoader resourceLoader = Helpers.ResourceLoaderInstance.ResourceLoader; private Windows.ApplicationModel.Resources.ResourceLoader resourceLoader = Helpers.ResourceLoaderInstance.ResourceLoader;
@@ -73,14 +90,13 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
generalSettingsConfig = settingsRepository.SettingsConfig; generalSettingsConfig = settingsRepository.SettingsConfig;
generalSettingsConfig.AddEnabledModuleChangeNotification(ModuleEnabledChangedOnSettingsPage); generalSettingsConfig.AddEnabledModuleChangeNotification(ModuleEnabledChangedOnSettingsPage);
// Initialize dashboard sort order from settings
_dashboardSortOrder = generalSettingsConfig.DashboardSortOrder;
// set the callback functions value to handle outgoing IPC message. // set the callback functions value to handle outgoing IPC message.
SendConfigMSG = ipcMSGCallBackFunc; SendConfigMSG = ipcMSGCallBackFunc;
foreach (ModuleType moduleType in Enum.GetValues<ModuleType>()) RefreshModuleList();
{
AddDashboardListItem(moduleType);
}
GetShortcutModules(); GetShortcutModules();
} }
@@ -113,21 +129,39 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
GlobalHotkeyConflictManager.Instance?.RequestAllConflicts(); GlobalHotkeyConflictManager.Instance?.RequestAllConflicts();
} }
private void AddDashboardListItem(ModuleType moduleType) private void RefreshModuleList()
{ {
GpoRuleConfigured gpo = ModuleHelper.GetModuleGpoConfiguration(moduleType); AllModules.Clear();
var newItem = new DashboardListItem()
var moduleItems = new List<DashboardListItem>();
foreach (ModuleType moduleType in Enum.GetValues<ModuleType>())
{ {
Tag = moduleType, GpoRuleConfigured gpo = ModuleHelper.GetModuleGpoConfiguration(moduleType);
Label = resourceLoader.GetString(ModuleHelper.GetModuleLabelResourceName(moduleType)), var newItem = new DashboardListItem()
IsEnabled = gpo == GpoRuleConfigured.Enabled || (gpo != GpoRuleConfigured.Disabled && ModuleHelper.GetIsModuleEnabled(generalSettingsConfig, moduleType)), {
IsLocked = gpo == GpoRuleConfigured.Enabled || gpo == GpoRuleConfigured.Disabled, Tag = moduleType,
Icon = ModuleHelper.GetModuleTypeFluentIconName(moduleType), Label = resourceLoader.GetString(ModuleHelper.GetModuleLabelResourceName(moduleType)),
DashboardModuleItems = GetModuleItems(moduleType), IsEnabled = gpo == GpoRuleConfigured.Enabled || (gpo != GpoRuleConfigured.Disabled && ModuleHelper.GetIsModuleEnabled(generalSettingsConfig, moduleType)),
IsLocked = gpo == GpoRuleConfigured.Enabled || gpo == GpoRuleConfigured.Disabled,
Icon = ModuleHelper.GetModuleTypeFluentIconName(moduleType),
DashboardModuleItems = GetModuleItems(moduleType),
};
newItem.EnabledChangedCallback = EnabledChangedOnUI;
moduleItems.Add(newItem);
}
// Sort based on current sort order
var sortedItems = DashboardSortOrder switch
{
DashboardSortOrder.ByStatus => moduleItems.OrderByDescending(x => x.IsEnabled).ThenBy(x => x.Label),
_ => moduleItems.OrderBy(x => x.Label), // Default alphabetical
}; };
AllModules.Add(newItem); foreach (var item in sortedItems)
newItem.EnabledChangedCallback = EnabledChangedOnUI; {
AllModules.Add(item);
}
} }
private void EnabledChangedOnUI(DashboardListItem dashboardListItem) private void EnabledChangedOnUI(DashboardListItem dashboardListItem)
@@ -149,6 +183,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
{ {
try try
{ {
RefreshModuleList();
GetShortcutModules(); GetShortcutModules();
OnPropertyChanged(nameof(ShortcutModules)); OnPropertyChanged(nameof(ShortcutModules));