Browse Source

Enable win32 file dialog functionality for .NET Standard build

pull/1140/merge
Nikita Tsukanov 9 years ago
parent
commit
61e4e50d31
  1. 6
      src/Windows/Avalonia.Win32/Interop/UnmanagedMethods.cs
  2. 9
      src/Windows/Avalonia.Win32/SystemDialogImpl.cs

6
src/Windows/Avalonia.Win32/Interop/UnmanagedMethods.cs

@ -841,14 +841,13 @@ namespace Avalonia.Win32.Interop
return SetClassLong64(hWnd, nIndex, dwNewLong);
}
#if !NETSTANDARD && !NETSTANDARD2_0
[ComImport, ClassInterface(ClassInterfaceType.None), TypeLibType(TypeLibTypeFlags.FCanCreate), Guid("DC1C5A9C-E88A-4DDE-A5A1-60F82A20AEF7")]
internal class FileOpenDialogRCW { }
[DllImport("shell32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
internal static extern int SHCreateItemFromParsingName([MarshalAs(UnmanagedType.LPWStr)] string pszPath, IntPtr pbc, ref Guid riid, [MarshalAs(UnmanagedType.Interface)] out IShellItem ppv);
#endif
[DllImport("user32.dll", SetLastError = true)]
public static extern bool OpenClipboard(IntPtr hWndOwner);
@ -1183,7 +1182,7 @@ namespace Avalonia.Win32.Interop
public int flagsEx;
}
}
#if !NETSTANDARD && !NETSTANDARD1_3
[ComImport(), Guid("42F85136-DB7E-439C-85F1-E4075D135FC8"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
internal interface IFileDialog
{
@ -1283,5 +1282,4 @@ namespace Avalonia.Win32.Interop
uint Compare([In, MarshalAs(UnmanagedType.Interface)] IShellItem psi, [In] uint hint, out int piOrder);
}
#endif
}

9
src/Windows/Avalonia.Win32/SystemDialogImpl.cs

@ -100,17 +100,14 @@ namespace Avalonia.Win32
var pofn = &ofn;
// We should save the current directory to restore it later.
#if !NETSTANDARD
var currentDirectory = Environment.CurrentDirectory;
#endif
var res = dialog is OpenFileDialog
? UnmanagedMethods.GetOpenFileName(new IntPtr(pofn))
: UnmanagedMethods.GetSaveFileName(new IntPtr(pofn));
// Restore the old current directory, since GetOpenFileName and GetSaveFileName change it after they're called
#if !NETSTANDARD
Environment.CurrentDirectory = currentDirectory;
#endif
if (!res)
return null;
@ -155,9 +152,6 @@ namespace Avalonia.Win32
public Task<string> ShowFolderDialogAsync(OpenFolderDialog dialog, IWindowImpl parent)
{
#if NETSTANDARD
throw new NotImplementedException();
#else
return Task.Factory.StartNew(() =>
{
string result = string.Empty;
@ -214,7 +208,6 @@ namespace Avalonia.Win32
return result;
});
#endif
}
}
}

Loading…
Cancel
Save