mirror of
https://fastgit.cc/github.com/sourcegit-scm/sourcegit
synced 2026-04-30 13:51:53 +08:00
refactor: use hotkey instead of custom OnKeyDown to re-order commits in Interactive Rebase window
Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
@@ -38,7 +38,7 @@
|
||||
</Grid>
|
||||
|
||||
<!-- Operation Information -->
|
||||
<Grid Grid.Row="1" Margin="8" ColumnDefinitions="*,Auto">
|
||||
<Grid Grid.Row="1" Margin="8" ColumnDefinitions="*,Auto,0,0">
|
||||
<StackPanel Grid.Column="0" Orientation="Horizontal" ClipToBounds="True">
|
||||
<TextBlock Text="{DynamicResource Text.InteractiveRebase.Target}" Foreground="{DynamicResource Brush.FG2}" FontWeight="Bold"/>
|
||||
<Path Width="14" Height="14" Margin="8,0,0,0" Data="{StaticResource Icons.Branch}"/>
|
||||
@@ -61,6 +61,9 @@
|
||||
|
||||
<Path Width="14" Height="14" Data="{StaticResource Icons.Info}"/>
|
||||
</Border>
|
||||
|
||||
<Button Grid.Column="2" Width="0" Height="0" Click="OnMoveSelectedUp" HotKey="{OnPlatform Ctrl+Up, macOS=⌘+Up}"/>
|
||||
<Button Grid.Column="3" Width="0" Height="0" Click="OnMoveSelectedDown" HotKey="{OnPlatform Ctrl+Down, macOS=⌘+Down}"/>
|
||||
</Grid>
|
||||
|
||||
<!-- Body -->
|
||||
@@ -122,7 +125,7 @@
|
||||
HorizontalAlignment="Center"/>
|
||||
|
||||
<!-- Action -->
|
||||
<Button Grid.Column="1" Opacity="1" Margin="4,0,0,0" Padding="8,2" Background="Transparent" Click="OnButtonActionClicked">
|
||||
<Button Grid.Column="1" Opacity="1" Margin="4,0,0,0" Padding="8,2" Background="Transparent" Click="OnShowActionsDropdownMenu">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<Ellipse Width="14" Height="14" Fill="{Binding Action, Converter={x:Static c:InteractiveRebaseActionConverters.ToIconBrush}}"/>
|
||||
<TextBlock Margin="8,0" Text="{Binding Action, Converter={x:Static c:InteractiveRebaseActionConverters.ToName}}"/>
|
||||
|
||||
@@ -76,40 +76,8 @@ namespace SourceGit.Views
|
||||
}
|
||||
else if (e.KeyModifiers.HasFlag(KeyModifiers.Control))
|
||||
{
|
||||
if (e.Key == Key.Up)
|
||||
{
|
||||
var idx = 0;
|
||||
for (int i = 0; i < vm.Items.Count; i++)
|
||||
{
|
||||
if (items.Contains(vm.Items[i]))
|
||||
{
|
||||
idx = Math.Max(0, i - 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
vm.Move(items, idx);
|
||||
SelectedItems = items;
|
||||
Focus();
|
||||
e.Handled = true;
|
||||
}
|
||||
else if (e.Key == Key.Down)
|
||||
{
|
||||
var idx = 0;
|
||||
for (int i = vm.Items.Count - 1; i >= 0; i--)
|
||||
{
|
||||
if (items.Contains(vm.Items[i]))
|
||||
{
|
||||
idx = Math.Min(vm.Items.Count, i + 2);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
vm.Move(items, idx);
|
||||
SelectedItems = items;
|
||||
Focus();
|
||||
e.Handled = true;
|
||||
}
|
||||
if (e.Key == Key.Up || e.Key == Key.Down)
|
||||
return;
|
||||
}
|
||||
|
||||
if (!e.Handled)
|
||||
@@ -265,7 +233,75 @@ namespace SourceGit.Views
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
private void OnButtonActionClicked(object sender, RoutedEventArgs e)
|
||||
private void OnMoveSelectedUp(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (DataContext is not ViewModels.InteractiveRebase vm)
|
||||
return;
|
||||
|
||||
if (IRItemListBox.SelectedItems is not { Count: > 0 } selected)
|
||||
return;
|
||||
|
||||
var hashes = new HashSet<string>();
|
||||
var items = new List<ViewModels.InteractiveRebaseItem>();
|
||||
foreach (var item in selected)
|
||||
{
|
||||
if (item is ViewModels.InteractiveRebaseItem irItem)
|
||||
{
|
||||
hashes.Add(irItem.Commit.SHA);
|
||||
items.Add(irItem);
|
||||
}
|
||||
}
|
||||
|
||||
var idx = 0;
|
||||
for (int i = 0; i < vm.Items.Count; i++)
|
||||
{
|
||||
if (hashes.Contains(vm.Items[i].Commit.SHA))
|
||||
{
|
||||
idx = Math.Max(0, i - 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
vm.Move(items, idx);
|
||||
IRItemListBox.SelectedItems = items;
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
private void OnMoveSelectedDown(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (DataContext is not ViewModels.InteractiveRebase vm)
|
||||
return;
|
||||
|
||||
if (IRItemListBox.SelectedItems is not { Count: > 0 } selected)
|
||||
return;
|
||||
|
||||
var hashes = new HashSet<string>();
|
||||
var items = new List<ViewModels.InteractiveRebaseItem>();
|
||||
foreach (var item in selected)
|
||||
{
|
||||
if (item is ViewModels.InteractiveRebaseItem irItem)
|
||||
{
|
||||
hashes.Add(irItem.Commit.SHA);
|
||||
items.Add(irItem);
|
||||
}
|
||||
}
|
||||
|
||||
var idx = 0;
|
||||
for (int i = vm.Items.Count - 1; i >= 0; i--)
|
||||
{
|
||||
if (hashes.Contains(vm.Items[i].Commit.SHA))
|
||||
{
|
||||
idx = Math.Min(vm.Items.Count, i + 2);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
vm.Move(items, idx);
|
||||
IRItemListBox.SelectedItems = items;
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
private void OnShowActionsDropdownMenu(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (sender is not Button { DataContext: ViewModels.InteractiveRebaseItem item } button)
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user