feat: Reset Mode Hotkey (#714)

This commit is contained in:
Enner Pérez 2024-11-18 20:14:53 -05:00 committed by GitHub
parent f4618afee6
commit ea1d966d27
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 41 additions and 9 deletions

View file

@ -6,23 +6,25 @@ namespace SourceGit.Models
{
public static readonly ResetMode[] Supported =
[
new ResetMode("Soft", "Keep all changes. Stage differences", "--soft", Brushes.Green),
new ResetMode("Mixed", "Keep all changes. Unstage differences", "--mixed", Brushes.Orange),
new ResetMode("Merge", "Reset while keeping unmerged changes", "--merge", Brushes.Purple),
new ResetMode("Keep", "Reset while keeping local modifications", "--keep", Brushes.Purple),
new ResetMode("Hard", "Discard all changes", "--hard", Brushes.Red),
new ResetMode("Soft", "Keep all changes. Stage differences", "--soft", 'S', Brushes.Green),
new ResetMode("Mixed", "Keep all changes. Unstage differences", "--mixed", 'M',Brushes.Orange),
new ResetMode("Merge", "Reset while keeping unmerged changes", "--merge", 'G',Brushes.Purple),
new ResetMode("Keep", "Reset while keeping local modifications", "--keep", 'K',Brushes.Purple),
new ResetMode("Hard", "Discard all changes", "--hard", 'H',Brushes.Red),
];
public string Name { get; set; }
public string Desc { get; set; }
public string Arg { get; set; }
public char Key { get; set; }
public IBrush Color { get; set; }
public ResetMode(string n, string d, string a, IBrush b)
public ResetMode(string n, string d, string a, char k, IBrush b)
{
Name = n;
Desc = d;
Arg = a;
Key = k;
Color = b;
}
}

View file

@ -7,6 +7,7 @@
xmlns:c="using:SourceGit.Converters"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="SourceGit.Views.Reset"
Loaded="Control_OnLoaded"
x:DataType="vm:Reset">
<StackPanel Orientation="Vertical" Margin="8,0">
<TextBlock FontSize="18"
@ -36,17 +37,19 @@
HorizontalAlignment="Right" VerticalAlignment="Center"
Margin="0,0,8,0"
Text="{DynamicResource Text.Reset.Mode}"/>
<ComboBox Grid.Row="2" Grid.Column="1"
<ComboBox x:Name="ResetMode" Grid.Row="2" Grid.Column="1"
Height="28" Padding="8,0"
VerticalAlignment="Center" HorizontalAlignment="Stretch"
KeyDown="InputElement_OnKeyDown"
ItemsSource="{Binding Source={x:Static m:ResetMode.Supported}}"
SelectedItem="{Binding SelectedMode, Mode=TwoWay}">
<ComboBox.ItemTemplate>
<DataTemplate DataType="m:ResetMode">
<Grid ColumnDefinitions="16,60,*">
<Ellipse Grid.Column="0" Width="12" Height="12" Fill="{Binding Color}"/>
<TextBlock Grid.Column="1" Text="{Binding Name}" Margin="4,0,0,0"/>
<TextBlock Grid.Column="2" Text="{Binding Desc}" FontSize="11" Foreground="{DynamicResource Brush.FG2}" HorizontalAlignment="Right"/>
<TextBlock Grid.Column="1" Text="{Binding Name}" Margin="2,0,0,0"/>
<TextBlock Grid.Column="2" Text="{Binding Desc}" Margin="2,0,16,0" FontSize="11" Foreground="{DynamicResource Brush.FG2}" HorizontalAlignment="Right"/>
<TextBlock Grid.Column="3" Text="{Binding Key}" FontSize="11" FontWeight="Bold" Foreground="{DynamicResource Brush.FG2}" HorizontalAlignment="Right"/>
</Grid>
</DataTemplate>
</ComboBox.ItemTemplate>

View file

@ -1,4 +1,8 @@
using System.Linq;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Interactivity;
using SourceGit.Models;
namespace SourceGit.Views
{
@ -8,5 +12,28 @@ namespace SourceGit.Views
{
InitializeComponent();
}
private void InputElement_OnKeyDown(object sender, KeyEventArgs e)
{
var key = e.Key.ToString().ToLower();
foreach (var item in ResetMode.ItemsSource)
{
if (item.GetType() == typeof(ResetMode))
{
var resetMode = (ResetMode)item;
if (resetMode.Key.ToString().ToLower() == key)
{
ResetMode.SelectedValue = resetMode;
return;
}
}
}
}
private void Control_OnLoaded(object sender, RoutedEventArgs e)
{
ResetMode.Focus();
}
}
}