Skip to content

Commit

Permalink
Feature: Added back support for applying tags by dropping files on th…
Browse files Browse the repository at this point in the history
…e sidebar (#16640)
  • Loading branch information
gave92 authored Dec 22, 2024
1 parent 0a4266e commit aaefa0a
Showing 1 changed file with 22 additions and 26 deletions.
48 changes: 22 additions & 26 deletions src/Files.App/ViewModels/UserControls/SidebarViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1214,34 +1214,28 @@ 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)
{
if (args.DropTarget is LocationItem locationItem)
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)
Expand Down Expand Up @@ -1269,18 +1263,20 @@ private Task<ReturnResult> 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);
}
}
}

Expand Down

0 comments on commit aaefa0a

Please sign in to comment.