From 360e0256b8e56055e0f371cdf6b0ee6f39c51d08 Mon Sep 17 00:00:00 2001 From: Ross Ferguson Date: Mon, 18 May 2020 06:42:23 +0100 Subject: [PATCH] TextFieldAutoComplete demo works cross-platform. Fix list clearing issue. --- Example/demo.cs | 13 ++++++++++--- Terminal.Gui/Views/TextFieldAutoComplete.cs | 14 +++++++++++++- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/Example/demo.cs b/Example/demo.cs index a85813d4e..23bd9e850 100644 --- a/Example/demo.cs +++ b/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 items = new List (); + 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 (); }; diff --git a/Terminal.Gui/Views/TextFieldAutoComplete.cs b/Terminal.Gui/Views/TextFieldAutoComplete.cs index 7aef2c8d6..042f8c31d 100644 --- a/Terminal.Gui/Views/TextFieldAutoComplete.cs +++ b/Terminal.Gui/Views/TextFieldAutoComplete.cs @@ -44,7 +44,7 @@ namespace Terminal.Gui { /// Completetion list hidden until start of typing. Use when hosting in Window as opposed to a Dialog public TextFieldAutoComplete(int x, int y, int w, int h, IList source, bool autoHide = false) { - listsource = source; + listsource = new List(source); isAutoHide = autoHide; searchset = isAutoHide ? new List () : 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)