mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-06-01 17:24:59 +00:00
refactor<WorkingCopyChanges>: use PreviewKeyDown instead of RoutedUICommand for staging/unstaging hot keys
This commit is contained in:
parent
208af69ea1
commit
62c182f5ca
3 changed files with 35 additions and 41 deletions
|
@ -48,12 +48,7 @@ namespace SourceGit.Views.Controls {
|
|||
public List<object> Selected {
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public Tree() {
|
||||
Selected = new List<object>();
|
||||
PreviewMouseDown += OnPreviewMouseDown;
|
||||
}
|
||||
} = new List<object>();
|
||||
|
||||
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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue