SaveDialog.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. //
  2. // FileDialog.cs: File system dialogs for open and save
  3. //
  4. // TODO:
  5. // * Add directory selector
  6. // * Implement subclasses
  7. // * Figure out why message text does not show
  8. // * Remove the extra space when message does not show
  9. // * Use a line separator to show the file listing, so we can use same colors as the rest
  10. // * DirListView: Add mouse support
  11. using System;
  12. using System.Collections.Generic;
  13. using System.Text;
  14. using Terminal.Gui.Resources;
  15. namespace Terminal.Gui {
  16. /// <summary>
  17. /// The <see cref="SaveDialog"/> provides an interactive dialog box for users to pick a file to
  18. /// save.
  19. /// </summary>
  20. /// <remarks>
  21. /// <para>
  22. /// To use, create an instance of <see cref="SaveDialog"/>, and pass it to
  23. /// <see cref="Application.Run(Func{Exception, bool})"/>. This will run the dialog modally,
  24. /// and when this returns, the <see cref="FileName"/>property will contain the selected file name or
  25. /// null if the user canceled.
  26. /// </para>
  27. /// </remarks>
  28. public class SaveDialog : FileDialog {
  29. /// <summary>
  30. /// Initializes a new <see cref="SaveDialog"/>.
  31. /// </summary>
  32. public SaveDialog () : this (title: string.Empty) { }
  33. /// <summary>
  34. /// Initializes a new <see cref="SaveDialog"/>.
  35. /// </summary>
  36. /// <param name="title">The title.</param>
  37. /// <param name="allowedTypes">The allowed types.</param>
  38. public SaveDialog (string title, List<IAllowedType> allowedTypes = null)
  39. {
  40. //: base (title, prompt: Strings.fdSave, nameFieldLabel: $"{Strings.fdSaveAs}:", message: message, allowedTypes) { }
  41. Title = title;
  42. Style.OkButtonText = Strings.fdSave;
  43. if(allowedTypes != null) {
  44. AllowedTypes = allowedTypes;
  45. }
  46. }
  47. /// <summary>
  48. /// Gets the name of the file the user selected for saving, or null
  49. /// if the user canceled the <see cref="SaveDialog"/>.
  50. /// </summary>
  51. /// <value>The name of the file.</value>
  52. public string FileName {
  53. get {
  54. if (Canceled)
  55. return null;
  56. return Path;
  57. }
  58. }
  59. }
  60. }