Implement OpenDialogMultiple

This commit is contained in:
Speykious committed 2022-03-27 17:42:35 +02:00
1 parent 824b671693
commit 9714ed8cd7
1 file changed
+37
+37
View File
@@ -11,6 +11,7 @@ namespace NativeFileDialogs.Net;
public static class Nfd
{
private static readonly NfdManager manager = new NfdManager();
public static NfdStatus OpenDialog(out string outPath, IDictionary<string, string>? filters = null, string? defaultPath = null)
{
manager.PushDialog();
@@ -28,6 +29,42 @@ public static class Nfd
return status;
}
public static NfdStatus OpenDialogMultiple(out string[] outPaths, IDictionary<string, string>? filters = null, string? defaultPath = null)
{
manager.PushDialog();
NfdnfilteritemT[] filterItems = ToFilterItems(filters);
NfdStatus status;
unsafe
{
IntPtr pathSet;
status = nfd.NFD_OpenDialogMultipleN(&pathSet, filterItems, (uint)filterItems.Length, defaultPath).ToNfdStatus();
if (status == NfdStatus.Ok)
{
uint count = 0;
nfd.NFD_PathSetGetCount(pathSet, ref count).ToNfdStatus();
outPaths = new string[count];
for (uint i = 0; i < count; i++)
{
sbyte* pathPtr;
nfd.NFD_PathSetGetPathN(pathSet, i, &pathPtr);
outPaths[i] = new string(pathPtr);
}
nfd.NFD_PathSetFree(pathSet);
}
else
{
outPaths = Array.Empty<string>();
}
}
manager.PullDialog();
return status;
}
internal static NfdnfilteritemT[] ToFilterItems(IDictionary<string, string>? filters)
{
if (filters == null)