diff --git a/Terminal.Gui/Views/ComboBox.cs b/Terminal.Gui/Views/ComboBox.cs
index eb03b7caa..fd277b6ad 100644
--- a/Terminal.Gui/Views/ComboBox.cs
+++ b/Terminal.Gui/Views/ComboBox.cs
@@ -6,10 +6,11 @@
//
using System;
-using System.Linq;
-using System.Collections.Generic;
-using NStack;
using System.Collections;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Linq;
+using NStack;
namespace Terminal.Gui {
///
@@ -17,6 +18,7 @@ namespace Terminal.Gui {
///
public class ComboBox : View {
+
IListDataSource source;
///
/// Gets or sets the backing this , enabling custom rendering.
@@ -56,9 +58,8 @@ namespace Terminal.Gui {
/// Client code can hook up to this event, it is
/// raised when the selection has been confirmed.
///
- public event EventHandler Changed;
+ public event EventHandler SelectedItemChanged;
- //IList listsource;
IList searchset;
ustring text = "";
TextField search;
@@ -109,10 +110,11 @@ namespace Terminal.Gui {
{
search.TextChanged += Search_Changed;
+ // On resize
LayoutComplete += (LayoutEventArgs a) => {
- search.Width = Frame.Width;
- listview.Width = Frame.Width - 1;
+ search.Width = Bounds.Width;
+ listview.Width = Bounds.Width - 1;
};
listview.SelectedItemChanged += (ListViewItemEventArgs e) => {
@@ -121,7 +123,6 @@ namespace Terminal.Gui {
SetValue ((string)searchset [listview.SelectedItem]);
};
- // TODO: LayoutComplete event breaks cursor up/down. Revert to Application.Loaded
Application.Loaded += (Application.ResizedEventArgs a) => {
// Determine if this view is hosted inside a dialog
for (View view = this.SuperView; view != null; view = view.SuperView) {
@@ -184,7 +185,7 @@ namespace Terminal.Gui {
if (e.MouseEvent.Flags != MouseFlags.Button1Clicked)
return;
- SuperView.SetFocus ((View)search);
+ SuperView.SetFocus (search);
}
///
@@ -198,6 +199,19 @@ namespace Terminal.Gui {
return true;
}
+ ///
+ /// Invokes the SelectedChanged event if it is defined.
+ ///
+ ///
+ public virtual bool OnSelectedChanged ()
+ {
+ // Note: Cannot rely on "listview.SelectedItem != lastSelectedItem" because the list is dynamic.
+ // So we cannot optimize. Ie: Don't call if not changed
+ SelectedItemChanged?.Invoke (this, search.Text);
+
+ return true;
+ }
+
///
public override bool ProcessKey(KeyEvent e)
{
@@ -215,7 +229,7 @@ namespace Terminal.Gui {
SetValue((string)searchset [listview.SelectedItem]);
search.CursorPosition = search.Text.Length;
Search_Changed (search.Text);
- Changed?.Invoke (this, text);
+ OnSelectedChanged ();
searchset.Clear();
listview.Clear ();
@@ -244,7 +258,7 @@ namespace Terminal.Gui {
if (e.Key == Key.Esc) {
this.SetFocus (search);
search.Text = text = "";
- Changed?.Invoke (this, search.Text);
+ OnSelectedChanged ();
return true;
}
@@ -286,7 +300,7 @@ namespace Terminal.Gui {
private void Reset()
{
search.Text = text = "";
- Changed?.Invoke (this, search.Text);
+ OnSelectedChanged();
ResetSearchSet ();