public void Clicking_WithShiftModifier_UpDirection_Should_Select_Range_Of_Items() { var tree = CreateTestTreeData(); var target = new TreeView { Template = CreateTreeViewTemplate(), Items = tree, SelectionMode = SelectionMode.Multiple }; var visualRoot = new TestRoot(); visualRoot.Child = target; CreateNodeDataTemplate(target); ApplyTemplates(target); var rootNode = tree[0]; var from = rootNode.Children.Last(); var to = rootNode.Children[0]; var fromContainer = (TreeViewItem)target.ItemContainerGenerator.Index.ContainerFromItem(from); var toContainer = (TreeViewItem)target.ItemContainerGenerator.Index.ContainerFromItem(to); TreeTestHelper.ClickContainer(fromContainer, InputModifiers.None); Assert.True(fromContainer.IsSelected); TreeTestHelper.ClickContainer(toContainer, InputModifiers.Shift); TreeTestHelper.AssertChildrenSelected(target, rootNode); }
public void Pressing_SelectAll_Gesture_Should_Select_All_Nodes() { using (UnitTestApplication.Start()) { var tree = CreateTestTreeData(); var target = new TreeView { Template = CreateTreeViewTemplate(), Items = tree, SelectionMode = SelectionMode.Multiple }; var visualRoot = new TestRoot(); visualRoot.Child = target; CreateNodeDataTemplate(target); ApplyTemplates(target); var rootNode = tree[0]; var keymap = AvaloniaLocator.Current.GetService <PlatformHotkeyConfiguration>(); var selectAllGesture = keymap.SelectAll.First(); var keyEvent = new KeyEventArgs { RoutedEvent = InputElement.KeyDownEvent, Key = selectAllGesture.Key, Modifiers = selectAllGesture.Modifiers }; target.RaiseEvent(keyEvent); TreeTestHelper.AssertChildrenSelected(target, rootNode); } }
public void Clicking_First_Item_Of_SelectedItems_Should_Select_Only_It() { var tree = CreateTestTreeData(); var target = new TreeView { Template = CreateTreeViewTemplate(), Items = tree, SelectionMode = SelectionMode.Multiple }; var visualRoot = new TestRoot(); visualRoot.Child = target; CreateNodeDataTemplate(target); ApplyTemplates(target); var rootNode = tree[0]; var from = rootNode.Children.Last(); var to = rootNode.Children[0]; var fromContainer = (TreeViewItem)target.ItemContainerGenerator.Index.ContainerFromItem(from); var toContainer = (TreeViewItem)target.ItemContainerGenerator.Index.ContainerFromItem(to); TreeTestHelper.ClickContainer(fromContainer, InputModifiers.None); TreeTestHelper.ClickContainer(toContainer, InputModifiers.Shift); TreeTestHelper.AssertChildrenSelected(target, rootNode); TreeTestHelper.ClickContainer(fromContainer, InputModifiers.None); Assert.True(fromContainer.IsSelected); foreach (var child in rootNode.Children) { if (child == from) { continue; } var container = (TreeViewItem)target.ItemContainerGenerator.Index.ContainerFromItem(child); Assert.False(container.IsSelected); } }
public void Pressing_SelectAll_Gesture_With_Upward_Range_Selected_Should_Select_All_Nodes() { using (UnitTestApplication.Start()) { var tree = CreateTestTreeData(); var target = new TreeView { Template = CreateTreeViewTemplate(), Items = tree, SelectionMode = SelectionMode.Multiple }; var visualRoot = new TestRoot(); visualRoot.Child = target; CreateNodeDataTemplate(target); ApplyTemplates(target); var rootNode = tree[0]; var from = rootNode.Children.Last(); var to = rootNode.Children[0]; var fromContainer = (TreeViewItem)target.ItemContainerGenerator.Index.ContainerFromItem(from); var toContainer = (TreeViewItem)target.ItemContainerGenerator.Index.ContainerFromItem(to); TreeTestHelper.ClickContainer(fromContainer, InputModifiers.None); TreeTestHelper.ClickContainer(toContainer, InputModifiers.Shift); var keymap = AvaloniaLocator.Current.GetService <PlatformHotkeyConfiguration>(); var selectAllGesture = keymap.SelectAll.First(); var keyEvent = new KeyEventArgs { RoutedEvent = InputElement.KeyDownEvent, Key = selectAllGesture.Key, Modifiers = selectAllGesture.Modifiers }; target.RaiseEvent(keyEvent); TreeTestHelper.AssertChildrenSelected(target, rootNode); } }
public void Clicking_WithControlModifier_Selected_Item_Should_Deselect_And_Remove_From_SelectedItems() { var tree = CreateTestTreeData(); var target = new TreeView { Template = CreateTreeViewTemplate(), Items = tree, SelectionMode = SelectionMode.Multiple }; var visualRoot = new TestRoot(); visualRoot.Child = target; CreateNodeDataTemplate(target); ApplyTemplates(target); var rootNode = tree[0]; var item1 = rootNode.Children[0]; var item2 = rootNode.Children.Last(); var item1Container = (TreeViewItem)target.ItemContainerGenerator.Index.ContainerFromItem(item1); var item2Container = (TreeViewItem)target.ItemContainerGenerator.Index.ContainerFromItem(item2); TreeTestHelper.ClickContainer(item1Container, InputModifiers.Control); Assert.True(item1Container.IsSelected); TreeTestHelper.ClickContainer(item2Container, InputModifiers.Control); Assert.True(item2Container.IsSelected); Assert.Equal(new[] { item1, item2 }, target.SelectedItems.OfType <Node>()); TreeTestHelper.ClickContainer(item1Container, InputModifiers.Control); Assert.False(item1Container.IsSelected); Assert.DoesNotContain(item1, target.SelectedItems.OfType <Node>()); }