Browse Source

Merge pull request #815 from BDisp/filedialog-volume

Fixes #813. It's now possible choose the volume through the directory TextField.
Charlie Kindel 5 years ago
parent
commit
5b38613d59
1 changed files with 19 additions and 10 deletions
  1. 19 10
      Terminal.Gui/Windows/FileDialog.cs

+ 19 - 10
Terminal.Gui/Windows/FileDialog.cs

@@ -46,15 +46,21 @@ namespace Terminal.Gui {
 
 		internal void Reload ()
 		{
-			dirInfo = new DirectoryInfo (directory.ToString ());
-			infos = (from x in dirInfo.GetFileSystemInfos ()
-				 where IsAllowed (x)
-				 orderby (!x.Attributes.HasFlag (FileAttributes.Directory)) + x.Name
-				 select (x.Name, x.Attributes.HasFlag (FileAttributes.Directory), false)).ToList ();
-			infos.Insert (0, ("..", true, false));
-			top = 0;
-			selected = 0;
-			SetNeedsDisplay ();
+			try {
+				dirInfo = new DirectoryInfo (directory.ToString ());
+				infos = (from x in dirInfo.GetFileSystemInfos ()
+					 where IsAllowed (x)
+					 orderby (!x.Attributes.HasFlag (FileAttributes.Directory)) + x.Name
+					 select (x.Name, x.Attributes.HasFlag (FileAttributes.Directory), false)).ToList ();
+				infos.Insert (0, ("..", true, false));
+				top = 0;
+				selected = 0;
+			} catch (Exception) {
+				dirInfo = null;
+				infos.Clear ();
+			} finally {
+				SetNeedsDisplay ();
+			}
 		}
 
 		ustring directory;
@@ -454,7 +460,10 @@ namespace Terminal.Gui {
 			dirEntry = new TextField ("") {
 				X = Pos.Right (dirLabel),
 				Y = 1 + msgLines,
-				Width = Dim.Fill () - 1
+				Width = Dim.Fill () - 1,
+				TextChanged = (e) => {
+					DirectoryPath = dirEntry.Text;
+				}
 			};
 			Add (dirLabel, dirEntry);