diff --git a/src/Views/Controls/Tree.cs b/src/Views/Controls/Tree.cs index 4d4a257a..cb2288bb 100644 --- a/src/Views/Controls/Tree.cs +++ b/src/Views/Controls/Tree.cs @@ -48,12 +48,7 @@ namespace SourceGit.Views.Controls { public List Selected { get; set; - } - - public Tree() { - Selected = new List(); - PreviewMouseDown += OnPreviewMouseDown; - } + } = new List(); public TreeItem FindItem(DependencyObject elem) { if (elem == null) return null; @@ -102,21 +97,18 @@ namespace SourceGit.Views.Controls { } } - private TreeItem FindItemByDataContext(ItemsControl control, object data) { - if (control == null) return null; + protected override void OnPreviewKeyDown(KeyEventArgs e) { + base.OnPreviewKeyDown(e); - for (int i = 0; i < control.Items.Count; i++) { - var child = control.ItemContainerGenerator.ContainerFromIndex(i) as TreeItem; - if (control.Items[i] == data) return child; - - var found = FindItemByDataContext(child, data); - if (found != null) return found; + if (MultiSelection && e.Key == Key.A && Keyboard.Modifiers == ModifierKeys.Control) { + SelectAll(); + e.Handled = true; } - - return null; } - private void OnPreviewMouseDown(object sender, MouseButtonEventArgs e) { + protected override void OnPreviewMouseDown(MouseButtonEventArgs e) { + base.OnPreviewMouseDown(e); + var hit = VisualTreeHelper.HitTest(this, e.GetPosition(this)); if (hit == null || hit.VisualHit == null) return; @@ -157,6 +149,20 @@ namespace SourceGit.Views.Controls { } } + private TreeItem FindItemByDataContext(ItemsControl control, object data) { + if (control == null) return null; + + for (int i = 0; i < control.Items.Count; i++) { + var child = control.ItemContainerGenerator.ContainerFromIndex(i) as TreeItem; + if (control.Items[i] == data) return child; + + var found = FindItemByDataContext(child, data); + if (found != null) return found; + } + + return null; + } + private void AddSelected(TreeItem item, bool removeOthers) { if (removeOthers && Selected.Count > 0) { UnselectAllChildren(this); diff --git a/src/Views/Widgets/WorkingCopyChanges.xaml b/src/Views/Widgets/WorkingCopyChanges.xaml index a3a7f131..86c328c8 100644 --- a/src/Views/Widgets/WorkingCopyChanges.xaml +++ b/src/Views/Widgets/WorkingCopyChanges.xaml @@ -25,22 +25,8 @@ MultiSelection="True" ItemsSource="{Binding ElementName=me, Path=Nodes}" SelectionChanged="OnTreeSelectionChanged" + PreviewKeyDown="OnChangePreviewKeyDown" Visibility="Visible"> - - - - - - - - - - - - - - -