Browse Source

Add nullable annotations.

pull/3470/head
Steven Kirk 6 years ago
parent
commit
01a1945201
  1. 47
      src/Avalonia.Controls/SelectionModelChangeSet.cs
  2. 12
      src/Avalonia.Controls/SelectionModelSelectionChangedEventArgs.cs

47
src/Avalonia.Controls/SelectionModelChangeSet.cs

@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
#nullable enable
namespace Avalonia.Controls
{
internal class SelectionModelChangeSet
@ -31,11 +33,11 @@ namespace Avalonia.Controls
_changes,
selectedCount,
GetSelectedIndexAt);
var deselectedItems = new SelectedItems<object, SelectionNodeOperation>(
var deselectedItems = new SelectedItems<object?, SelectionNodeOperation>(
_changes,
deselectedCount,
GetDeselectedItemAt);
var selectedItems = new SelectedItems<object, SelectionNodeOperation>(
var selectedItems = new SelectedItems<object?, SelectionNodeOperation>(
_changes,
selectedCount,
GetSelectedItemAt);
@ -52,7 +54,7 @@ namespace Avalonia.Controls
int index)
{
static int GetCount(SelectionNodeOperation info) => info.DeselectedCount;
static List<IndexRange> GetRanges(SelectionNodeOperation info) => info.DeselectedRanges;
static List<IndexRange>? GetRanges(SelectionNodeOperation info) => info.DeselectedRanges;
return GetIndexAt(infos, index, GetCount, GetRanges);
}
@ -61,25 +63,25 @@ namespace Avalonia.Controls
int index)
{
static int GetCount(SelectionNodeOperation info) => info.SelectedCount;
static List<IndexRange> GetRanges(SelectionNodeOperation info) => info.SelectedRanges;
static List<IndexRange>? GetRanges(SelectionNodeOperation info) => info.SelectedRanges;
return GetIndexAt(infos, index, GetCount, GetRanges);
}
private object GetDeselectedItemAt(
private object? GetDeselectedItemAt(
List<SelectionNodeOperation> infos,
int index)
{
static int GetCount(SelectionNodeOperation info) => info.DeselectedCount;
static List<IndexRange> GetRanges(SelectionNodeOperation info) => info.DeselectedRanges;
static List<IndexRange>? GetRanges(SelectionNodeOperation info) => info.DeselectedRanges;
return GetItemAt(infos, index, GetCount, GetRanges);
}
private object GetSelectedItemAt(
private object? GetSelectedItemAt(
List<SelectionNodeOperation> infos,
int index)
{
static int GetCount(SelectionNodeOperation info) => info.SelectedCount;
static List<IndexRange> GetRanges(SelectionNodeOperation info) => info.SelectedRanges;
static List<IndexRange>? GetRanges(SelectionNodeOperation info) => info.SelectedRanges;
return GetItemAt(infos, index, GetCount, GetRanges);
}
@ -87,7 +89,7 @@ namespace Avalonia.Controls
List<SelectionNodeOperation> infos,
int index,
Func<SelectionNodeOperation, int> getCount,
Func<SelectionNodeOperation, List<IndexRange>> getRanges)
Func<SelectionNodeOperation, List<IndexRange>?> getRanges)
{
var currentIndex = 0;
IndexPath path = default;
@ -109,14 +111,14 @@ namespace Avalonia.Controls
return path;
}
private object GetItemAt(
private object? GetItemAt(
List<SelectionNodeOperation> infos,
int index,
Func<SelectionNodeOperation, int> getCount,
Func<SelectionNodeOperation, List<IndexRange>> getRanges)
Func<SelectionNodeOperation, List<IndexRange>?> getRanges)
{
var currentIndex = 0;
object item = null;
object? item = null;
foreach (var info in infos)
{
@ -125,7 +127,7 @@ namespace Avalonia.Controls
if (index >= currentIndex && index < currentIndex + currentCount)
{
int targetIndex = GetIndexAt(getRanges(info), index - currentIndex);
item = info.Items.GetAt(targetIndex);
item = info.Items?.GetAt(targetIndex);
break;
}
@ -135,20 +137,23 @@ namespace Avalonia.Controls
return item;
}
private int GetIndexAt(List<IndexRange> ranges, int index)
private int GetIndexAt(List<IndexRange>? ranges, int index)
{
var currentIndex = 0;
foreach (var range in ranges)
if (ranges != null)
{
var currentCount = (range.End - range.Begin) + 1;
if (index >= currentIndex && index < currentIndex + currentCount)
foreach (var range in ranges)
{
return range.Begin + (index - currentIndex);
}
var currentCount = (range.End - range.Begin) + 1;
currentIndex += currentCount;
if (index >= currentIndex && index < currentIndex + currentCount)
{
return range.Begin + (index - currentIndex);
}
currentIndex += currentCount;
}
}
throw new IndexOutOfRangeException();

12
src/Avalonia.Controls/SelectionModelSelectionChangedEventArgs.cs

@ -15,13 +15,13 @@ namespace Avalonia.Controls
public SelectionModelSelectionChangedEventArgs(
IReadOnlyList<IndexPath>? deselectedIndices,
IReadOnlyList<IndexPath>? selectedIndices,
IReadOnlyList<object>? deselectedItems,
IReadOnlyList<object>? selectedItems)
IReadOnlyList<object?>? deselectedItems,
IReadOnlyList<object?>? selectedItems)
{
DeselectedIndices = deselectedIndices ?? Array.Empty<IndexPath>();
SelectedIndices = selectedIndices ?? Array.Empty<IndexPath>();
DeselectedItems = deselectedItems ?? Array.Empty<object>();
SelectedItems= selectedItems ?? Array.Empty<object>();
DeselectedItems = deselectedItems ?? Array.Empty<object?>();
SelectedItems= selectedItems ?? Array.Empty<object?>();
}
/// <summary>
@ -37,11 +37,11 @@ namespace Avalonia.Controls
/// <summary>
/// Gets the items that were removed from the selection.
/// </summary>
public IReadOnlyList<object> DeselectedItems { get; }
public IReadOnlyList<object?> DeselectedItems { get; }
/// <summary>
/// Gets the items that were added to the selection.
/// </summary>
public IReadOnlyList<object> SelectedItems { get; }
public IReadOnlyList<object?> SelectedItems { get; }
}
}

Loading…
Cancel
Save