|
| 1 | +using System; |
| 2 | + |
1 | 3 | using Avalonia.Controls; |
2 | 4 | using Avalonia.Input; |
3 | 5 | using Avalonia.Interactivity; |
4 | 6 |
|
5 | 7 | namespace SourceGit.Views |
6 | 8 | { |
| 9 | + public class InteractiveRebaseListBox : ListBox |
| 10 | + { |
| 11 | + protected override Type StyleKeyOverride => typeof(ListBox); |
| 12 | + |
| 13 | + /// <summary> |
| 14 | + /// Prevent ListBox handle the arrow keys. |
| 15 | + /// </summary> |
| 16 | + /// <param name="e"></param> |
| 17 | + protected override void OnKeyDown(KeyEventArgs e) |
| 18 | + { |
| 19 | + var vm = DataContext as ViewModels.InteractiveRebase; |
| 20 | + if (vm == null) |
| 21 | + return; |
| 22 | + |
| 23 | + var item = vm.SelectedItem; |
| 24 | + if (item == null) |
| 25 | + { |
| 26 | + base.OnKeyDown(e); |
| 27 | + return; |
| 28 | + } |
| 29 | + |
| 30 | + if (e.Key == Key.P) |
| 31 | + { |
| 32 | + item.SetAction(Models.InteractiveRebaseAction.Pick); |
| 33 | + e.Handled = true; |
| 34 | + } |
| 35 | + else if (e.Key == Key.E) |
| 36 | + { |
| 37 | + item.SetAction(Models.InteractiveRebaseAction.Edit); |
| 38 | + e.Handled = true; |
| 39 | + } |
| 40 | + else if (e.Key == Key.R) |
| 41 | + { |
| 42 | + item.SetAction(Models.InteractiveRebaseAction.Reword); |
| 43 | + e.Handled = true; |
| 44 | + } |
| 45 | + else if (e.Key == Key.S) |
| 46 | + { |
| 47 | + item.SetAction(Models.InteractiveRebaseAction.Squash); |
| 48 | + e.Handled = true; |
| 49 | + } |
| 50 | + else if (e.Key == Key.F) |
| 51 | + { |
| 52 | + item.SetAction(Models.InteractiveRebaseAction.Fixup); |
| 53 | + e.Handled = true; |
| 54 | + } |
| 55 | + else if (e.Key == Key.D) |
| 56 | + { |
| 57 | + item.SetAction(Models.InteractiveRebaseAction.Drop); |
| 58 | + e.Handled = true; |
| 59 | + } |
| 60 | + else if (e.KeyModifiers == KeyModifiers.Alt && e.Key == Key.Up) |
| 61 | + { |
| 62 | + vm.MoveItemUp(item); |
| 63 | + e.Handled = true; |
| 64 | + } |
| 65 | + else if (e.KeyModifiers == KeyModifiers.Alt && e.Key == Key.Down) |
| 66 | + { |
| 67 | + vm.MoveItemDown(item); |
| 68 | + e.Handled = true; |
| 69 | + } |
| 70 | + else |
| 71 | + { |
| 72 | + base.OnKeyDown(e); |
| 73 | + } |
| 74 | + } |
| 75 | + } |
| 76 | + |
7 | 77 | public partial class InteractiveRebase : ChromelessWindow |
8 | 78 | { |
9 | 79 | public InteractiveRebase() |
@@ -89,26 +159,6 @@ private void OnMoveItemDown(object sender, RoutedEventArgs e) |
89 | 159 | } |
90 | 160 | } |
91 | 161 |
|
92 | | - private void OnItemsListBoxKeyDown(object sender, KeyEventArgs e) |
93 | | - { |
94 | | - var item = (sender as ListBox)?.SelectedItem as ViewModels.InteractiveRebaseItem; |
95 | | - if (item == null) |
96 | | - return; |
97 | | - |
98 | | - if (e.Key == Key.P) |
99 | | - item.SetAction(Models.InteractiveRebaseAction.Pick); |
100 | | - else if (e.Key == Key.E) |
101 | | - item.SetAction(Models.InteractiveRebaseAction.Edit); |
102 | | - else if (e.Key == Key.R) |
103 | | - item.SetAction(Models.InteractiveRebaseAction.Reword); |
104 | | - else if (e.Key == Key.S) |
105 | | - item.SetAction(Models.InteractiveRebaseAction.Squash); |
106 | | - else if (e.Key == Key.F) |
107 | | - item.SetAction(Models.InteractiveRebaseAction.Fixup); |
108 | | - else if (e.Key == Key.D) |
109 | | - item.SetAction(Models.InteractiveRebaseAction.Drop); |
110 | | - } |
111 | | - |
112 | 162 | private async void StartJobs(object _1, RoutedEventArgs _2) |
113 | 163 | { |
114 | 164 | var vm = DataContext as ViewModels.InteractiveRebase; |
|
0 commit comments