refactor add and remove functions
MODIFY
WalletWasabi.Fluent/Controls/TagControl.axaml.cs
WalletWasabi.Fluent/Controls/TagControl.axaml.cs
@@ -67,7 +67,7 @@ namespace WalletWasabi.Fluent.Controls
private void OnDeleteTagClicked(object? sender, RoutedEventArgs e)
{
- _parentTagBox?.RemoveTargetTag(DataContext);
+ _parentTagBox?.RemoveAt(OrdinalIndex - 1);
}
}
}

MODIFY
WalletWasabi.Fluent/Controls/TagsBox.axaml.cs
WalletWasabi.Fluent/Controls/TagsBox.axaml.cs
@@ -490,17 +490,6 @@ namespace WalletWasabi.Fluent.Controls
}
}
- private void RemoveLastTag()
- {
- if (Items is IList { Count: > 0 } list)
- {
- list.RemoveAt(list.Count - 1);
- }
-
- InvalidateWatermark();
- CheckIsInputEnabled();
- }
-
protected override void OnPropertyChanged<T>(AvaloniaPropertyChangedEventArgs<T> e)
{
base.OnPropertyChanged(e);
@@ -517,38 +506,53 @@ namespace WalletWasabi.Fluent.Controls
}
}
- internal void RemoveTargetTag(object? tag)
+ private void RemoveLastTag()
{
- if (Items is IList list)
+ if (Items is IList { Count: > 0 } items)
{
- list.Remove(tag);
+ RemoveAt(items.Count - 1);
+ }
}
- InvalidateWatermark();
+ public void RemoveAt(int index)
+ {
+ if (Items is not IList items)
+ {
+ return;
+ }
+
+ items.RemoveAt(index);
CheckIsInputEnabled();
+ InvalidateWatermark();
}
public void AddTag(string tag)
{
- if (Items is IList x)
- {
- if (ItemCountLimit > 0 && x.Count + 1 > ItemCountLimit)
+ if (Items is not IList items)
{
return;
}
- var finalTag = tag.ParseLabel();
+ if (ItemCountLimit > 0 && items.Count + 1 > ItemCountLimit)
+ {
+ return;
+ }
- if (!AllowDuplication && x.Contains(finalTag))
+ if (!AllowDuplication && items.Contains(tag))
{
return;
}
- x.Add(finalTag);
+ if (RestrictInputToSuggestions &&
+ Suggestions is { } suggestions &&
+ !suggestions.Any(x => x.Equals(tag, _stringComparison)))
+ {
+ return;
}
- InvalidateWatermark();
+ items.Add(tag);
CheckIsInputEnabled();
+ InvalidateWatermark();
}
}
}

refactor add and remove functions