|
@@ -162,8 +162,6 @@ namespace Terminal.Gui {
|
|
public IListDataSource Source {
|
|
public IListDataSource Source {
|
|
get => source;
|
|
get => source;
|
|
set {
|
|
set {
|
|
- if (value == null)
|
|
|
|
- throw new ArgumentNullException ("value");
|
|
|
|
source = value;
|
|
source = value;
|
|
top = 0;
|
|
top = 0;
|
|
selected = 0;
|
|
selected = 0;
|
|
@@ -178,10 +176,12 @@ namespace Terminal.Gui {
|
|
public void SetSource (IList source)
|
|
public void SetSource (IList source)
|
|
{
|
|
{
|
|
if (source == null)
|
|
if (source == null)
|
|
- throw new ArgumentNullException (nameof (source));
|
|
|
|
- Source = MakeWrapper (source);
|
|
|
|
- ((ListWrapper) Source).Container = this;
|
|
|
|
- ((ListWrapper) Source).Driver = Driver;
|
|
|
|
|
|
+ Source = null;
|
|
|
|
+ else {
|
|
|
|
+ Source = MakeWrapper (source);
|
|
|
|
+ ((ListWrapper)Source).Container = this;
|
|
|
|
+ ((ListWrapper)Source).Driver = Driver;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
bool allowsMarking;
|
|
bool allowsMarking;
|
|
@@ -204,6 +204,9 @@ namespace Terminal.Gui {
|
|
public int TopItem {
|
|
public int TopItem {
|
|
get => top;
|
|
get => top;
|
|
set {
|
|
set {
|
|
|
|
+ if (source == null)
|
|
|
|
+ return;
|
|
|
|
+
|
|
if (top < 0 || top >= source.Count)
|
|
if (top < 0 || top >= source.Count)
|
|
throw new ArgumentException ("value");
|
|
throw new ArgumentException ("value");
|
|
top = value;
|
|
top = value;
|
|
@@ -218,6 +221,8 @@ namespace Terminal.Gui {
|
|
public int SelectedItem {
|
|
public int SelectedItem {
|
|
get => selected;
|
|
get => selected;
|
|
set {
|
|
set {
|
|
|
|
+ if (source == null)
|
|
|
|
+ return;
|
|
if (selected < 0 || selected >= source.Count)
|
|
if (selected < 0 || selected >= source.Count)
|
|
throw new ArgumentException ("value");
|
|
throw new ArgumentException ("value");
|
|
selected = value;
|
|
selected = value;
|
|
@@ -250,12 +255,17 @@ namespace Terminal.Gui {
|
|
/// <param name="source">IListDataSource object that provides a mechanism to render the data. The number of elements on the collection should not change, if you must change, set the "Source" property to reset the internal settings of the ListView.</param>
|
|
/// <param name="source">IListDataSource object that provides a mechanism to render the data. The number of elements on the collection should not change, if you must change, set the "Source" property to reset the internal settings of the ListView.</param>
|
|
public ListView (IListDataSource source) : base ()
|
|
public ListView (IListDataSource source) : base ()
|
|
{
|
|
{
|
|
- if (source == null)
|
|
|
|
- throw new ArgumentNullException (nameof (source));
|
|
|
|
Source = source;
|
|
Source = source;
|
|
CanFocus = true;
|
|
CanFocus = true;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// Initializes a new instance of the <see cref="T:Terminal.Gui.ListView"/> class. You must set the Source property for this to show something.
|
|
|
|
+ /// </summary>
|
|
|
|
+ public ListView () : base ()
|
|
|
|
+ {
|
|
|
|
+ }
|
|
|
|
+
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Initializes a new ListView that will display the contents of the object implementing the IList interface with an absolute position.
|
|
/// Initializes a new ListView that will display the contents of the object implementing the IList interface with an absolute position.
|
|
/// </summary>
|
|
/// </summary>
|
|
@@ -274,8 +284,6 @@ namespace Terminal.Gui {
|
|
/// <param name="source">IListDataSource object that provides a mechanism to render the data. The number of elements on the collection should not change, if you must change, set the "Source" property to reset the internal settings of the ListView.</param>
|
|
/// <param name="source">IListDataSource object that provides a mechanism to render the data. The number of elements on the collection should not change, if you must change, set the "Source" property to reset the internal settings of the ListView.</param>
|
|
public ListView (Rect rect, IListDataSource source) : base (rect)
|
|
public ListView (Rect rect, IListDataSource source) : base (rect)
|
|
{
|
|
{
|
|
- if (source == null)
|
|
|
|
- throw new ArgumentNullException (nameof (source));
|
|
|
|
Source = source;
|
|
Source = source;
|
|
CanFocus = true;
|
|
CanFocus = true;
|
|
}
|
|
}
|
|
@@ -302,8 +310,8 @@ namespace Terminal.Gui {
|
|
current = newcolor;
|
|
current = newcolor;
|
|
}
|
|
}
|
|
|
|
|
|
- if (item >= source.Count) {
|
|
|
|
- Move(0, row);
|
|
|
|
|
|
+ if (source == null || item >= source.Count) {
|
|
|
|
+ Move(0, row);
|
|
for (int c = 0; c < f.Width; c++)
|
|
for (int c = 0; c < f.Width; c++)
|
|
Driver.AddRune(' ');
|
|
Driver.AddRune(' ');
|
|
} else {
|
|
} else {
|
|
@@ -324,6 +332,9 @@ namespace Terminal.Gui {
|
|
/// <param name="kb">Keyboard event.</param>
|
|
/// <param name="kb">Keyboard event.</param>
|
|
public override bool ProcessKey (KeyEvent kb)
|
|
public override bool ProcessKey (KeyEvent kb)
|
|
{
|
|
{
|
|
|
|
+ if (source == null)
|
|
|
|
+ return base.ProcessKey (kb);
|
|
|
|
+
|
|
switch (kb.Key) {
|
|
switch (kb.Key) {
|
|
case Key.CursorUp:
|
|
case Key.CursorUp:
|
|
case Key.ControlP:
|
|
case Key.ControlP:
|
|
@@ -398,6 +409,9 @@ namespace Terminal.Gui {
|
|
if (!HasFocus)
|
|
if (!HasFocus)
|
|
SuperView.SetFocus (this);
|
|
SuperView.SetFocus (this);
|
|
|
|
|
|
|
|
+ if (source == null)
|
|
|
|
+ return false;
|
|
|
|
+
|
|
if (me.Y + top >= source.Count)
|
|
if (me.Y + top >= source.Count)
|
|
return true;
|
|
return true;
|
|
|
|
|