BrowseDialog.cs 3.1 KB

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