Skip to content

Commit

Permalink
Fix: Remove deleted tags from items (#11309)
Browse files Browse the repository at this point in the history
  • Loading branch information
ferrariofilippo authored Feb 15, 2023
1 parent 37e4b75 commit 65834fc
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Files.App.Extensions;
using Files.App.Helpers;
using Files.App.Filesystem;
using Files.App.Serialization;
using Files.App.Serialization.Implementation;
using Files.Backend.Services.Settings;
Expand Down Expand Up @@ -114,6 +114,8 @@ public void DeleteTag(string uid)
var oldTags = FileTagList.ToList();
oldTags.RemoveAt(index);
FileTagList = oldTags;
UntagAllFiles(uid);

OnTagsUpdated.Invoke(this, EventArgs.Empty);
}

Expand Down Expand Up @@ -163,5 +165,20 @@ public override object ExportSettings()

return (tag, index);
}

private void UntagAllFiles(string uid)
{
var tagDoDelete = new string [] { uid };

foreach (var item in FileTagsHelper.GetDbInstance().GetAll())
{
if (item.Tags.Contains(uid))
{
FileTagsHelper.WriteFileTag(
item.FilePath,
item.Tags.Except(tagDoDelete).ToArray());
}
}
}
}
}
8 changes: 5 additions & 3 deletions src/Files.App/ViewModels/ItemViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,8 @@ public ItemViewModel(FolderSettingsViewModel folderSettingsViewModel)
dispatcherQueue = DispatcherQueue.GetForCurrentThread();

UserSettingsService.OnSettingChangedEvent += UserSettingsService_OnSettingChangedEvent;
fileTagsSettingsService.OnSettingImportedEvent += FileTagsSettingsService_OnSettingImportedEvent;
fileTagsSettingsService.OnSettingImportedEvent += FileTagsSettingsService_OnSettingUpdated;
fileTagsSettingsService.OnTagsUpdated += FileTagsSettingsService_OnSettingUpdated;
folderSizeProvider.SizeChanged += FolderSizeProvider_SizeChanged;
RecycleBinManager.Default.RecycleBinItemCreated += RecycleBinItemCreated;
RecycleBinManager.Default.RecycleBinItemDeleted += RecycleBinItemDeleted;
Expand Down Expand Up @@ -473,7 +474,7 @@ await dispatcherQueue.EnqueueAsync(() =>
}
}

private async void FileTagsSettingsService_OnSettingImportedEvent(object? sender, EventArgs e)
private async void FileTagsSettingsService_OnSettingUpdated(object? sender, EventArgs e)
{
await dispatcherQueue.EnqueueAsync(() =>
{
Expand Down Expand Up @@ -2281,7 +2282,8 @@ public void Dispose()
RecycleBinManager.Default.RecycleBinItemDeleted -= RecycleBinItemDeleted;
RecycleBinManager.Default.RecycleBinRefreshRequested -= RecycleBinRefreshRequested;
UserSettingsService.OnSettingChangedEvent -= UserSettingsService_OnSettingChangedEvent;
fileTagsSettingsService.OnSettingImportedEvent -= FileTagsSettingsService_OnSettingImportedEvent;
fileTagsSettingsService.OnSettingImportedEvent -= FileTagsSettingsService_OnSettingUpdated;
fileTagsSettingsService.OnTagsUpdated -= FileTagsSettingsService_OnSettingUpdated;
folderSizeProvider.SizeChanged -= FolderSizeProvider_SizeChanged;
DefaultIcons.Clear();
}
Expand Down
4 changes: 1 addition & 3 deletions src/Files.App/Views/LayoutModes/DetailsLayoutBrowser.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ public sealed partial class DetailsLayoutBrowser : StandardViewBase

private ListedItem? _nextItemToSelect;

private IFileTagsSettingsService tagsSettingsService { get; } = Ioc.Default.GetRequiredService<IFileTagsSettingsService>();

protected override uint IconSize => currentIconSize;

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

var tagId = tagsSettingsService.GetTagsByName(tagName).FirstOrDefault()?.Uid;
var tagId = FileTagsSettingsService.GetTagsByName(tagName).FirstOrDefault()?.Uid;

item.FileTags = item.FileTags
.Except(new string[] { tagId })
Expand Down
8 changes: 4 additions & 4 deletions src/Files.App/Views/SettingsPages/Advanced.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,16 @@ private void NewTagTextBox_TextChanged(object sender, TextChangedEventArgs e)
private bool IsNameValid(string name)
{
return !(
string.IsNullOrWhiteSpace(name) ||
name.StartsWith('.') ||
name.EndsWith('.') ||
string.IsNullOrWhiteSpace(name) ||
name.StartsWith('.') ||
name.EndsWith('.') ||
ViewModel.Tags.Any(tag => name == tag.Tag.Name)
);
}

private void KeyboardAccelerator_Invoked(KeyboardAccelerator sender, KeyboardAcceleratorInvokedEventArgs args)
{
if (args.KeyboardAccelerator.Key is VirtualKey.Escape)
if (args.KeyboardAccelerator.Key is VirtualKey.Escape && editingTag is not null)
{
CloseEdit();
args.Handled = true;
Expand Down

0 comments on commit 65834fc

Please sign in to comment.