BrowseDialog.cs 3.4 KB

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