Browse Source
Merge branch 'master' into perf-fixes
pull/2361/head
Steven Kirk
8 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with
41 additions and
5 deletions
-
src/Avalonia.Controls/Generators/TreeContainerIndex.cs
-
src/Avalonia.Controls/Primitives/SelectingItemsControl.cs
-
src/Avalonia.Controls/TreeView.cs
-
tests/Avalonia.Controls.UnitTests/TreeViewTests.cs
|
|
|
@ -34,7 +34,12 @@ namespace Avalonia.Controls.Generators |
|
|
|
/// <summary>
|
|
|
|
/// Gets the currently materialized containers.
|
|
|
|
/// </summary>
|
|
|
|
public IEnumerable<IControl> Items => _containerToItem.Keys; |
|
|
|
public IEnumerable<IControl> Containers => _containerToItem.Keys; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets the items of currently materialized containers.
|
|
|
|
/// </summary>
|
|
|
|
public IEnumerable<object> Items => _containerToItem.Values; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Adds an entry to the index.
|
|
|
|
|
|
|
|
@ -10,6 +10,7 @@ using Avalonia.Collections; |
|
|
|
using Avalonia.Controls.Generators; |
|
|
|
using Avalonia.Data; |
|
|
|
using Avalonia.Input; |
|
|
|
using Avalonia.Input.Platform; |
|
|
|
using Avalonia.Interactivity; |
|
|
|
using Avalonia.Styling; |
|
|
|
using Avalonia.VisualTree; |
|
|
|
@ -459,6 +460,23 @@ namespace Avalonia.Controls.Primitives |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
protected override void OnKeyDown(KeyEventArgs e) |
|
|
|
{ |
|
|
|
base.OnKeyDown(e); |
|
|
|
|
|
|
|
if (!e.Handled) |
|
|
|
{ |
|
|
|
var keymap = AvaloniaLocator.Current.GetService<PlatformHotkeyConfiguration>(); |
|
|
|
bool Match(List<KeyGesture> gestures) => gestures.Any(g => g.Matches(e)); |
|
|
|
|
|
|
|
if (this.SelectionMode == SelectionMode.Multiple && Match(keymap.SelectAll)) |
|
|
|
{ |
|
|
|
SynchronizeItems(SelectedItems, Items?.Cast<object>()); |
|
|
|
e.Handled = true; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Moves the selection in the specified direction relative to the current selection.
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
@ -10,6 +10,7 @@ using Avalonia.Collections; |
|
|
|
using Avalonia.Controls.Generators; |
|
|
|
using Avalonia.Controls.Primitives; |
|
|
|
using Avalonia.Input; |
|
|
|
using Avalonia.Input.Platform; |
|
|
|
using Avalonia.Interactivity; |
|
|
|
using Avalonia.Threading; |
|
|
|
using Avalonia.VisualTree; |
|
|
|
@ -244,7 +245,7 @@ namespace Avalonia.Controls |
|
|
|
break; |
|
|
|
case NotifyCollectionChangedAction.Reset: |
|
|
|
|
|
|
|
foreach (IControl container in ItemContainerGenerator.Index.Items) |
|
|
|
foreach (IControl container in ItemContainerGenerator.Index.Containers) |
|
|
|
{ |
|
|
|
MarkContainerSelected(container, false); |
|
|
|
} |
|
|
|
@ -402,6 +403,18 @@ namespace Avalonia.Controls |
|
|
|
SelectedItem = ElementAt(Items, 0); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (!e.Handled) |
|
|
|
{ |
|
|
|
var keymap = AvaloniaLocator.Current.GetService<PlatformHotkeyConfiguration>(); |
|
|
|
bool Match(List<KeyGesture> gestures) => gestures.Any(g => g.Matches(e)); |
|
|
|
|
|
|
|
if (this.SelectionMode == SelectionMode.Multiple && Match(keymap.SelectAll)) |
|
|
|
{ |
|
|
|
SelectingItemsControl.SynchronizeItems(SelectedItems, ItemContainerGenerator.Index.Items); |
|
|
|
e.Handled = true; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private TreeViewItem GetContainerInDirection( |
|
|
|
|
|
|
|
@ -54,7 +54,7 @@ namespace Avalonia.Controls.UnitTests |
|
|
|
|
|
|
|
ApplyTemplates(target); |
|
|
|
|
|
|
|
var items = target.ItemContainerGenerator.Index.Items |
|
|
|
var items = target.ItemContainerGenerator.Index.Containers |
|
|
|
.OfType<TreeViewItem>() |
|
|
|
.ToList(); |
|
|
|
|
|
|
|
@ -463,11 +463,11 @@ namespace Avalonia.Controls.UnitTests |
|
|
|
CreateNodeDataTemplate(target); |
|
|
|
ApplyTemplates(target); |
|
|
|
|
|
|
|
Assert.Equal(5, target.ItemContainerGenerator.Index.Items.Count()); |
|
|
|
Assert.Equal(5, target.ItemContainerGenerator.Index.Containers.Count()); |
|
|
|
|
|
|
|
tree[0].Children.RemoveAt(1); |
|
|
|
|
|
|
|
Assert.Equal(3, target.ItemContainerGenerator.Index.Items.Count()); |
|
|
|
Assert.Equal(3, target.ItemContainerGenerator.Index.Containers.Count()); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
|