Skip to content

Commit 65834fc

Browse files
Fix: Remove deleted tags from items (#11309)
1 parent 37e4b75 commit 65834fc

File tree

4 files changed

+28
-11
lines changed

4 files changed

+28
-11
lines changed

src/Files.App/ServicesImplementation/Settings/FileTagsSettingsService.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using Files.App.Extensions;
2-
using Files.App.Helpers;
2+
using Files.App.Filesystem;
33
using Files.App.Serialization;
44
using Files.App.Serialization.Implementation;
55
using Files.Backend.Services.Settings;
@@ -114,6 +114,8 @@ public void DeleteTag(string uid)
114114
var oldTags = FileTagList.ToList();
115115
oldTags.RemoveAt(index);
116116
FileTagList = oldTags;
117+
UntagAllFiles(uid);
118+
117119
OnTagsUpdated.Invoke(this, EventArgs.Empty);
118120
}
119121

@@ -163,5 +165,20 @@ public override object ExportSettings()
163165

164166
return (tag, index);
165167
}
168+
169+
private void UntagAllFiles(string uid)
170+
{
171+
var tagDoDelete = new string [] { uid };
172+
173+
foreach (var item in FileTagsHelper.GetDbInstance().GetAll())
174+
{
175+
if (item.Tags.Contains(uid))
176+
{
177+
FileTagsHelper.WriteFileTag(
178+
item.FilePath,
179+
item.Tags.Except(tagDoDelete).ToArray());
180+
}
181+
}
182+
}
166183
}
167184
}

src/Files.App/ViewModels/ItemViewModel.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,8 @@ public ItemViewModel(FolderSettingsViewModel folderSettingsViewModel)
376376
dispatcherQueue = DispatcherQueue.GetForCurrentThread();
377377

378378
UserSettingsService.OnSettingChangedEvent += UserSettingsService_OnSettingChangedEvent;
379-
fileTagsSettingsService.OnSettingImportedEvent += FileTagsSettingsService_OnSettingImportedEvent;
379+
fileTagsSettingsService.OnSettingImportedEvent += FileTagsSettingsService_OnSettingUpdated;
380+
fileTagsSettingsService.OnTagsUpdated += FileTagsSettingsService_OnSettingUpdated;
380381
folderSizeProvider.SizeChanged += FolderSizeProvider_SizeChanged;
381382
RecycleBinManager.Default.RecycleBinItemCreated += RecycleBinItemCreated;
382383
RecycleBinManager.Default.RecycleBinItemDeleted += RecycleBinItemDeleted;
@@ -473,7 +474,7 @@ await dispatcherQueue.EnqueueAsync(() =>
473474
}
474475
}
475476

476-
private async void FileTagsSettingsService_OnSettingImportedEvent(object? sender, EventArgs e)
477+
private async void FileTagsSettingsService_OnSettingUpdated(object? sender, EventArgs e)
477478
{
478479
await dispatcherQueue.EnqueueAsync(() =>
479480
{
@@ -2281,7 +2282,8 @@ public void Dispose()
22812282
RecycleBinManager.Default.RecycleBinItemDeleted -= RecycleBinItemDeleted;
22822283
RecycleBinManager.Default.RecycleBinRefreshRequested -= RecycleBinRefreshRequested;
22832284
UserSettingsService.OnSettingChangedEvent -= UserSettingsService_OnSettingChangedEvent;
2284-
fileTagsSettingsService.OnSettingImportedEvent -= FileTagsSettingsService_OnSettingImportedEvent;
2285+
fileTagsSettingsService.OnSettingImportedEvent -= FileTagsSettingsService_OnSettingUpdated;
2286+
fileTagsSettingsService.OnTagsUpdated -= FileTagsSettingsService_OnSettingUpdated;
22852287
folderSizeProvider.SizeChanged -= FolderSizeProvider_SizeChanged;
22862288
DefaultIcons.Clear();
22872289
}

src/Files.App/Views/LayoutModes/DetailsLayoutBrowser.xaml.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ public sealed partial class DetailsLayoutBrowser : StandardViewBase
4040

4141
private ListedItem? _nextItemToSelect;
4242

43-
private IFileTagsSettingsService tagsSettingsService { get; } = Ioc.Default.GetRequiredService<IFileTagsSettingsService>();
44-
4543
protected override uint IconSize => currentIconSize;
4644

4745
protected override ListViewBase ListViewBase => FileList;
@@ -757,7 +755,7 @@ private void TagIcon_Tapped(object sender, TappedRoutedEventArgs e)
757755
if (tagName is null || parent?.DataContext is not ListedItem item)
758756
return;
759757

760-
var tagId = tagsSettingsService.GetTagsByName(tagName).FirstOrDefault()?.Uid;
758+
var tagId = FileTagsSettingsService.GetTagsByName(tagName).FirstOrDefault()?.Uid;
761759

762760
item.FileTags = item.FileTags
763761
.Except(new string[] { tagId })

src/Files.App/Views/SettingsPages/Advanced.xaml.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,16 +100,16 @@ private void NewTagTextBox_TextChanged(object sender, TextChangedEventArgs e)
100100
private bool IsNameValid(string name)
101101
{
102102
return !(
103-
string.IsNullOrWhiteSpace(name) ||
104-
name.StartsWith('.') ||
105-
name.EndsWith('.') ||
103+
string.IsNullOrWhiteSpace(name) ||
104+
name.StartsWith('.') ||
105+
name.EndsWith('.') ||
106106
ViewModel.Tags.Any(tag => name == tag.Tag.Name)
107107
);
108108
}
109109

110110
private void KeyboardAccelerator_Invoked(KeyboardAccelerator sender, KeyboardAcceleratorInvokedEventArgs args)
111111
{
112-
if (args.KeyboardAccelerator.Key is VirtualKey.Escape)
112+
if (args.KeyboardAccelerator.Key is VirtualKey.Escape && editingTag is not null)
113113
{
114114
CloseEdit();
115115
args.Handled = true;

0 commit comments

Comments
 (0)