Skip to content

Commit

Permalink
The file loaders would accept HWND
Browse files Browse the repository at this point in the history
  • Loading branch information
iconstudio committed Oct 6, 2023
1 parent 7f3045b commit ae3ba6b
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions Editor/TestEditor/Utilities/FilePickHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,67 @@
using Windows.Storage;
using Windows.Storage.Pickers;
using TestEditor.Editor;
using Windows.Win32.Foundation;

namespace TestEditor.Utility
{
public static class FilePickHelper
public static class FilePickHelper
{
public static
internal static
IAsyncOperation<StorageFile>
OpenLoadPicker(Window window, IEnumerable<string> extentions)
{
var handle = WinRT.Interop.WindowNative.GetWindowHandle(window);

return OpenLoadPicker((HWND) handle, extentions);
}
internal static
IAsyncOperation<StorageFile>
OpenLoadPicker(Window window, params string[] extentions)
{
var handle = WinRT.Interop.WindowNative.GetWindowHandle(window);

return OpenLoadPicker((HWND) handle, extentions);
}
internal static
IAsyncOperation<StorageFile>
OpenLoadPicker(HWND hwnd, IEnumerable<string> extentions)
{
FileOpenPicker picker = new()
{
ViewMode = PickerViewMode.Thumbnail
};

picker.FileTypeFilter.Clear();
foreach (var ext in extentions)
{
picker.FileTypeFilter.Add(ext);
}

var hwnd = WinRT.Interop.WindowNative.GetWindowHandle(window);
WinRT.Interop.InitializeWithWindow.Initialize(picker, hwnd);

return picker.PickSingleFileAsync();
}
public static
internal static
IAsyncOperation<StorageFile>
OpenLoadPicker(Window window, params string[] extentions)
OpenLoadPicker(HWND hwnd, params string[] extentions)
{
FileOpenPicker picker = new()
{
ViewMode = PickerViewMode.Thumbnail
};

picker.FileTypeFilter.Clear();
foreach (var ext in extentions)
{
picker.FileTypeFilter.Add(ext);
}

var hwnd = WinRT.Interop.WindowNative.GetWindowHandle(window);
WinRT.Interop.InitializeWithWindow.Initialize(picker, hwnd);

return picker.PickSingleFileAsync();
}
public static
internal static
IAsyncOperation<StorageFile>
OpenSavePicker(Window window)
{
Expand Down

0 comments on commit ae3ba6b

Please sign in to comment.