FileDialog.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761
  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 NStack;
  14. using System.IO;
  15. using System.Linq;
  16. namespace Terminal.Gui {
  17. internal class DirListView : View {
  18. int top, selected;
  19. DirectoryInfo dirInfo;
  20. List<(string, bool, bool)> infos;
  21. internal bool canChooseFiles = true;
  22. internal bool canChooseDirectories = false;
  23. internal bool allowsMultipleSelection = false;
  24. FileDialog host;
  25. public DirListView (FileDialog host)
  26. {
  27. infos = new List<(string, bool, bool)> ();
  28. CanFocus = true;
  29. this.host = host;
  30. }
  31. bool IsAllowed (FileSystemInfo fsi)
  32. {
  33. if (fsi.Attributes.HasFlag (FileAttributes.Directory))
  34. return true;
  35. if (allowedFileTypes == null)
  36. return true;
  37. foreach (var ft in allowedFileTypes)
  38. if (fsi.Name.EndsWith (ft))
  39. return true;
  40. return false;
  41. }
  42. internal bool Reload (ustring value = null)
  43. {
  44. bool valid = false;
  45. try {
  46. dirInfo = new DirectoryInfo (value == null ? directory.ToString () : value.ToString ());
  47. infos = (from x in dirInfo.GetFileSystemInfos ()
  48. where IsAllowed (x) && (!canChooseFiles ? x.Attributes.HasFlag (FileAttributes.Directory) : true)
  49. orderby (!x.Attributes.HasFlag (FileAttributes.Directory)) + x.Name
  50. select (x.Name, x.Attributes.HasFlag (FileAttributes.Directory), false)).ToList ();
  51. infos.Insert (0, ("..", true, false));
  52. top = 0;
  53. selected = 0;
  54. valid = true;
  55. } catch (Exception ex) {
  56. switch (ex) {
  57. case DirectoryNotFoundException _:
  58. case ArgumentException _:
  59. dirInfo = null;
  60. infos.Clear ();
  61. valid = true;
  62. break;
  63. default:
  64. valid = false;
  65. break;
  66. }
  67. } finally {
  68. if (valid) {
  69. SetNeedsDisplay ();
  70. }
  71. }
  72. return valid;
  73. }
  74. ustring directory;
  75. public ustring Directory {
  76. get => directory;
  77. set {
  78. if (directory == value) {
  79. return;
  80. }
  81. if (Reload (value)) {
  82. directory = value;
  83. }
  84. }
  85. }
  86. public override void PositionCursor ()
  87. {
  88. Move (0, selected - top);
  89. }
  90. int lastSelected;
  91. bool shiftOnWheel;
  92. public override bool MouseEvent (MouseEvent me)
  93. {
  94. if ((me.Flags & (MouseFlags.Button1Clicked | MouseFlags.Button1DoubleClicked |
  95. MouseFlags.WheeledUp | MouseFlags.WheeledDown)) == 0)
  96. return false;
  97. if (!HasFocus)
  98. SetFocus ();
  99. if (infos == null)
  100. return false;
  101. if (me.Y + top >= infos.Count)
  102. return true;
  103. int lastSelectedCopy = shiftOnWheel ? lastSelected : selected;
  104. switch (me.Flags) {
  105. case MouseFlags.Button1Clicked:
  106. SetSelected (me);
  107. SelectionChanged ();
  108. SetNeedsDisplay ();
  109. break;
  110. case MouseFlags.Button1DoubleClicked:
  111. SetSelected (me);
  112. if (ExecuteSelection ()) {
  113. host.canceled = false;
  114. Application.RequestStop ();
  115. }
  116. return true;
  117. case MouseFlags.Button1Clicked | MouseFlags.ButtonShift:
  118. SetSelected (me);
  119. if (shiftOnWheel)
  120. lastSelected = lastSelectedCopy;
  121. shiftOnWheel = false;
  122. PerformMultipleSelection (lastSelected);
  123. return true;
  124. case MouseFlags.Button1Clicked | MouseFlags.ButtonCtrl:
  125. SetSelected (me);
  126. PerformMultipleSelection ();
  127. return true;
  128. case MouseFlags.WheeledUp:
  129. SetSelected (me);
  130. selected = lastSelected;
  131. MoveUp ();
  132. return true;
  133. case MouseFlags.WheeledDown:
  134. SetSelected (me);
  135. selected = lastSelected;
  136. MoveDown ();
  137. return true;
  138. case MouseFlags.WheeledUp | MouseFlags.ButtonShift:
  139. SetSelected (me);
  140. selected = lastSelected;
  141. lastSelected = lastSelectedCopy;
  142. shiftOnWheel = true;
  143. MoveUp ();
  144. return true;
  145. case MouseFlags.WheeledDown | MouseFlags.ButtonShift:
  146. SetSelected (me);
  147. selected = lastSelected;
  148. lastSelected = lastSelectedCopy;
  149. shiftOnWheel = true;
  150. MoveDown ();
  151. return true;
  152. }
  153. return true;
  154. }
  155. void SetSelected (MouseEvent me)
  156. {
  157. lastSelected = selected;
  158. selected = top + me.Y;
  159. }
  160. void DrawString (int line, string str)
  161. {
  162. var f = Frame;
  163. var width = f.Width;
  164. var ustr = ustring.Make (str);
  165. Move (allowsMultipleSelection ? 3 : 2, line);
  166. int byteLen = ustr.Length;
  167. int used = allowsMultipleSelection ? 2 : 1;
  168. for (int i = 0; i < byteLen;) {
  169. (var rune, var size) = Utf8.DecodeRune (ustr, i, i - byteLen);
  170. var count = Rune.ColumnWidth (rune);
  171. if (used + count >= width)
  172. break;
  173. Driver.AddRune (rune);
  174. used += count;
  175. i += size;
  176. }
  177. for (; used < width - 1; used++) {
  178. Driver.AddRune (' ');
  179. }
  180. }
  181. public override void Redraw (Rect bounds)
  182. {
  183. var current = ColorScheme.Focus;
  184. Driver.SetAttribute (current);
  185. Move (0, 0);
  186. var f = Frame;
  187. var item = top;
  188. bool focused = HasFocus;
  189. var width = bounds.Width;
  190. for (int row = 0; row < f.Height; row++, item++) {
  191. bool isSelected = item == selected;
  192. Move (0, row);
  193. var newcolor = focused ? (isSelected ? ColorScheme.HotNormal : ColorScheme.Focus) : ColorScheme.Focus;
  194. if (newcolor != current) {
  195. Driver.SetAttribute (newcolor);
  196. current = newcolor;
  197. }
  198. if (item >= infos.Count) {
  199. for (int c = 0; c < f.Width; c++)
  200. Driver.AddRune (' ');
  201. continue;
  202. }
  203. var fi = infos [item];
  204. Driver.AddRune (isSelected ? '>' : ' ');
  205. if (allowsMultipleSelection)
  206. Driver.AddRune (fi.Item3 ? '*' : ' ');
  207. if (fi.Item2)
  208. Driver.AddRune ('/');
  209. else
  210. Driver.AddRune (' ');
  211. DrawString (row, fi.Item1);
  212. }
  213. }
  214. public Action<(string, bool)> SelectedChanged { get; set; }
  215. public Action<ustring> DirectoryChanged { get; set; }
  216. public Action<ustring> FileChanged { get; set; }
  217. void SelectionChanged ()
  218. {
  219. if (FilePaths.Count > 0)
  220. FileChanged?.Invoke (string.Join (", ", GetFilesName (FilePaths)));
  221. else
  222. FileChanged?.Invoke (infos [selected].Item2 ? "" : Path.GetFileName (infos [selected].Item1));
  223. if (SelectedChanged != null) {
  224. var sel = infos [selected];
  225. SelectedChanged ((sel.Item1, sel.Item2));
  226. }
  227. }
  228. List<string> GetFilesName (IReadOnlyList<string> files)
  229. {
  230. List<string> filesName = new List<string> ();
  231. foreach (var file in files) {
  232. filesName.Add (Path.GetFileName (file));
  233. }
  234. return filesName;
  235. }
  236. public override bool ProcessKey (KeyEvent keyEvent)
  237. {
  238. switch (keyEvent.Key) {
  239. case Key.CursorUp:
  240. case Key.ControlP:
  241. MoveUp ();
  242. return true;
  243. case Key.CursorDown:
  244. case Key.ControlN:
  245. MoveDown ();
  246. return true;
  247. case Key.ControlV:
  248. case Key.PageDown:
  249. var n = (selected + Frame.Height);
  250. if (n > infos.Count)
  251. n = infos.Count - 1;
  252. if (n != selected) {
  253. selected = n;
  254. if (infos.Count >= Frame.Height)
  255. top = selected;
  256. else
  257. top = 0;
  258. SelectionChanged ();
  259. SetNeedsDisplay ();
  260. }
  261. return true;
  262. case Key.Enter:
  263. if (ExecuteSelection ())
  264. return false;
  265. else
  266. return true;
  267. case Key.PageUp:
  268. n = (selected - Frame.Height);
  269. if (n < 0)
  270. n = 0;
  271. if (n != selected) {
  272. selected = n;
  273. top = selected;
  274. SelectionChanged ();
  275. SetNeedsDisplay ();
  276. }
  277. return true;
  278. case Key.Space:
  279. case Key.ControlT:
  280. PerformMultipleSelection ();
  281. return true;
  282. case Key.Home:
  283. MoveFirst ();
  284. return true;
  285. case Key.End:
  286. MoveLast ();
  287. return true;
  288. }
  289. return base.ProcessKey (keyEvent);
  290. }
  291. void MoveLast ()
  292. {
  293. selected = infos.Count - 1;
  294. top = infos.Count () - 1;
  295. SelectionChanged ();
  296. SetNeedsDisplay ();
  297. }
  298. void MoveFirst ()
  299. {
  300. selected = 0;
  301. top = 0;
  302. SelectionChanged ();
  303. SetNeedsDisplay ();
  304. }
  305. void MoveDown ()
  306. {
  307. if (selected + 1 < infos.Count) {
  308. selected++;
  309. if (selected >= top + Frame.Height)
  310. top++;
  311. SelectionChanged ();
  312. SetNeedsDisplay ();
  313. }
  314. }
  315. void MoveUp ()
  316. {
  317. if (selected > 0) {
  318. selected--;
  319. if (selected < top)
  320. top = selected;
  321. SelectionChanged ();
  322. SetNeedsDisplay ();
  323. }
  324. }
  325. internal bool ExecuteSelection (bool isPrompt = false)
  326. {
  327. if (infos.Count == 0) {
  328. return false;
  329. }
  330. var isDir = infos [selected].Item2;
  331. if (isDir) {
  332. if (!isPrompt) {
  333. Directory = Path.GetFullPath (Path.Combine (Path.GetFullPath (Directory.ToString ()), infos [selected].Item1));
  334. DirectoryChanged?.Invoke (Directory);
  335. }
  336. } else {
  337. FileChanged?.Invoke (infos [selected].Item1);
  338. if (canChooseFiles) {
  339. // Ensures that at least one file is selected.
  340. if (FilePaths.Count == 0)
  341. PerformMultipleSelection ();
  342. // Let the OK handler take it over
  343. return true;
  344. }
  345. // No files allowed, do not let the default handler take it.
  346. }
  347. return false;
  348. }
  349. void PerformMultipleSelection (int? firstSelected = null)
  350. {
  351. if (allowsMultipleSelection) {
  352. int first = Math.Min (firstSelected ?? selected, selected);
  353. int last = Math.Max (selected, firstSelected ?? selected);
  354. for (int i = first; i <= last; i++) {
  355. if ((canChooseFiles && infos [i].Item2 == false) ||
  356. (canChooseDirectories && infos [i].Item2 &&
  357. infos [i].Item1 != "..")) {
  358. infos [i] = (infos [i].Item1, infos [i].Item2, !infos [i].Item3);
  359. }
  360. }
  361. SelectionChanged ();
  362. SetNeedsDisplay ();
  363. }
  364. }
  365. string [] allowedFileTypes;
  366. public string [] AllowedFileTypes {
  367. get => allowedFileTypes;
  368. set {
  369. allowedFileTypes = value;
  370. Reload ();
  371. }
  372. }
  373. public string MakePath (string relativePath)
  374. {
  375. return Path.GetFullPath (Path.Combine (Directory.ToString (), relativePath));
  376. }
  377. public IReadOnlyList<string> FilePaths {
  378. get {
  379. if (allowsMultipleSelection) {
  380. var res = new List<string> ();
  381. foreach (var item in infos)
  382. if (item.Item3)
  383. res.Add (MakePath (item.Item1));
  384. return res;
  385. } else {
  386. if (infos.Count == 0) {
  387. return null;
  388. }
  389. if (infos [selected].Item2) {
  390. if (canChooseDirectories)
  391. return new List<string> () { MakePath (infos [selected].Item1) };
  392. return Array.Empty<string> ();
  393. } else {
  394. if (canChooseFiles)
  395. return new List<string> () { MakePath (infos [selected].Item1) };
  396. return Array.Empty<string> ();
  397. }
  398. }
  399. }
  400. }
  401. }
  402. /// <summary>
  403. /// Base class for the <see cref="OpenDialog"/> and the <see cref="SaveDialog"/>
  404. /// </summary>
  405. public class FileDialog : Dialog {
  406. Button prompt, cancel;
  407. Label nameFieldLabel, message, dirLabel;
  408. TextField dirEntry, nameEntry;
  409. internal DirListView dirListView;
  410. /// <summary>
  411. /// Initializes a new <see cref="FileDialog"/>.
  412. /// </summary>
  413. public FileDialog () : this (title: string.Empty, prompt: string.Empty, nameFieldLabel: string.Empty, message: string.Empty) { }
  414. /// <summary>
  415. /// Initializes a new instance of <see cref="FileDialog"/>
  416. /// </summary>
  417. /// <param name="title">The title.</param>
  418. /// <param name="prompt">The prompt.</param>
  419. /// <param name="nameFieldLabel">The name field label.</param>
  420. /// <param name="message">The message.</param>
  421. public FileDialog (ustring title, ustring prompt, ustring nameFieldLabel, ustring message) : base (title)//, Driver.Cols - 20, Driver.Rows - 5, null)
  422. {
  423. this.message = new Label (message) {
  424. X = 1,
  425. Y = 0,
  426. };
  427. Add (this.message);
  428. var msgLines = TextFormatter.MaxLines (message, Driver.Cols - 20);
  429. dirLabel = new Label ("Directory: ") {
  430. X = 1,
  431. Y = 1 + msgLines
  432. };
  433. dirEntry = new TextField ("") {
  434. X = Pos.Right (dirLabel),
  435. Y = 1 + msgLines,
  436. Width = Dim.Fill () - 1,
  437. TextChanged = (e) => {
  438. DirectoryPath = dirEntry.Text;
  439. }
  440. };
  441. Add (dirLabel, dirEntry);
  442. this.nameFieldLabel = new Label ("Open: ") {
  443. X = 6,
  444. Y = 3 + msgLines,
  445. };
  446. nameEntry = new TextField ("") {
  447. X = Pos.Left (dirEntry),
  448. Y = 3 + msgLines,
  449. Width = Dim.Fill () - 1
  450. };
  451. Add (this.nameFieldLabel, nameEntry);
  452. dirListView = new DirListView (this) {
  453. X = 1,
  454. Y = 3 + msgLines + 2,
  455. Width = Dim.Fill () - 1,
  456. Height = Dim.Fill () - 2,
  457. };
  458. DirectoryPath = Path.GetFullPath (Environment.CurrentDirectory);
  459. Add (dirListView);
  460. dirListView.DirectoryChanged = (dir) => dirEntry.Text = dir;
  461. dirListView.FileChanged = (file) => nameEntry.Text = file;
  462. this.cancel = new Button ("Cancel");
  463. this.cancel.Clicked += () => {
  464. canceled = true;
  465. Application.RequestStop ();
  466. };
  467. AddButton (cancel);
  468. this.prompt = new Button (prompt) {
  469. IsDefault = true,
  470. };
  471. this.prompt.Clicked += () => {
  472. dirListView.ExecuteSelection (true);
  473. canceled = false;
  474. Application.RequestStop ();
  475. };
  476. AddButton (this.prompt);
  477. Width = Dim.Percent (80);
  478. Height = Dim.Percent (80);
  479. // On success, we will set this to false.
  480. canceled = true;
  481. }
  482. internal bool canceled;
  483. ///<inheritdoc/>
  484. public override void WillPresent ()
  485. {
  486. base.WillPresent ();
  487. //SetFocus (nameEntry);
  488. }
  489. //protected override void Dispose (bool disposing)
  490. //{
  491. // message?.Dispose ();
  492. // base.Dispose (disposing);
  493. //}
  494. /// <summary>
  495. /// Gets or sets the prompt label for the <see cref="Button"/> displayed to the user
  496. /// </summary>
  497. /// <value>The prompt.</value>
  498. public ustring Prompt {
  499. get => prompt.Text;
  500. set {
  501. prompt.Text = value;
  502. }
  503. }
  504. /// <summary>
  505. /// Gets or sets the name field label.
  506. /// </summary>
  507. /// <value>The name field label.</value>
  508. public ustring NameFieldLabel {
  509. get => nameFieldLabel.Text;
  510. set {
  511. nameFieldLabel.Text = value;
  512. }
  513. }
  514. /// <summary>
  515. /// Gets or sets the message displayed to the user, defaults to nothing
  516. /// </summary>
  517. /// <value>The message.</value>
  518. public ustring Message {
  519. get => message.Text;
  520. set {
  521. message.Text = value;
  522. }
  523. }
  524. /// <summary>
  525. /// Gets or sets a value indicating whether this <see cref="FileDialog"/> can create directories.
  526. /// </summary>
  527. /// <value><c>true</c> if can create directories; otherwise, <c>false</c>.</value>
  528. public bool CanCreateDirectories { get; set; }
  529. /// <summary>
  530. /// Gets or sets a value indicating whether this <see cref="FileDialog"/> is extension hidden.
  531. /// </summary>
  532. /// <value><c>true</c> if is extension hidden; otherwise, <c>false</c>.</value>
  533. public bool IsExtensionHidden { get; set; }
  534. /// <summary>
  535. /// Gets or sets the directory path for this panel
  536. /// </summary>
  537. /// <value>The directory path.</value>
  538. public ustring DirectoryPath {
  539. get => dirEntry.Text;
  540. set {
  541. dirEntry.Text = value;
  542. dirListView.Directory = value;
  543. }
  544. }
  545. /// <summary>
  546. /// The array of filename extensions allowed, or null if all file extensions are allowed.
  547. /// </summary>
  548. /// <value>The allowed file types.</value>
  549. public string [] AllowedFileTypes {
  550. get => dirListView.AllowedFileTypes;
  551. set => dirListView.AllowedFileTypes = value;
  552. }
  553. /// <summary>
  554. /// Gets or sets a value indicating whether this <see cref="FileDialog"/> allows the file to be saved with a different extension
  555. /// </summary>
  556. /// <value><c>true</c> if allows other file types; otherwise, <c>false</c>.</value>
  557. public bool AllowsOtherFileTypes { get; set; }
  558. /// <summary>
  559. /// The File path that is currently shown on the panel
  560. /// </summary>
  561. /// <value>The absolute file path for the file path entered.</value>
  562. public ustring FilePath {
  563. get => dirListView.MakePath (nameEntry.Text.ToString ());
  564. set {
  565. nameEntry.Text = Path.GetFileName (value.ToString ());
  566. }
  567. }
  568. /// <summary>
  569. /// Check if the dialog was or not canceled.
  570. /// </summary>
  571. public bool Canceled { get => canceled; }
  572. }
  573. /// <summary>
  574. /// The <see cref="SaveDialog"/> provides an interactive dialog box for users to pick a file to
  575. /// save.
  576. /// </summary>
  577. /// <remarks>
  578. /// <para>
  579. /// To use, create an instance of <see cref="SaveDialog"/>, and pass it to
  580. /// <see cref="Application.Run()"/>. This will run the dialog modally,
  581. /// and when this returns, the <see cref="FileName"/>property will contain the selected file name or
  582. /// null if the user canceled.
  583. /// </para>
  584. /// </remarks>
  585. public class SaveDialog : FileDialog {
  586. /// <summary>
  587. /// Initializes a new <see cref="SaveDialog"/>.
  588. /// </summary>
  589. public SaveDialog () : this (title: string.Empty, message: string.Empty) { }
  590. /// <summary>
  591. /// Initializes a new <see cref="SaveDialog"/>.
  592. /// </summary>
  593. /// <param name="title">The title.</param>
  594. /// <param name="message">The message.</param>
  595. public SaveDialog (ustring title, ustring message) : base (title, prompt: "Save", nameFieldLabel: "Save as:", message: message) { }
  596. /// <summary>
  597. /// Gets the name of the file the user selected for saving, or null
  598. /// if the user canceled the <see cref="SaveDialog"/>.
  599. /// </summary>
  600. /// <value>The name of the file.</value>
  601. public ustring FileName {
  602. get {
  603. if (canceled)
  604. return null;
  605. return Path.GetFileName (FilePath.ToString ());
  606. }
  607. }
  608. }
  609. /// <summary>
  610. /// The <see cref="OpenDialog"/>provides an interactive dialog box for users to select files or directories.
  611. /// </summary>
  612. /// <remarks>
  613. /// <para>
  614. /// The open dialog can be used to select files for opening, it can be configured to allow
  615. /// multiple items to be selected (based on the AllowsMultipleSelection) variable and
  616. /// you can control whether this should allow files or directories to be selected.
  617. /// </para>
  618. /// <para>
  619. /// To use, create an instance of <see cref="OpenDialog"/>, and pass it to
  620. /// <see cref="Application.Run()"/>. This will run the dialog modally,
  621. /// and when this returns, the list of filds will be available on the <see cref="FilePaths"/> property.
  622. /// </para>
  623. /// <para>
  624. /// To select more than one file, users can use the spacebar, or control-t.
  625. /// </para>
  626. /// </remarks>
  627. public class OpenDialog : FileDialog {
  628. /// <summary>
  629. /// Initializes a new <see cref="OpenDialog"/>.
  630. /// </summary>
  631. public OpenDialog () : this (title: string.Empty, message: string.Empty) { }
  632. /// <summary>
  633. /// Initializes a new <see cref="OpenDialog"/>.
  634. /// </summary>
  635. /// <param name="title"></param>
  636. /// <param name="message"></param>
  637. public OpenDialog (ustring title, ustring message) : base (title, prompt: "Open", nameFieldLabel: "Open", message: message)
  638. {
  639. }
  640. /// <summary>
  641. /// Gets or sets a value indicating whether this <see cref="Terminal.Gui.OpenDialog"/> can choose files.
  642. /// </summary>
  643. /// <value><c>true</c> if can choose files; otherwise, <c>false</c>. Defaults to <c>true</c></value>
  644. public bool CanChooseFiles {
  645. get => dirListView.canChooseFiles;
  646. set {
  647. dirListView.canChooseFiles = value;
  648. dirListView.Reload ();
  649. }
  650. }
  651. /// <summary>
  652. /// Gets or sets a value indicating whether this <see cref="OpenDialog"/> can choose directories.
  653. /// </summary>
  654. /// <value><c>true</c> if can choose directories; otherwise, <c>false</c> defaults to <c>false</c>.</value>
  655. public bool CanChooseDirectories {
  656. get => dirListView.canChooseDirectories;
  657. set {
  658. dirListView.canChooseDirectories = value;
  659. dirListView.Reload ();
  660. }
  661. }
  662. /// <summary>
  663. /// Gets or sets a value indicating whether this <see cref="OpenDialog"/> allows multiple selection.
  664. /// </summary>
  665. /// <value><c>true</c> if allows multiple selection; otherwise, <c>false</c>, defaults to false.</value>
  666. public bool AllowsMultipleSelection {
  667. get => dirListView.allowsMultipleSelection;
  668. set {
  669. dirListView.allowsMultipleSelection = value;
  670. dirListView.Reload ();
  671. }
  672. }
  673. /// <summary>
  674. /// Returns the selected files, or an empty list if nothing has been selected
  675. /// </summary>
  676. /// <value>The file paths.</value>
  677. public IReadOnlyList<string> FilePaths {
  678. get => dirListView.FilePaths;
  679. }
  680. }
  681. }