-
Notifications
You must be signed in to change notification settings - Fork 7.8k
[cmdpal] Setting a new alias should remove the old one #38193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -152,7 +152,7 @@ private void Item_PropertyChanged(object? sender, System.ComponentModel.Property | |
| { | ||
| GenerateId(); | ||
|
|
||
| UpdateAlias(); | ||
| FetchAliasFromAliasManager(); | ||
| UpdateHotkey(); | ||
| UpdateTags(); | ||
| } | ||
|
|
@@ -163,24 +163,31 @@ private void Item_PropertyChanged(object? sender, System.ComponentModel.Property | |
|
|
||
| private void HandleChangeAlias() | ||
| { | ||
| SetAlias(Alias); | ||
| SetAlias(); | ||
| Save(); | ||
| } | ||
|
|
||
| public void SetAlias(CommandAlias? newAlias) | ||
| public void SetAlias() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @vanzue , it doesn't make sense this is a "Public" method, and become like using as "private method" (e.g. assuming calling from HandleChangeAlias() (which is a private method) |
||
| { | ||
| _serviceProvider.GetService<AliasManager>()!.UpdateAlias(Id, newAlias); | ||
| UpdateAlias(); | ||
| var commandAlias = Alias is null | ||
| ? null | ||
| : new CommandAlias(Alias.Alias, Alias.CommandId, Alias.IsDirect); | ||
|
|
||
| _serviceProvider.GetService<AliasManager>()!.UpdateAlias(Id, commandAlias); | ||
| UpdateTags(); | ||
| } | ||
|
|
||
| private void UpdateAlias() | ||
| private void FetchAliasFromAliasManager() | ||
| { | ||
| // Add tags for the alias, if we have one. | ||
| var aliases = _serviceProvider.GetService<AliasManager>(); | ||
| if (aliases != null) | ||
| var am = _serviceProvider.GetService<AliasManager>(); | ||
| if (am != null) | ||
| { | ||
| Alias = aliases.AliasFromId(Id); | ||
| var commandAlias = am.AliasFromId(Id); | ||
| if (commandAlias is not null) | ||
| { | ||
| // Decouple from the alias manager alias object | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we mean the alias object from serviceProvider cannot cache here, we need to make a copy of alias object ourselves here?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes |
||
| Alias = new CommandAlias(commandAlias.Alias, commandAlias.CommandId, commandAlias.IsDirect); | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given all operation can be failed (Especially Save(), which I assume it will be saving to setting file), and I will suggest we need to rollback to previous Alias still being use?
The current alias handling pattern is not perfect, given it will directly change "current alias object".
Moreover, we can try to "Save" first, since for failure situation (no matter it failed at save, or failed at serviceManager), there will be less code to handle rollback to previous alias.