Skip to content

armgit / Filee

Public Imported from GitHub
0

Free, open-source file converter. Convert 263 formats offline by drag & drop — images, PDF, Word, Excel, PowerPoint, HWP/HWPX, video, audio, e-books and archives. No upload, no Office needed.

Dragged folders go into archives too

Sonica Reddy566002ddbca3
diff --git a/src/Filee.App/Services/DraggedFiles.cs b/src/Filee.App/Services/DraggedFiles.cs
index e5fca059..43a6818f 100644
--- a/src/Filee.App/Services/DraggedFiles.cs
+++ b/src/Filee.App/Services/DraggedFiles.cs
@@ -16,17 +16,21 @@ internal static class DraggedFiles
data.Contains(DataFormat.File) || data.Items.Any(item => item.Formats.Any(IsFilenames));
/// <summary>
- /// Local file paths in the drag (folders and virtual items are ignored). A shortcut counts as the file it points
- /// to; one to a folder is ignored like the folder.
+ /// Local file and folder paths in the drag (virtual items are ignored). A shortcut counts as the file or folder it
+ /// points to. Folders go into "Compress into one archive" like on the command line (issue #186); other presets
+ /// report them as unsupported.
/// </summary>
public static IReadOnlyList<string> Local(IDataTransfer data) =>
- Local(data, File.Exists, AppHost.Get<IPlatformServices>().ResolveShortcuts);
+ Local(data, IsFileOrFolder, AppHost.Get<IPlatformServices>().ResolveShortcuts);
- internal static IReadOnlyList<string> Local(IDataTransfer data, Func<string, bool> fileExists,
+ /// <summary>Whether <paramref name="path"/> is a file or a folder that exists.</summary>
+ internal static bool IsFileOrFolder(string path) => File.Exists(path) || Directory.Exists(path);
+
+ internal static IReadOnlyList<string> Local(IDataTransfer data, Func<string, bool> exists,
Func<IReadOnlyList<string>, IReadOnlyList<string>>? resolveShortcuts = null)
{
IReadOnlyList<string> Usable(IReadOnlyList<string> paths) =>
- (resolveShortcuts?.Invoke(paths) ?? paths).Where(fileExists).Distinct(FileSystemPaths.Comparer).ToList();
+ (resolveShortcuts?.Invoke(paths) ?? paths).Where(exists).Distinct(FileSystemPaths.Comparer).ToList();
var files = Usable((data.TryGetFiles() ?? []).Select(item => item.TryGetLocalPath()).OfType<string>().ToList());
return files.Count > 0 ? files : Usable(Filenames(data).ToList());
diff --git a/tests/Filee.App.Tests/OtherFileManagerTests.cs b/tests/Filee.App.Tests/OtherFileManagerTests.cs
index ba70d407..78ffb946 100644
--- a/tests/Filee.App.Tests/OtherFileManagerTests.cs
+++ b/tests/Filee.App.Tests/OtherFileManagerTests.cs
@@ -36,6 +36,29 @@ public class OtherFileManagerTests
Assert.Equal(["/Users/a/1.png"], DraggedFiles.Local(data, Files.Contains));
}
+ [Fact]
+ public void A_dragged_folder_counts_like_a_file_so_it_can_go_into_an_archive()
+ {
+ var folder = Directory.CreateTempSubdirectory("filee-drag-folder-").FullName;
+ var file = Path.Combine(folder, "1.png");
+ File.WriteAllBytes(file, [1]);
+ try
+ {
+ Assert.True(DraggedFiles.IsFileOrFolder(file));
+ Assert.True(DraggedFiles.IsFileOrFolder(folder));
+ Assert.False(DraggedFiles.IsFileOrFolder(Path.Combine(folder, "missing.png")));
+ }
+ finally
+ {
+ Directory.Delete(folder, recursive: true);
+ }
+
+ // Issue #186: files and folders dragged together all stay in the list.
+ using var data = Drag(PasteboardPaths.FilenamesType, Encoding.UTF8.GetBytes(Plist));
+ HashSet<string> existing = ["/Users/a/1.png", "/Users/a/folder"];
+ Assert.Equal(["/Users/a/1.png", "/Users/a/folder"], DraggedFiles.Local(data, existing.Contains));
+ }
+
[Fact]
public void A_drag_of_text_or_file_promises_brings_no_files_and_says_what_it_offered()
{