浏览代码

TextFieldAutoComplete demo works cross-platform. Fix list clearing issue.

Ross Ferguson 5 年之前
父节点
当前提交
360e0256b8
共有 2 个文件被更改,包括 23 次插入4 次删除
  1. 10 3
      Example/demo.cs
  2. 13 1
      Terminal.Gui/Views/TextFieldAutoComplete.cs

+ 10 - 3
Example/demo.cs

@@ -415,9 +415,16 @@ static class Demo {
 
 	static void TextFieldAutoCompleteDemo ()
 	{
-		var items = Directory.GetFiles (@"..\..\..\Terminal.Gui", "*.cs", SearchOption.AllDirectories)
-						.Select (x => Path.GetFileName (x)).Where(x => !x.StartsWith(".")).Distinct().OrderBy(x => x).ToList ();
-
+		IList<string> items = new List<string> ();
+		foreach (var dir in new [] { "/etc", @"\windows\System32" }) {
+			if (Directory.Exists (dir)) {
+				items = Directory.GetFiles (dir)
+				.Select (Path.GetFileName)
+				.Where (x => char.IsLetterOrDigit (x [0]))
+				.Distinct ()
+				.OrderBy (x => x).ToList ();
+			}
+		}
 		var list = new TextFieldAutoComplete (0, 0, 36, 7, items);
 		list.Changed += (object sender, ustring text) => { Application.RequestStop (); };
 

+ 13 - 1
Terminal.Gui/Views/TextFieldAutoComplete.cs

@@ -44,7 +44,7 @@ namespace Terminal.Gui {
 		/// <param name="autoHide">Completetion list hidden until start of typing. Use when hosting in Window as opposed to a Dialog</param>
 		public TextFieldAutoComplete(int x, int y, int w, int h, IList<string> source, bool autoHide = false)
 		{
-			listsource = source;
+			listsource = new List<string>(source);
 			isAutoHide = autoHide;
 			searchset = isAutoHide ? new List<string> () : listsource;
 			height = h;
@@ -74,6 +74,18 @@ namespace Terminal.Gui {
 			this.SetFocus(search);
 		}
 
+		public new Dim Width 
+		{
+			get { return base.Width; }
+			set { base.Width = value; }
+		}
+
+		public new Dim Height 
+		{
+			get { return base.Height-1; } 
+			set { base.Width = value+1; }
+		}
+
 		public override bool OnEnter ()
 		{
 			if (!search.HasFocus)