mirror of
https://github.com/microsoft/PowerToys
synced 2025-08-22 01:58:04 +00:00
CmdPal: Ensuring alias changes are propagated to related TopLevelViewModels (#40970)
Closes #39709 - Only updating aliases when the alias has changed - When an alias is used that is already in use, remove the alias from the previous TopLevelViewModel - Don't crash if the previous TopLevelViewModel doesn't exist (e.g. it was uninstalled)
This commit is contained in:
parent
da572c6c40
commit
56aa9acfb4
@ -97,14 +97,27 @@ public partial class AliasManager : ObservableObject
|
||||
}
|
||||
}
|
||||
|
||||
// Look for the old alias, and remove it
|
||||
List<CommandAlias> toRemove = [];
|
||||
foreach (var kv in _aliases)
|
||||
{
|
||||
// Look for the old aliases for the command, and remove it
|
||||
if (kv.Value.CommandId == commandId)
|
||||
{
|
||||
toRemove.Add(kv.Value);
|
||||
}
|
||||
|
||||
// Look for the alias belonging to another command, and remove it
|
||||
if (newAlias is not null && kv.Value.Alias == newAlias.Alias)
|
||||
{
|
||||
toRemove.Add(kv.Value);
|
||||
|
||||
// Remove alias from other TopLevelViewModels it may be assigned to
|
||||
var topLevelCommand = _topLevelCommandManager.LookupCommand(kv.Value.CommandId);
|
||||
if (topLevelCommand is not null)
|
||||
{
|
||||
topLevelCommand.AliasText = string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var alias in toRemove)
|
||||
|
@ -110,6 +110,8 @@ public sealed partial class TopLevelViewModel : ObservableObject, IListItem
|
||||
get => Alias?.Alias ?? string.Empty;
|
||||
set
|
||||
{
|
||||
var previousAlias = Alias?.Alias ?? string.Empty;
|
||||
|
||||
if (string.IsNullOrEmpty(value))
|
||||
{
|
||||
Alias = null;
|
||||
@ -126,11 +128,15 @@ public sealed partial class TopLevelViewModel : ObservableObject, IListItem
|
||||
}
|
||||
}
|
||||
|
||||
// Only call HandleChangeAlias if there was an actual change.
|
||||
if (previousAlias != Alias?.Alias)
|
||||
{
|
||||
HandleChangeAlias();
|
||||
OnPropertyChanged(nameof(AliasText));
|
||||
OnPropertyChanged(nameof(IsDirectAlias));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsDirectAlias
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user