Merge pull request #2825 from MaciekWin3/combobox-search-text

Fixes #2824. Add SearchText property to ComboBox
This commit is contained in:
Tig
2023-09-29 11:18:02 -06:00
committed by GitHub

View File

@@ -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 {
/// <summary>
@@ -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 (nameof(container), "ComboBox container cannot be null.");
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;
/// <summary>
/// Public constructor
@@ -721,7 +718,19 @@ namespace Terminal.Gui {
return text;
}
set {
search.Text = text = value;
SetSearchText (value);
}
}
/// <summary>
/// Current search text
/// </summary>
public ustring SearchText {
get {
return search.Text;
}
set {
SetSearchText (value);
}
}
@@ -775,7 +784,7 @@ namespace Terminal.Gui {
private void Reset (bool keepSearchText = false)
{
if (!keepSearchText) {
search.Text = text = "";
SetSearchText (string.Empty);
}
ResetSearchSet ();
@@ -788,6 +797,11 @@ namespace Terminal.Gui {
}
}
private void SetSearchText (ustring value)
{
search.Text = text = value;
}
private void ResetSearchSet (bool noCopy = false)
{
searchset.Clear ();
@@ -843,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);
}
/// <summary>
@@ -857,7 +871,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);