2
0

FileDialog.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. //
  2. // FileDialog.cs: File system dialogs for open and save
  3. //
  4. using System;
  5. using System.Collections.Generic;
  6. using NStack;
  7. namespace Terminal.Gui {
  8. public class FileDialog : Dialog {
  9. Button prompt;
  10. Label nameFieldLabel, message;
  11. public FileDialog (ustring title, ustring prompt, ustring nameFieldLabel, ustring message) : base (title, Driver.Cols - 20, Driver.Rows - 6, null)
  12. {
  13. this.prompt = new Button (prompt);
  14. AddButton (this.prompt);
  15. this.nameFieldLabel = new Label (Rect.Empty, nameFieldLabel);
  16. this.message = new Label (Rect.Empty, message);
  17. }
  18. /// <summary>
  19. /// Gets or sets the prompt label for the button displayed to the user
  20. /// </summary>
  21. /// <value>The prompt.</value>
  22. public ustring Prompt {
  23. get => prompt.Text;
  24. set {
  25. prompt.Text = value;
  26. }
  27. }
  28. /// <summary>
  29. /// Gets or sets the name field label.
  30. /// </summary>
  31. /// <value>The name field label.</value>
  32. public ustring NameFieldLabel {
  33. get => nameFieldLabel.Text;
  34. set {
  35. nameFieldLabel.Text = value;
  36. }
  37. }
  38. /// <summary>
  39. /// Gets or sets the message displayed to the user, defaults to nothing
  40. /// </summary>
  41. /// <value>The message.</value>
  42. public ustring Message { get; set; }
  43. /// <summary>
  44. /// Gets or sets a value indicating whether this <see cref="T:Terminal.Gui.FileDialog"/> can create directories.
  45. /// </summary>
  46. /// <value><c>true</c> if can create directories; otherwise, <c>false</c>.</value>
  47. public bool CanCreateDirectories { get; set; }
  48. /// <summary>
  49. /// Gets or sets a value indicating whether this <see cref="T:Terminal.Gui.FileDialog"/> is extension hidden.
  50. /// </summary>
  51. /// <value><c>true</c> if is extension hidden; otherwise, <c>false</c>.</value>
  52. public bool IsExtensionHidden { get; set; }
  53. /// <summary>
  54. /// Gets or sets the directory path for this panel
  55. /// </summary>
  56. /// <value>The directory path.</value>
  57. public ustring DirectoryPath { get; set; }
  58. /// <summary>
  59. /// The array of filename extensions allowed, or null if all file extensions are allowed.
  60. /// </summary>
  61. /// <value>The allowed file types.</value>
  62. public ustring [] AllowedFileTypes { get; set; }
  63. /// <summary>
  64. /// Gets or sets a value indicating whether this <see cref="T:Terminal.Gui.FileDialog"/> allows the file to be saved with a different extension
  65. /// </summary>
  66. /// <value><c>true</c> if allows other file types; otherwise, <c>false</c>.</value>
  67. public bool AllowsOtherFileTypes { get; set; }
  68. /// <summary>
  69. /// The File path that is currently shown on the panel
  70. /// </summary>
  71. /// <value>The absolute file path for the file path entered.</value>
  72. public ustring FilePath { get; set; }
  73. }
  74. public class SaveDialog : FileDialog {
  75. public SaveDialog (ustring title, ustring message) : base (title, "Save", "Save as:", message)
  76. {
  77. }
  78. }
  79. public class OpenDialog : FileDialog {
  80. public OpenDialog (ustring title, ustring message) : base (title, "Open", "Open", message)
  81. {
  82. }
  83. /// <summary>
  84. /// Gets or sets a value indicating whether this <see cref="T:Terminal.Gui.OpenDialog"/> can choose files.
  85. /// </summary>
  86. /// <value><c>true</c> if can choose files; otherwise, <c>false</c>.</value>
  87. public bool CanChooseFiles { get; set; }
  88. /// <summary>
  89. /// Gets or sets a value indicating whether this <see cref="T:Terminal.Gui.OpenDialog"/> can choose directories.
  90. /// </summary>
  91. /// <value><c>true</c> if can choose directories; otherwise, <c>false</c>.</value>
  92. public bool CanChooseDirectories { get; set; }
  93. /// <summary>
  94. /// Gets or sets a value indicating whether this <see cref="T:Terminal.Gui.OpenDialog"/> allows multiple selection.
  95. /// </summary>
  96. /// <value><c>true</c> if allows multiple selection; otherwise, <c>false</c>.</value>
  97. public bool AllowsMultipleSelection { get; set; }
  98. /// <summary>
  99. /// Gets the file paths selected
  100. /// </summary>
  101. /// <value>The file paths.</value>
  102. public IReadOnlyList<ustring> FilePaths { get; }
  103. }
  104. }