From 7157e36712e79b9aeea9eb5c3ebb5b14d4c341e0 Mon Sep 17 00:00:00 2001 From: Maciej Winnik Date: Sat, 19 Aug 2023 12:50:03 +0200 Subject: [PATCH 1/4] Add SearchText field --- Terminal.Gui/Views/ComboBox.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Terminal.Gui/Views/ComboBox.cs b/Terminal.Gui/Views/ComboBox.cs index 4fb87d7e5..dfc625f63 100644 --- a/Terminal.Gui/Views/ComboBox.cs +++ b/Terminal.Gui/Views/ComboBox.cs @@ -5,10 +5,10 @@ // Ross Ferguson (ross.c.ferguson@btinternet.com) // +using NStack; using System; using System.Collections; using System.Collections.Generic; -using NStack; namespace Terminal.Gui { /// @@ -725,6 +725,18 @@ namespace Terminal.Gui { } } + /// + /// Current search text + /// + public ustring SearchText { + get { + return search.Text; + } + set { + search.Text = text = value; + } + } + private void SetValue (object text, bool isFromSelectedItem = false) { search.TextChanged -= Search_Changed; From c542b811351c65fd095eec6eeeeb11dac159185f Mon Sep 17 00:00:00 2001 From: Maciej Winnik Date: Sat, 19 Aug 2023 13:08:22 +0200 Subject: [PATCH 2/4] Prevent reseting text search --- Terminal.Gui/Views/ComboBox.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Terminal.Gui/Views/ComboBox.cs b/Terminal.Gui/Views/ComboBox.cs index dfc625f63..896af0dbb 100644 --- a/Terminal.Gui/Views/ComboBox.cs +++ b/Terminal.Gui/Views/ComboBox.cs @@ -869,7 +869,7 @@ namespace Terminal.Gui { OnOpenSelectedItem (); } var rect = listview.ViewToScreen (listview.Bounds); - Reset (SelectedItem > -1); + Reset (keepSearchText: true); listview.Clear (rect); listview.TabStop = false; SuperView?.SendSubviewToBack (this); From 78e2fc01c9fac6c607806929b098a8ed8569ab90 Mon Sep 17 00:00:00 2001 From: Maciej Winnik Date: Sat, 19 Aug 2023 13:13:29 +0200 Subject: [PATCH 3/4] Code cleanup --- Terminal.Gui/Views/ComboBox.cs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/Terminal.Gui/Views/ComboBox.cs b/Terminal.Gui/Views/ComboBox.cs index 896af0dbb..08225e05e 100644 --- a/Terminal.Gui/Views/ComboBox.cs +++ b/Terminal.Gui/Views/ComboBox.cs @@ -39,10 +39,7 @@ namespace Terminal.Gui { private void Initialize (ComboBox container, bool hideDropdownListOnClick) { - if (container == null) - throw new ArgumentNullException ("ComboBox container cannot be null.", nameof (container)); - - this.container = container; + this.container = container ?? throw new ArgumentNullException ("ComboBox container cannot be null.", nameof (container)); HideDropdownListOnClick = hideDropdownListOnClick; } @@ -236,7 +233,7 @@ namespace Terminal.Gui { readonly TextField search; readonly ComboListView listview; bool autoHide = true; - int minimumHeight = 2; + readonly int minimumHeight = 2; /// /// Public constructor @@ -721,7 +718,7 @@ namespace Terminal.Gui { return text; } set { - search.Text = text = value; + SetSearchText (value); } } @@ -733,7 +730,7 @@ namespace Terminal.Gui { return search.Text; } set { - search.Text = text = value; + SetSearchText (value); } } @@ -787,7 +784,7 @@ namespace Terminal.Gui { private void Reset (bool keepSearchText = false) { if (!keepSearchText) { - search.Text = text = ""; + SetSearchText (string.Empty); } ResetSearchSet (); @@ -800,6 +797,11 @@ namespace Terminal.Gui { } } + private void SetSearchText (ustring value) + { + search.Text = text = value; + } + private void ResetSearchSet (bool noCopy = false) { searchset.Clear (); @@ -855,7 +857,7 @@ namespace Terminal.Gui { listview.SetSource (searchset); listview.Clear (); // Ensure list shrinks in Dialog as you type listview.Height = CalculatetHeight (); - this.SuperView?.BringSubviewToFront (this); + SuperView?.BringSubviewToFront (this); } /// From cc88e33ffe99448bb99968861144443643c287d4 Mon Sep 17 00:00:00 2001 From: maciekwin3 Date: Wed, 30 Aug 2023 19:59:14 +0200 Subject: [PATCH 4/4] Fix order of parameters --- Terminal.Gui/Views/ComboBox.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Terminal.Gui/Views/ComboBox.cs b/Terminal.Gui/Views/ComboBox.cs index 08225e05e..0483d82e7 100644 --- a/Terminal.Gui/Views/ComboBox.cs +++ b/Terminal.Gui/Views/ComboBox.cs @@ -39,7 +39,7 @@ namespace Terminal.Gui { private void Initialize (ComboBox container, bool hideDropdownListOnClick) { - this.container = container ?? throw new ArgumentNullException ("ComboBox container cannot be null.", nameof (container)); + this.container = container ?? throw new ArgumentNullException (nameof(container), "ComboBox container cannot be null."); HideDropdownListOnClick = hideDropdownListOnClick; }