refactor<WorkingCopyChanges>: use PreviewKeyDown instead of RoutedUICommand for staging/unstaging hot keys

This commit is contained in:
leo 2021-07-14 14:54:44 +08:00
parent 208af69ea1
commit 62c182f5ca
3 changed files with 35 additions and 41 deletions

View file

@ -25,22 +25,8 @@
MultiSelection="True"
ItemsSource="{Binding ElementName=me, Path=Nodes}"
SelectionChanged="OnTreeSelectionChanged"
PreviewKeyDown="OnChangePreviewKeyDown"
Visibility="Visible">
<TreeView.Resources>
<RoutedUICommand x:Key="SelectWholeTreeCommand" Text="SelectWholeTree"/>
<RoutedUICommand x:Key="StageChangeCommand" Text="StageChange"/>
</TreeView.Resources>
<TreeView.InputBindings>
<KeyBinding Key="A" Modifiers="Ctrl" Command="{StaticResource SelectWholeTreeCommand}"/>
<KeyBinding Key="Space" Command="{StaticResource StageChangeCommand}"/>
</TreeView.InputBindings>
<TreeView.CommandBindings>
<CommandBinding Command="{StaticResource SelectWholeTreeCommand}" Executed="SelectWholeTree"/>
<CommandBinding Command="{StaticResource StageChangeCommand}" Executed="StageChange"/>
</TreeView.CommandBindings>
<controls:Tree.ItemContainerStyle>
<Style TargetType="{x:Type controls:TreeItem}" BasedOn="{StaticResource Style.TreeItem}">
<Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}"/>
@ -95,6 +81,7 @@
SelectionUnit="FullRow"
SelectionChanged="OnListSelectionChanged"
SizeChanged="OnListSizeChanged"
PreviewKeyDown="OnChangePreviewKeyDown"
ItemsSource="{Binding ElementName=me, Path=Changes}"
RowStyle="{StaticResource Style.DataGridRow.Change}"
Visibility="Collapsed">
@ -123,6 +110,7 @@
SelectionUnit="FullRow"
SelectionChanged="OnGridSelectionChanged"
SizeChanged="OnGridSizeChanged"
PreviewKeyDown="OnChangePreviewKeyDown"
ItemsSource="{Binding ElementName=me, Path=Changes}"
RowStyle="{StaticResource Style.DataGridRow.Change}"
Visibility="Collapsed">

View file

@ -686,15 +686,15 @@ namespace SourceGit.Views.Widgets {
#endregion
#region EVENTS
private void SelectWholeTree(object sender, ExecutedRoutedEventArgs e) {
modeTree.SelectAll();
}
private void StageChange(object sender, ExecutedRoutedEventArgs e) {
if (!IsUnstaged) {
UnstageSelected();
} else {
StageSelected();
private void OnChangePreviewKeyDown(object sender, KeyEventArgs e) {
if (e.Key == Key.Space && Keyboard.Modifiers == ModifierKeys.None) {
if (!IsUnstaged) {
UnstageSelected();
} else {
StageSelected();
}
e.Handled = true;
}
}