diff --git a/src/Files.App/ViewModels/UserControls/SidebarViewModel.cs b/src/Files.App/ViewModels/UserControls/SidebarViewModel.cs index cdea49b4f614..b59fb8ac3172 100644 --- a/src/Files.App/ViewModels/UserControls/SidebarViewModel.cs +++ b/src/Files.App/ViewModels/UserControls/SidebarViewModel.cs @@ -1214,22 +1214,19 @@ private async Task HandleTagItemDragOverAsync(FileTagItem tagItem, ItemDragOverE args.RawEvent.Handled = true; - // Comment out the code for dropping to Tags section as it is currently not supported. - - //var storageItems = await Utils.Storage.FilesystemHelpers.GetDraggedStorageItems(args.DroppedItem); - - //if (!storageItems.Any()) - //{ - args.RawEvent.AcceptedOperation = DataPackageOperation.None; - //} - //else - //{ - // args.RawEvent.DragUIOverride.IsCaptionVisible = true; - // args.RawEvent.DragUIOverride.Caption = string.Format("LinkToFolderCaptionText".GetLocalizedResource(), tagItem.Text); - // args.RawEvent.AcceptedOperation = DataPackageOperation.Link; - //} - } + var storageItems = await Utils.Storage.FilesystemHelpers.GetDraggedStorageItems(args.DroppedItem); + if (!storageItems.Any(x => !string.IsNullOrEmpty(x.Path))) + { + args.RawEvent.AcceptedOperation = DataPackageOperation.None; + } + else + { + args.RawEvent.DragUIOverride.IsCaptionVisible = true; + args.RawEvent.DragUIOverride.Caption = string.Format("LinkToFolderCaptionText".GetLocalizedResource(), tagItem.Text); + args.RawEvent.AcceptedOperation = DataPackageOperation.Link; + } + } public async Task HandleItemDroppedAsync(ItemDroppedEventArgs args) { @@ -1237,11 +1234,8 @@ public async Task HandleItemDroppedAsync(ItemDroppedEventArgs args) await HandleLocationItemDroppedAsync(locationItem, args); else if (args.DropTarget is DriveItem driveItem) await HandleDriveItemDroppedAsync(driveItem, args); - - // Comment out the code for dropping to Tags section as it is currently not supported. - - //else if (args.DropTarget is FileTagItem fileTagItem) - // await HandleTagItemDroppedAsync(fileTagItem, args); + else if (args.DropTarget is FileTagItem fileTagItem) + await HandleTagItemDroppedAsync(fileTagItem, args); } private async Task HandleLocationItemDroppedAsync(LocationItem locationItem, ItemDroppedEventArgs args) @@ -1269,18 +1263,20 @@ private Task HandleDriveItemDroppedAsync(DriveItem driveItem, Item return FilesystemHelpers.PerformOperationTypeAsync(args.RawEvent.AcceptedOperation, args.RawEvent.DataView, driveItem.Path, false, true); } - // TODO: This method effectively does nothing. We need to implement the functionality for dropping to Tags section. private async Task HandleTagItemDroppedAsync(FileTagItem fileTagItem, ItemDroppedEventArgs args) { var storageItems = await Utils.Storage.FilesystemHelpers.GetDraggedStorageItems(args.DroppedItem); + var dbInstance = FileTagsHelper.GetDbInstance(); foreach (var item in storageItems.Where(x => !string.IsNullOrEmpty(x.Path))) { - var listedItem = new ListedItem(null) + var filesTags = FileTagsHelper.ReadFileTag(item.Path); + if (!filesTags.Contains(fileTagItem.FileTag.Uid)) { - ItemPath = item.Path, - FileFRN = await FileTagsHelper.GetFileFRN(item.Item), - FileTags = [fileTagItem.FileTag.Uid] - }; + filesTags = [.. filesTags, fileTagItem.FileTag.Uid]; + var fileFRN = await FileTagsHelper.GetFileFRN(item.Item); + dbInstance.SetTags(item.Path, fileFRN, filesTags); + FileTagsHelper.WriteFileTag(item.Path, filesTags); + } } }