Skip to content

Commit 32d5a17

Browse files
committed
fix: Fix bug that a tag filter can not be removed when the filter is selected and then renamed. fix #390
1 parent c15c2b9 commit 32d5a17

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

Ui/View/ServerList/ServerListPageViewModel.Tag.cs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,27 @@ public partial class ServerListPageViewModel
2424
private string _selectedTabName = TAB_ALL_NAME;
2525
public string SelectedTabName { get => _selectedTabName; private set => SetAndNotifyIfChanged(ref _selectedTabName, value); }
2626

27+
28+
private void OnTagsChanged()
29+
{
30+
// 当修改了tags后,将无效的tag筛选器移除。
31+
var needRemove = new List<string>();
32+
var filters = TagFilters.ToList();
33+
foreach (var filter in filters)
34+
{
35+
if (AppData.TagList.All(x => x.Name != filter.TagName))
36+
{
37+
needRemove.Add(filter.TagName);
38+
}
39+
}
40+
41+
if (!needRemove.Any()) return;
42+
foreach (var tag in needRemove)
43+
{
44+
FilterTagsControl(tag, TagFilter.FilterTagsControlAction.Remove);
45+
}
46+
}
47+
2748
private List<TagFilter> _tagFilters = new List<TagFilter>();
2849
public List<TagFilter> TagFilters
2950
{
@@ -82,11 +103,13 @@ public List<TagFilter> TagFilters
82103
private void FilterTagsControl(object? o, TagFilter.FilterTagsControlAction action)
83104
{
84105
string newTagName;
85-
if (o is Tag obj && AppData.TagList.Any(x => x.Name == obj.Name))
106+
if (o is Tag obj
107+
&& (AppData.TagList.Any(x => x.Name == obj.Name) || action == TagFilter.FilterTagsControlAction.Remove))
86108
{
87109
newTagName = obj.Name;
88110
}
89-
else if (o is string str && AppData.TagList.Any(x => x.Name == str))
111+
else if (o is string str
112+
&& (AppData.TagList.Any(x => x.Name == str) || action == TagFilter.FilterTagsControlAction.Remove))
90113
{
91114
newTagName = str;
92115
}

Ui/View/ServerList/ServerListPageViewModel.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,11 @@ public ServerListPageViewModel(DataSourceService sourceService, GlobalData appDa
177177
}
178178

179179
RebuildVmServerList();
180+
AppData.PropertyChanged += (sender, args) =>
181+
{
182+
if (args.PropertyName == nameof(AppData.TagList))
183+
OnTagsChanged();
184+
};
180185
}
181186

182187
protected override void OnViewLoaded()

0 commit comments

Comments
 (0)