浏览代码

Rename TextViewAutoComplete to ComboBox

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

+ 3 - 3
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<string> items = new List<string> ();
 		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 ()),

+ 10 - 8
Terminal.Gui/Views/TextFieldAutoComplete.cs → Terminal.Gui/Views/ComboBox.cs

@@ -1,7 +1,7 @@
 //
-// TextFieldAutoComplete.cs: TextField with AutoComplete
+// ComboBox.cs: ComboBox control
 //
-// Author:
+// Authors:
 //   Ross Ferguson ([email protected])
 //
 
@@ -12,9 +12,9 @@ using NStack;
 
 namespace Terminal.Gui {
 	/// <summary>
-	/// TextField with AutoComplete
+	/// ComboBox control
 	/// </summary>
-	public class TextFieldAutoComplete : View {
+	public class ComboBox : View {
 		/// <summary>
 		///   Changed event, raised when the selection has been confirmed.
 		/// </summary>
@@ -41,7 +41,7 @@ namespace Terminal.Gui {
 		/// <param name="w">The width</param>
 		/// <param name="h">The height</param>
 		/// <param name="source">Auto completetion source</param>
-		public TextFieldAutoComplete(int x, int y, int w, int h, IList<string> source)
+		public ComboBox(int x, int y, int w, int h, IList<string> source)
 		{
 			listsource = new List<string>(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);