diff --git a/Example/demo.cs b/Example/demo.cs index 23bd9e850..98dd80af7 100644 --- a/Example/demo.cs +++ b/Example/demo.cs @@ -413,7 +413,7 @@ static class Demo { MessageBox.Query (60, 10, "Selected Animals", result == "" ? "No animals selected" : result, "Ok"); } - static void TextFieldAutoCompleteDemo () + static void ComboBoxDemo () { IList items = new List (); foreach (var dir in new [] { "/etc", @"\windows\System32" }) { @@ -425,7 +425,7 @@ static class Demo { .OrderBy (x => x).ToList (); } } - var list = new TextFieldAutoComplete (0, 0, 36, 7, items); + var list = new ComboBox (0, 0, 36, 7, items); list.Changed += (object sender, ustring text) => { Application.RequestStop (); }; var d = new Dialog ("Select source file", 40, 12) { list }; @@ -563,7 +563,7 @@ static class Demo { new MenuBarItem ("_List Demos", new MenuItem [] { new MenuItem ("Select _Multiple Items", "", () => ListSelectionDemo (true)), new MenuItem ("Select _Single Item", "", () => ListSelectionDemo (false)), - new MenuItem ("Search Single Item", "", TextFieldAutoCompleteDemo) + new MenuItem ("Search Single Item", "", ComboBoxDemo) }), new MenuBarItem ("A_ssorted", new MenuItem [] { new MenuItem ("_Show text alignments", "", () => ShowTextAlignments ()), diff --git a/Terminal.Gui/Views/TextFieldAutoComplete.cs b/Terminal.Gui/Views/ComboBox.cs similarity index 92% rename from Terminal.Gui/Views/TextFieldAutoComplete.cs rename to Terminal.Gui/Views/ComboBox.cs index 8bee85a93..b04d6dbc3 100644 --- a/Terminal.Gui/Views/TextFieldAutoComplete.cs +++ b/Terminal.Gui/Views/ComboBox.cs @@ -1,7 +1,7 @@ // -// TextFieldAutoComplete.cs: TextField with AutoComplete +// ComboBox.cs: ComboBox control // -// Author: +// Authors: // Ross Ferguson (ross.c.ferguson@btinternet.com) // @@ -12,9 +12,9 @@ using NStack; namespace Terminal.Gui { /// - /// TextField with AutoComplete + /// ComboBox control /// - public class TextFieldAutoComplete : View { + public class ComboBox : View { /// /// Changed event, raised when the selection has been confirmed. /// @@ -41,7 +41,7 @@ namespace Terminal.Gui { /// The width /// The height /// Auto completetion source - public TextFieldAutoComplete(int x, int y, int w, int h, IList source) + public ComboBox(int x, int y, int w, int h, IList source) { listsource = new List(source); height = h; @@ -55,7 +55,8 @@ namespace Terminal.Gui { ColorScheme = Colors.Dialog }; listview.SelectedChanged += () => { - SetValue (searchset [listview.SelectedItem]); + if(searchset.Count > 0) + SetValue (searchset [listview.SelectedItem]); }; Application.OnLoad += () => { @@ -90,6 +91,7 @@ namespace Terminal.Gui { return true; } + public override bool ProcessKey(KeyEvent e) { if (e.Key == Key.Tab) @@ -117,13 +119,13 @@ namespace Terminal.Gui { return true; } - if (e.Key == Key.CursorDown && search.HasFocus && listview.SelectedItem == 0) { // jump to list + if (e.Key == Key.CursorDown && search.HasFocus && listview.SelectedItem == 0 && searchset.Count > 0) { // jump to list this.SetFocus (listview); SetValue (searchset [listview.SelectedItem]); return true; } - if (e.Key == Key.CursorUp && listview.HasFocus && listview.SelectedItem == 0) // jump back to search + if (e.Key == Key.CursorUp && listview.HasFocus && listview.SelectedItem == 0 && searchset.Count > 0) // jump back to search { search.CursorPosition = search.Text.Length; this.SetFocus (search);