mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 10:46:33 +02:00
CmdPal: Add option to choose default order for Terminal profiles (#41945)
## Summary of the Pull Request This PR adds a new drop-down to the Windows Terminal extension settings page that allows the user to choose the default sort order of profiles. The available options are: - Default (currently alphabetical, but may change in the future) - Alphabetical - Most recently used It also extends the app data to store AppSettings, including a list of up to 64 recently used profiles, stored as pairs of profile name and terminal app ID. Pictures? Pictures! <img width="1821" height="1097" alt="image" src="https://github.com/user-attachments/assets/c751dcbf-e638-4207-a3e4-6dd283c5239c" /> <img width="1694" height="521" alt="image" src="https://github.com/user-attachments/assets/914c0498-98fa-4ed7-997d-f988253c923c" /> <!-- Please review the items on the PR checklist before submitting--> ## PR Checklist - [x] Closes: #41430 - [ ] **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
This commit is contained in:
@@ -51,9 +51,16 @@ internal sealed partial class ProfilesListPage : ListPage, INotifyItemsChanged
|
||||
Icon = Icons.TerminalIcon;
|
||||
Name = Resources.profiles_list_page_name;
|
||||
_terminalSettings = terminalSettings;
|
||||
_terminalSettings.Settings.SettingsChanged += Settings_SettingsChanged;
|
||||
_appSettingsManager = appSettingsManager;
|
||||
}
|
||||
|
||||
private void Settings_SettingsChanged(object sender, Settings args)
|
||||
{
|
||||
EnsureInitialized();
|
||||
RaiseItemsChanged();
|
||||
}
|
||||
|
||||
private List<ListItem> Query()
|
||||
{
|
||||
EnsureInitialized();
|
||||
@@ -62,7 +69,27 @@ internal sealed partial class ProfilesListPage : ListPage, INotifyItemsChanged
|
||||
openNewTab = _terminalSettings.OpenNewTab;
|
||||
openQuake = _terminalSettings.OpenQuake;
|
||||
|
||||
var profiles = _terminalQuery.GetProfiles();
|
||||
var profiles = _terminalQuery.GetProfiles()!;
|
||||
|
||||
switch (_terminalSettings.ProfileSortOrder)
|
||||
{
|
||||
case ProfileSortOrder.MostRecentlyUsed:
|
||||
var mru = _appSettingsManager.Current.RecentlyUsedProfiles ?? [];
|
||||
profiles = profiles.OrderBy(p =>
|
||||
{
|
||||
var key = new TerminalProfileKey(p.Terminal?.AppUserModelId ?? string.Empty, p.Name ?? string.Empty);
|
||||
var index = mru.IndexOf(key);
|
||||
return index == -1 ? int.MaxValue : index;
|
||||
})
|
||||
.ThenBy(static p => p.Name, StringComparer.CurrentCultureIgnoreCase)
|
||||
.ToList();
|
||||
break;
|
||||
case ProfileSortOrder.Default:
|
||||
case ProfileSortOrder.Alphabetical:
|
||||
default:
|
||||
profiles = profiles.OrderBy(static p => p.Name, StringComparer.CurrentCultureIgnoreCase);
|
||||
break;
|
||||
}
|
||||
|
||||
if (terminalFilters?.IsAllSelected == false)
|
||||
{
|
||||
@@ -78,12 +105,12 @@ internal sealed partial class ProfilesListPage : ListPage, INotifyItemsChanged
|
||||
continue;
|
||||
}
|
||||
|
||||
result.Add(new ListItem(new LaunchProfileCommand(profile.Terminal.AppUserModelId, profile.Name, profile.Terminal.LogoPath, openNewTab, openQuake))
|
||||
result.Add(new ListItem(new LaunchProfileCommand(profile.Terminal.AppUserModelId, profile.Name, profile.Terminal.LogoPath, openNewTab, openQuake, _appSettingsManager))
|
||||
{
|
||||
Title = profile.Name,
|
||||
Subtitle = profile.Terminal.DisplayName,
|
||||
MoreCommands = [
|
||||
new CommandContextItem(new LaunchProfileAsAdminCommand(profile.Terminal.AppUserModelId, profile.Name, openNewTab, openQuake)),
|
||||
new CommandContextItem(new LaunchProfileAsAdminCommand(profile.Terminal.AppUserModelId, profile.Name, openNewTab, openQuake, _appSettingsManager)),
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user