Implement PickFolder and use more nullables

This commit is contained in:
Speykious committed 2022-03-27 17:49:44 +02:00
1 parent 9714ed8cd7
commit 4caf1bdd2d
1 file changed
+20 -4
+20 -4
View File
@@ -12,7 +12,7 @@ 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)
public static NfdStatus OpenDialog(out string? outPath, IDictionary<string, string>? filters = null, string? defaultPath = null)
{
manager.PushDialog();
NfdnfilteritemT[] filterItems = ToFilterItems(filters);
@@ -22,14 +22,14 @@ public static class Nfd
{
sbyte* outPathPtr;
status = nfd.NFD_OpenDialogN(&outPathPtr, filterItems, (uint)filterItems.Length, defaultPath).ToNfdStatus();
outPath = status == NfdStatus.Cancelled ? "" : new string(outPathPtr);
outPath = status == NfdStatus.Cancelled ? null : new string(outPathPtr);
}
manager.PullDialog();
return status;
}
public static NfdStatus OpenDialogMultiple(out string[] outPaths, IDictionary<string, string>? filters = null, string? defaultPath = null)
public static NfdStatus OpenDialogMultiple(out string[]? outPaths, IDictionary<string, string>? filters = null, string? defaultPath = null)
{
manager.PushDialog();
NfdnfilteritemT[] filterItems = ToFilterItems(filters);
@@ -57,7 +57,7 @@ public static class Nfd
}
else
{
outPaths = Array.Empty<string>();
outPaths = null;
}
}
@@ -65,6 +65,22 @@ public static class Nfd
return status;
}
public static NfdStatus PickFolder(out string? outPath, string? defaultPath = null)
{
manager.PushDialog();
NfdStatus status;
unsafe
{
sbyte* outPathPtr;
status = nfd.NFD_PickFolderN(&outPathPtr, defaultPath).ToNfdStatus();
outPath = status == NfdStatus.Cancelled ? null : new string(outPathPtr);
}
manager.PullDialog();
return status;
}
internal static NfdnfilteritemT[] ToFilterItems(IDictionary<string, string>? filters)
{
if (filters == null)