mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-08 12:18:50 +02:00
[cmdpal] Setting a new alias should remove the old one (#38193)
* [cmdpal] Fix alias update * Fix the command palette extension alias update issue * clean code --------- Co-authored-by: vanzue <vanzue@outlook.com>
This commit is contained in:
@@ -152,7 +152,7 @@ public sealed partial class TopLevelViewModel : ObservableObject, IListItem
|
|||||||
{
|
{
|
||||||
GenerateId();
|
GenerateId();
|
||||||
|
|
||||||
UpdateAlias();
|
FetchAliasFromAliasManager();
|
||||||
UpdateHotkey();
|
UpdateHotkey();
|
||||||
UpdateTags();
|
UpdateTags();
|
||||||
}
|
}
|
||||||
@@ -163,24 +163,31 @@ public sealed partial class TopLevelViewModel : ObservableObject, IListItem
|
|||||||
|
|
||||||
private void HandleChangeAlias()
|
private void HandleChangeAlias()
|
||||||
{
|
{
|
||||||
SetAlias(Alias);
|
SetAlias();
|
||||||
Save();
|
Save();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetAlias(CommandAlias? newAlias)
|
public void SetAlias()
|
||||||
{
|
{
|
||||||
_serviceProvider.GetService<AliasManager>()!.UpdateAlias(Id, newAlias);
|
var commandAlias = Alias is null
|
||||||
UpdateAlias();
|
? null
|
||||||
|
: new CommandAlias(Alias.Alias, Alias.CommandId, Alias.IsDirect);
|
||||||
|
|
||||||
|
_serviceProvider.GetService<AliasManager>()!.UpdateAlias(Id, commandAlias);
|
||||||
UpdateTags();
|
UpdateTags();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateAlias()
|
private void FetchAliasFromAliasManager()
|
||||||
{
|
{
|
||||||
// Add tags for the alias, if we have one.
|
var am = _serviceProvider.GetService<AliasManager>();
|
||||||
var aliases = _serviceProvider.GetService<AliasManager>();
|
if (am != null)
|
||||||
if (aliases != null)
|
|
||||||
{
|
{
|
||||||
Alias = aliases.AliasFromId(Id);
|
var commandAlias = am.AliasFromId(Id);
|
||||||
|
if (commandAlias is not null)
|
||||||
|
{
|
||||||
|
// Decouple from the alias manager alias object
|
||||||
|
Alias = new CommandAlias(commandAlias.Alias, commandAlias.CommandId, commandAlias.IsDirect);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user