mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-04 18:26:39 +02:00
[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:
@@ -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 GeneralSettings generalSettingsConfig;
|
||||
private Windows.ApplicationModel.Resources.ResourceLoader resourceLoader = Helpers.ResourceLoaderInstance.ResourceLoader;
|
||||
@@ -73,14 +90,13 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
||||
generalSettingsConfig = settingsRepository.SettingsConfig;
|
||||
generalSettingsConfig.AddEnabledModuleChangeNotification(ModuleEnabledChangedOnSettingsPage);
|
||||
|
||||
// Initialize dashboard sort order from settings
|
||||
_dashboardSortOrder = generalSettingsConfig.DashboardSortOrder;
|
||||
|
||||
// set the callback functions value to handle outgoing IPC message.
|
||||
SendConfigMSG = ipcMSGCallBackFunc;
|
||||
|
||||
foreach (ModuleType moduleType in Enum.GetValues<ModuleType>())
|
||||
{
|
||||
AddDashboardListItem(moduleType);
|
||||
}
|
||||
|
||||
RefreshModuleList();
|
||||
GetShortcutModules();
|
||||
}
|
||||
|
||||
@@ -113,21 +129,39 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
||||
GlobalHotkeyConflictManager.Instance?.RequestAllConflicts();
|
||||
}
|
||||
|
||||
private void AddDashboardListItem(ModuleType moduleType)
|
||||
private void RefreshModuleList()
|
||||
{
|
||||
GpoRuleConfigured gpo = ModuleHelper.GetModuleGpoConfiguration(moduleType);
|
||||
var newItem = new DashboardListItem()
|
||||
AllModules.Clear();
|
||||
|
||||
var moduleItems = new List<DashboardListItem>();
|
||||
|
||||
foreach (ModuleType moduleType in Enum.GetValues<ModuleType>())
|
||||
{
|
||||
Tag = moduleType,
|
||||
Label = resourceLoader.GetString(ModuleHelper.GetModuleLabelResourceName(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),
|
||||
GpoRuleConfigured gpo = ModuleHelper.GetModuleGpoConfiguration(moduleType);
|
||||
var newItem = new DashboardListItem()
|
||||
{
|
||||
Tag = moduleType,
|
||||
Label = resourceLoader.GetString(ModuleHelper.GetModuleLabelResourceName(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);
|
||||
newItem.EnabledChangedCallback = EnabledChangedOnUI;
|
||||
foreach (var item in sortedItems)
|
||||
{
|
||||
AllModules.Add(item);
|
||||
}
|
||||
}
|
||||
|
||||
private void EnabledChangedOnUI(DashboardListItem dashboardListItem)
|
||||
@@ -149,6 +183,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
||||
{
|
||||
try
|
||||
{
|
||||
RefreshModuleList();
|
||||
GetShortcutModules();
|
||||
|
||||
OnPropertyChanged(nameof(ShortcutModules));
|
||||
|
||||
Reference in New Issue
Block a user