|
1 | 1 | using System;
|
2 |
| - |
| 2 | +using Avalonia; |
3 | 3 | using Avalonia.Controls;
|
| 4 | +using Avalonia.Controls.Shapes; |
4 | 5 | using Avalonia.Input;
|
5 | 6 | using Avalonia.Interactivity;
|
| 7 | +using Avalonia.Media; |
6 | 8 |
|
7 | 9 | namespace SourceGit.Views
|
8 | 10 | {
|
@@ -126,16 +128,31 @@ private void OnRowHeaderDragOver(object sender, DragEventArgs e)
|
126 | 128 | }
|
127 | 129 | }
|
128 | 130 |
|
129 |
| - private void OnChangeRebaseAction(object sender, RoutedEventArgs e) |
| 131 | + private void OnButtonActionClicked(object sender, RoutedEventArgs e) |
130 | 132 | {
|
131 |
| - if (DataContext is ViewModels.InteractiveRebase vm && |
132 |
| - sender is Control |
133 |
| - { |
134 |
| - DataContext: ViewModels.InteractiveRebaseItem item, |
135 |
| - Tag: Models.InteractiveRebaseAction action |
136 |
| - }) |
137 |
| - vm.ChangeAction(item, action); |
| 133 | + if (DataContext is not ViewModels.InteractiveRebase vm) |
| 134 | + return; |
| 135 | + |
| 136 | + if (sender is not Button { DataContext: ViewModels.InteractiveRebaseItem item } button) |
| 137 | + return; |
138 | 138 |
|
| 139 | + var flyout = new MenuFlyout(); |
| 140 | + flyout.Placement = PlacementMode.BottomEdgeAlignedLeft; |
| 141 | + flyout.VerticalOffset = -4; |
| 142 | + |
| 143 | + CreateActionMenuItem(flyout, Brushes.Green, "Pick", "Use this commit", "P", item, Models.InteractiveRebaseAction.Pick); |
| 144 | + CreateActionMenuItem(flyout, Brushes.Orange, "Edit", "Stop for amending", "E", item, Models.InteractiveRebaseAction.Edit); |
| 145 | + CreateActionMenuItem(flyout, Brushes.Orange, "Reword", "Edit the commit message", "R", item, Models.InteractiveRebaseAction.Reword); |
| 146 | + |
| 147 | + if (item.CanSquashOrFixup) |
| 148 | + { |
| 149 | + CreateActionMenuItem(flyout, Brushes.LightGray, "Squash", "Meld into previous commit", "S", item, Models.InteractiveRebaseAction.Squash); |
| 150 | + CreateActionMenuItem(flyout, Brushes.LightGray, "Fixup", "Like 'Squash' but discard message", "F", item, Models.InteractiveRebaseAction.Fixup); |
| 151 | + } |
| 152 | + |
| 153 | + CreateActionMenuItem(flyout, Brushes.Red, "Drop", "Remove commit", "D", item, Models.InteractiveRebaseAction.Drop); |
| 154 | + |
| 155 | + flyout.ShowAt(button); |
139 | 156 | e.Handled = true;
|
140 | 157 | }
|
141 | 158 |
|
@@ -163,5 +180,46 @@ private async void OnStartJobs(object _1, RoutedEventArgs _2)
|
163 | 180 | Running.IsVisible = false;
|
164 | 181 | Close();
|
165 | 182 | }
|
| 183 | + |
| 184 | + private void CreateActionMenuItem(MenuFlyout flyout, IBrush iconBrush, string label, string desc, string hotkey, ViewModels.InteractiveRebaseItem item, Models.InteractiveRebaseAction action) |
| 185 | + { |
| 186 | + var header = new Grid() |
| 187 | + { |
| 188 | + ColumnDefinitions = |
| 189 | + [ |
| 190 | + new ColumnDefinition(64, GridUnitType.Pixel), |
| 191 | + new ColumnDefinition(240, GridUnitType.Pixel), |
| 192 | + ], |
| 193 | + Children = |
| 194 | + { |
| 195 | + new TextBlock() |
| 196 | + { |
| 197 | + [Grid.ColumnProperty] = 0, |
| 198 | + Margin = new Thickness(4, 0), |
| 199 | + Text = label |
| 200 | + }, |
| 201 | + new TextBlock() |
| 202 | + { |
| 203 | + [Grid.ColumnProperty] = 1, |
| 204 | + Text = desc, |
| 205 | + Foreground = this.FindResource("Brush.FG2") as SolidColorBrush, |
| 206 | + } |
| 207 | + } |
| 208 | + }; |
| 209 | + |
| 210 | + var menuItem = new MenuItem(); |
| 211 | + menuItem.Icon = new Ellipse() { Width = 14, Height = 14, Fill = iconBrush }; |
| 212 | + menuItem.Header = header; |
| 213 | + menuItem.Tag = hotkey; |
| 214 | + menuItem.Click += (_, e) => |
| 215 | + { |
| 216 | + if (DataContext is ViewModels.InteractiveRebase vm) |
| 217 | + vm.ChangeAction(item, action); |
| 218 | + |
| 219 | + e.Handled = true; |
| 220 | + }; |
| 221 | + |
| 222 | + flyout.Items.Add(menuItem); |
| 223 | + } |
166 | 224 | }
|
167 | 225 | }
|
0 commit comments