feature: simple interactive rebase support (#188)

* Only allow to start interactive rebase from merged commit in current branch
* The order of commits in the interactive rebase window is as same as it's in histories page.
* Unlike anthor git frontend app `Fork`, you should edit the final message on the last commit rather than the  previous commit that will be meld into while squashing commits
This commit is contained in:
leo 2024-06-20 17:02:12 +08:00
parent 6c9f7e6da3
commit 7070a07e15
No known key found for this signature in database
17 changed files with 816 additions and 7 deletions

View file

@ -0,0 +1,79 @@
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Interactivity;
namespace SourceGit.Views
{
public partial class InteractiveRebase : ChromelessWindow
{
public InteractiveRebase()
{
InitializeComponent();
}
private void BeginMoveWindow(object sender, PointerPressedEventArgs e)
{
BeginMoveDrag(e);
}
private void CloseWindow(object sender, RoutedEventArgs e)
{
Close();
}
private void OnMoveItemUp(object sender, RoutedEventArgs e)
{
if (sender is Control control && DataContext is ViewModels.InteractiveRebase vm)
{
vm.MoveItemUp(control.DataContext as ViewModels.InteractiveRebaseItem);
e.Handled = true;
}
}
private void OnMoveItemDown(object sender, RoutedEventArgs e)
{
if (sender is Control control && DataContext is ViewModels.InteractiveRebase vm)
{
vm.MoveItemDown(control.DataContext as ViewModels.InteractiveRebaseItem);
e.Handled = true;
}
}
private void OnDataGridKeyDown(object sender, KeyEventArgs e)
{
var datagrid = sender as DataGrid;
var item = datagrid.SelectedItem as ViewModels.InteractiveRebaseItem;
if (item == null)
return;
var vm = DataContext as ViewModels.InteractiveRebase;
if (e.Key == Key.P)
item.SetAction(Models.InteractiveRebaseAction.Pick);
else if (e.Key == Key.E)
item.SetAction(Models.InteractiveRebaseAction.Edit);
else if (e.Key == Key.R)
item.SetAction(Models.InteractiveRebaseAction.Reword);
else if (e.Key == Key.S)
item.SetAction(Models.InteractiveRebaseAction.Squash);
else if (e.Key == Key.F)
item.SetAction(Models.InteractiveRebaseAction.Fixup);
else if (e.Key == Key.D)
item.SetAction(Models.InteractiveRebaseAction.Drop);
else if (e.Key == Key.Up && e.KeyModifiers == KeyModifiers.Alt)
vm.MoveItemUp(item);
else if (e.Key == Key.Down && e.KeyModifiers == KeyModifiers.Alt)
vm.MoveItemDown(item);
}
private async void StartJobs(object sender, RoutedEventArgs e)
{
Running.IsVisible = true;
Running.IsIndeterminate = true;
var vm = DataContext as ViewModels.InteractiveRebase;
await vm.Start();
Running.IsIndeterminate = false;
Running.IsVisible = false;
Close();
}
}
}