From e3d7d477538bec919957c92498589bf189929a2e Mon Sep 17 00:00:00 2001 From: MonkAlex <3amepob@gmail.com> Date: Fri, 8 Mar 2019 18:43:54 +0400 Subject: [PATCH 1/7] #2355 Ctrl+A hotkey for SelectingItemsControl --- .../Primitives/SelectingItemsControl.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/Avalonia.Controls/Primitives/SelectingItemsControl.cs b/src/Avalonia.Controls/Primitives/SelectingItemsControl.cs index a54bb502c0..f5dcbf9186 100644 --- a/src/Avalonia.Controls/Primitives/SelectingItemsControl.cs +++ b/src/Avalonia.Controls/Primitives/SelectingItemsControl.cs @@ -459,6 +459,23 @@ namespace Avalonia.Controls.Primitives } } + /// + /// Handles 'select all' (Ctrl+A) in . + /// + /// The key events. + protected override void OnKeyDown(KeyEventArgs e) + { + base.OnKeyDown(e); + + if (!e.Handled) + { + if (this.SelectionMode == SelectionMode.Multiple && e.Key == Key.A && e.Modifiers == InputModifiers.Control) + { + SynchronizeItems(SelectedItems, Items?.Cast()); + } + } + } + /// /// Moves the selection in the specified direction relative to the current selection. /// From e38e49e7d0fa69832b198ac375e4d152c39291d0 Mon Sep 17 00:00:00 2001 From: MonkAlex <3amepob@gmail.com> Date: Sat, 9 Mar 2019 23:40:01 +0400 Subject: [PATCH 2/7] #2355 'Select all' for SelectingItemsControl with platform hotkey configuration. --- src/Avalonia.Controls/Primitives/SelectingItemsControl.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Avalonia.Controls/Primitives/SelectingItemsControl.cs b/src/Avalonia.Controls/Primitives/SelectingItemsControl.cs index f5dcbf9186..e868f39fce 100644 --- a/src/Avalonia.Controls/Primitives/SelectingItemsControl.cs +++ b/src/Avalonia.Controls/Primitives/SelectingItemsControl.cs @@ -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; @@ -469,9 +470,13 @@ namespace Avalonia.Controls.Primitives if (!e.Handled) { - if (this.SelectionMode == SelectionMode.Multiple && e.Key == Key.A && e.Modifiers == InputModifiers.Control) + var keymap = AvaloniaLocator.Current.GetService(); + bool Match(List gestures) => gestures.Any(g => g.Matches(e)); + + if (this.SelectionMode == SelectionMode.Multiple && Match(keymap.SelectAll)) { SynchronizeItems(SelectedItems, Items?.Cast()); + e.Handled = true; } } } From 57dcfadf57175590313c136ed8bf8d96e0e8ff8d Mon Sep 17 00:00:00 2001 From: MonkAlex <3amepob@gmail.com> Date: Sun, 10 Mar 2019 00:40:48 +0400 Subject: [PATCH 3/7] #2355 'Select all' support TreeView too, only visible part of tree. --- src/Avalonia.Controls/TreeView.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/Avalonia.Controls/TreeView.cs b/src/Avalonia.Controls/TreeView.cs index db8de49494..141a151bdb 100644 --- a/src/Avalonia.Controls/TreeView.cs +++ b/src/Avalonia.Controls/TreeView.cs @@ -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; @@ -402,6 +403,19 @@ namespace Avalonia.Controls SelectedItem = ElementAt(Items, 0); } } + + if (!e.Handled) + { + var keymap = AvaloniaLocator.Current.GetService(); + bool Match(List gestures) => gestures.Any(g => g.Matches(e)); + + if (this.SelectionMode == SelectionMode.Multiple && Match(keymap.SelectAll)) + { + var allVisibleItems = ItemContainerGenerator.Index.Items.Select(ItemContainerGenerator.Index.ItemFromContainer); + SelectingItemsControl.SynchronizeItems(SelectedItems, allVisibleItems); + e.Handled = true; + } + } } private TreeViewItem GetContainerInDirection( From 33a6ae8215ce81b45d95cd0b6254b969aabd4ee0 Mon Sep 17 00:00:00 2001 From: MonkAlex <3amepob@gmail.com> Date: Sun, 10 Mar 2019 00:55:29 +0400 Subject: [PATCH 4/7] #2355 Direct access for treeview index values when select all. --- src/Avalonia.Controls/Generators/TreeContainerIndex.cs | 5 +++++ src/Avalonia.Controls/TreeView.cs | 3 +-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Avalonia.Controls/Generators/TreeContainerIndex.cs b/src/Avalonia.Controls/Generators/TreeContainerIndex.cs index 24b3fc1f32..0a65dd9ff1 100644 --- a/src/Avalonia.Controls/Generators/TreeContainerIndex.cs +++ b/src/Avalonia.Controls/Generators/TreeContainerIndex.cs @@ -36,6 +36,11 @@ namespace Avalonia.Controls.Generators /// public IEnumerable Items => _containerToItem.Keys; + /// + /// Gets the items of currently materialized containers. + /// + public IEnumerable Objects => _containerToItem.Values; + /// /// Adds an entry to the index. /// diff --git a/src/Avalonia.Controls/TreeView.cs b/src/Avalonia.Controls/TreeView.cs index 141a151bdb..abd9bc4232 100644 --- a/src/Avalonia.Controls/TreeView.cs +++ b/src/Avalonia.Controls/TreeView.cs @@ -411,8 +411,7 @@ namespace Avalonia.Controls if (this.SelectionMode == SelectionMode.Multiple && Match(keymap.SelectAll)) { - var allVisibleItems = ItemContainerGenerator.Index.Items.Select(ItemContainerGenerator.Index.ItemFromContainer); - SelectingItemsControl.SynchronizeItems(SelectedItems, allVisibleItems); + SelectingItemsControl.SynchronizeItems(SelectedItems, ItemContainerGenerator.Index.Objects); e.Handled = true; } } From 235cc660fd2cc97fc3ac922cd8a81f8548e628fa Mon Sep 17 00:00:00 2001 From: MonkAlex <3amepob@gmail.com> Date: Sun, 10 Mar 2019 11:27:51 +0400 Subject: [PATCH 5/7] #1052 Rename TreeContainerIndex.Items to Containers --- src/Avalonia.Controls/Generators/TreeContainerIndex.cs | 2 +- src/Avalonia.Controls/TreeView.cs | 2 +- tests/Avalonia.Controls.UnitTests/TreeViewTests.cs | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Avalonia.Controls/Generators/TreeContainerIndex.cs b/src/Avalonia.Controls/Generators/TreeContainerIndex.cs index 0a65dd9ff1..c831b7985c 100644 --- a/src/Avalonia.Controls/Generators/TreeContainerIndex.cs +++ b/src/Avalonia.Controls/Generators/TreeContainerIndex.cs @@ -34,7 +34,7 @@ namespace Avalonia.Controls.Generators /// /// Gets the currently materialized containers. /// - public IEnumerable Items => _containerToItem.Keys; + public IEnumerable Containers => _containerToItem.Keys; /// /// Gets the items of currently materialized containers. diff --git a/src/Avalonia.Controls/TreeView.cs b/src/Avalonia.Controls/TreeView.cs index abd9bc4232..8236c11983 100644 --- a/src/Avalonia.Controls/TreeView.cs +++ b/src/Avalonia.Controls/TreeView.cs @@ -245,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); } diff --git a/tests/Avalonia.Controls.UnitTests/TreeViewTests.cs b/tests/Avalonia.Controls.UnitTests/TreeViewTests.cs index f65ef7d08e..519872f9f2 100644 --- a/tests/Avalonia.Controls.UnitTests/TreeViewTests.cs +++ b/tests/Avalonia.Controls.UnitTests/TreeViewTests.cs @@ -54,7 +54,7 @@ namespace Avalonia.Controls.UnitTests ApplyTemplates(target); - var items = target.ItemContainerGenerator.Index.Items + var items = target.ItemContainerGenerator.Index.Containers .OfType() .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] From 1c460061cc65a9941412432cc240440dbcc0008f Mon Sep 17 00:00:00 2001 From: MonkAlex <3amepob@gmail.com> Date: Mon, 11 Mar 2019 19:26:56 +0400 Subject: [PATCH 6/7] #2355 Remove useless xmldoc. --- src/Avalonia.Controls/Primitives/SelectingItemsControl.cs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Avalonia.Controls/Primitives/SelectingItemsControl.cs b/src/Avalonia.Controls/Primitives/SelectingItemsControl.cs index e868f39fce..a64dbe0546 100644 --- a/src/Avalonia.Controls/Primitives/SelectingItemsControl.cs +++ b/src/Avalonia.Controls/Primitives/SelectingItemsControl.cs @@ -460,10 +460,6 @@ namespace Avalonia.Controls.Primitives } } - /// - /// Handles 'select all' (Ctrl+A) in . - /// - /// The key events. protected override void OnKeyDown(KeyEventArgs e) { base.OnKeyDown(e); From 1114df5d453838326d493386e2ae9aed2b077b86 Mon Sep 17 00:00:00 2001 From: MonkAlex <3amepob@gmail.com> Date: Mon, 11 Mar 2019 22:42:54 +0400 Subject: [PATCH 7/7] #2356 Small rename Objects to Items --- src/Avalonia.Controls/Generators/TreeContainerIndex.cs | 2 +- src/Avalonia.Controls/TreeView.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Avalonia.Controls/Generators/TreeContainerIndex.cs b/src/Avalonia.Controls/Generators/TreeContainerIndex.cs index c831b7985c..0da84008f6 100644 --- a/src/Avalonia.Controls/Generators/TreeContainerIndex.cs +++ b/src/Avalonia.Controls/Generators/TreeContainerIndex.cs @@ -39,7 +39,7 @@ namespace Avalonia.Controls.Generators /// /// Gets the items of currently materialized containers. /// - public IEnumerable Objects => _containerToItem.Values; + public IEnumerable Items => _containerToItem.Values; /// /// Adds an entry to the index. diff --git a/src/Avalonia.Controls/TreeView.cs b/src/Avalonia.Controls/TreeView.cs index 8236c11983..94989254dc 100644 --- a/src/Avalonia.Controls/TreeView.cs +++ b/src/Avalonia.Controls/TreeView.cs @@ -411,7 +411,7 @@ namespace Avalonia.Controls if (this.SelectionMode == SelectionMode.Multiple && Match(keymap.SelectAll)) { - SelectingItemsControl.SynchronizeItems(SelectedItems, ItemContainerGenerator.Index.Objects); + SelectingItemsControl.SynchronizeItems(SelectedItems, ItemContainerGenerator.Index.Items); e.Handled = true; } }