BrowseDialog.cs 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. using System.Runtime.CompilerServices;
  4. namespace bs.Editor
  5. {
  6. /** @addtogroup Windows
  7. * @{
  8. */
  9. /// <summary>
  10. /// Contains methods for opening various OS-specific browse, open and save file/folder dialogs.
  11. /// </summary>
  12. public static class BrowseDialog
  13. {
  14. /// <summary>
  15. /// Displays a platform specific dialog that allows the user to select file(s).
  16. /// </summary>
  17. /// <param name="defaultPath">Default path the dialog should point to.</param>
  18. /// <param name="filterList">Semi-colon separated list of file names or types to display in the dialog,
  19. /// for example "exe;txt;png".</param>
  20. /// <param name="allowMultiselect">True if user is allowed to select multiple files.</param>
  21. /// <param name="outPaths">A list of file paths selected by the user.</param>
  22. /// <returns>True if the user selected the file(s), false if the user canceled out of the dialog.</returns>
  23. public static bool OpenFile(string defaultPath, string filterList, bool allowMultiselect, out string[] outPaths)
  24. {
  25. return Internal_OpenFile(defaultPath, filterList, allowMultiselect, out outPaths);
  26. }
  27. /// <summary>
  28. /// Displays a platform specific dialog that allows the user to select a folder.
  29. /// </summary>
  30. /// <param name="defaultPath">Default path the dialog should point to.</param>
  31. /// <param name="outPath">Path to the selected folder.</param>
  32. /// <returns>True if the user selected the folder, false if the user canceled out of the dialog.</returns>
  33. public static bool OpenFolder(string defaultPath, out string outPath)
  34. {
  35. return Internal_OpenFolder(defaultPath, out outPath);
  36. }
  37. /// <summary>
  38. /// Displays a platform specific dialog that allows the user to select where to save a file.
  39. /// </summary>
  40. /// <param name="defaultPath">Default path the dialog should point to.</param>
  41. /// <param name="filterList">Semi-colon separated list of file names or types to display in the dialog,
  42. /// for example "exe;txt;png".</param>
  43. /// <param name="outPath">File path selected by the user.</param>
  44. /// <returns>True if the user selected the file, false if the user canceled out of the dialog.</returns>
  45. public static bool SaveFile(string defaultPath, string filterList, out string outPath)
  46. {
  47. return Internal_SaveFile(defaultPath, filterList, out outPath);
  48. }
  49. [MethodImpl(MethodImplOptions.InternalCall)]
  50. private static extern bool Internal_OpenFile(string defaultPath, string filterList, bool allowMultiselect, out string[] outPaths);
  51. [MethodImpl(MethodImplOptions.InternalCall)]
  52. private static extern bool Internal_OpenFolder(string defaultPath, out string outPath);
  53. [MethodImpl(MethodImplOptions.InternalCall)]
  54. private static extern bool Internal_SaveFile(string defaultPath, string filterList, out string outPath);
  55. }
  56. /** @} */
  57. }