Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ private void Item_PropertyChanged(object? sender, System.ComponentModel.Property
{
GenerateId();

UpdateAlias();
FetchAliasFromAliasManager();
UpdateHotkey();
UpdateTags();
}
Expand All @@ -163,24 +163,31 @@ private void Item_PropertyChanged(object? sender, System.ComponentModel.Property

private void HandleChangeAlias()
{
SetAlias(Alias);
Copy link
Contributor

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.

SetAlias();
Save();
}

public void SetAlias(CommandAlias? newAlias)
public void SetAlias()
Copy link
Contributor

Choose a reason for hiding this comment

The 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
Copy link
Contributor

Choose a reason for hiding this comment

The 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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

Alias = new CommandAlias(commandAlias.Alias, commandAlias.CommandId, commandAlias.IsDirect);
}
}
}

Expand Down
Loading