Skip to content

Commit aaefa0a

Browse files
authored
Feature: Added back support for applying tags by dropping files on the sidebar (#16640)
1 parent 0a4266e commit aaefa0a

File tree

1 file changed

+22
-26
lines changed

1 file changed

+22
-26
lines changed

src/Files.App/ViewModels/UserControls/SidebarViewModel.cs

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,34 +1214,28 @@ private async Task HandleTagItemDragOverAsync(FileTagItem tagItem, ItemDragOverE
12141214

12151215
args.RawEvent.Handled = true;
12161216

1217-
// Comment out the code for dropping to Tags section as it is currently not supported.
1218-
1219-
//var storageItems = await Utils.Storage.FilesystemHelpers.GetDraggedStorageItems(args.DroppedItem);
1220-
1221-
//if (!storageItems.Any())
1222-
//{
1223-
args.RawEvent.AcceptedOperation = DataPackageOperation.None;
1224-
//}
1225-
//else
1226-
//{
1227-
// args.RawEvent.DragUIOverride.IsCaptionVisible = true;
1228-
// args.RawEvent.DragUIOverride.Caption = string.Format("LinkToFolderCaptionText".GetLocalizedResource(), tagItem.Text);
1229-
// args.RawEvent.AcceptedOperation = DataPackageOperation.Link;
1230-
//}
1231-
}
1217+
var storageItems = await Utils.Storage.FilesystemHelpers.GetDraggedStorageItems(args.DroppedItem);
12321218

1219+
if (!storageItems.Any(x => !string.IsNullOrEmpty(x.Path)))
1220+
{
1221+
args.RawEvent.AcceptedOperation = DataPackageOperation.None;
1222+
}
1223+
else
1224+
{
1225+
args.RawEvent.DragUIOverride.IsCaptionVisible = true;
1226+
args.RawEvent.DragUIOverride.Caption = string.Format("LinkToFolderCaptionText".GetLocalizedResource(), tagItem.Text);
1227+
args.RawEvent.AcceptedOperation = DataPackageOperation.Link;
1228+
}
1229+
}
12331230

12341231
public async Task HandleItemDroppedAsync(ItemDroppedEventArgs args)
12351232
{
12361233
if (args.DropTarget is LocationItem locationItem)
12371234
await HandleLocationItemDroppedAsync(locationItem, args);
12381235
else if (args.DropTarget is DriveItem driveItem)
12391236
await HandleDriveItemDroppedAsync(driveItem, args);
1240-
1241-
// Comment out the code for dropping to Tags section as it is currently not supported.
1242-
1243-
//else if (args.DropTarget is FileTagItem fileTagItem)
1244-
// await HandleTagItemDroppedAsync(fileTagItem, args);
1237+
else if (args.DropTarget is FileTagItem fileTagItem)
1238+
await HandleTagItemDroppedAsync(fileTagItem, args);
12451239
}
12461240

12471241
private async Task HandleLocationItemDroppedAsync(LocationItem locationItem, ItemDroppedEventArgs args)
@@ -1269,18 +1263,20 @@ private Task<ReturnResult> HandleDriveItemDroppedAsync(DriveItem driveItem, Item
12691263
return FilesystemHelpers.PerformOperationTypeAsync(args.RawEvent.AcceptedOperation, args.RawEvent.DataView, driveItem.Path, false, true);
12701264
}
12711265

1272-
// TODO: This method effectively does nothing. We need to implement the functionality for dropping to Tags section.
12731266
private async Task HandleTagItemDroppedAsync(FileTagItem fileTagItem, ItemDroppedEventArgs args)
12741267
{
12751268
var storageItems = await Utils.Storage.FilesystemHelpers.GetDraggedStorageItems(args.DroppedItem);
1269+
var dbInstance = FileTagsHelper.GetDbInstance();
12761270
foreach (var item in storageItems.Where(x => !string.IsNullOrEmpty(x.Path)))
12771271
{
1278-
var listedItem = new ListedItem(null)
1272+
var filesTags = FileTagsHelper.ReadFileTag(item.Path);
1273+
if (!filesTags.Contains(fileTagItem.FileTag.Uid))
12791274
{
1280-
ItemPath = item.Path,
1281-
FileFRN = await FileTagsHelper.GetFileFRN(item.Item),
1282-
FileTags = [fileTagItem.FileTag.Uid]
1283-
};
1275+
filesTags = [.. filesTags, fileTagItem.FileTag.Uid];
1276+
var fileFRN = await FileTagsHelper.GetFileFRN(item.Item);
1277+
dbInstance.SetTags(item.Path, fileFRN, filesTags);
1278+
FileTagsHelper.WriteFileTag(item.Path, filesTags);
1279+
}
12841280
}
12851281
}
12861282

0 commit comments

Comments
 (0)