SaveDialog.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 Terminal.Gui.Resources;
  12. namespace Terminal.Gui;
  13. /// <summary>The <see cref="SaveDialog"/> provides an interactive dialog box for users to pick a file to save.</summary>
  14. /// <remarks>
  15. /// <para>
  16. /// To use, create an instance of <see cref="SaveDialog"/>, and pass it to
  17. /// <see cref="Application.Run(Toplevel, Func{Exception, bool})"/>. This will run the dialog modally, and when this returns,
  18. /// the <see cref="FileName"/>property will contain the selected file name or null if the user canceled.
  19. /// </para>
  20. /// </remarks>
  21. public class SaveDialog : FileDialog
  22. {
  23. /// <summary>Initializes a new <see cref="SaveDialog"/>.</summary>
  24. public SaveDialog () { Style.OkButtonText = Strings.btnSave; }
  25. /// <summary>
  26. /// Gets the name of the file the user selected for saving, or null if the user canceled the
  27. /// <see cref="SaveDialog"/>.
  28. /// </summary>
  29. /// <value>The name of the file.</value>
  30. public string FileName => Canceled ? null : Path;
  31. /// <summary>Gets the default title for the <see cref="SaveDialog"/>.</summary>
  32. /// <returns></returns>
  33. protected override string GetDefaultTitle ()
  34. {
  35. List<string> titleParts = [Strings.fdSave]
  36. ;
  37. if (MustExist)
  38. {
  39. titleParts.Add (Strings.fdExisting);
  40. }
  41. switch (OpenMode)
  42. {
  43. case OpenMode.File:
  44. titleParts.Add (Strings.fdFile);
  45. break;
  46. case OpenMode.Directory:
  47. titleParts.Add (Strings.fdDirectory);
  48. break;
  49. }
  50. return string.Join (' ', titleParts);
  51. }
  52. }