diff --git a/src/Models/ResetMode.cs b/src/Models/ResetMode.cs index 312302a8..827ccaa9 100644 --- a/src/Models/ResetMode.cs +++ b/src/Models/ResetMode.cs @@ -6,20 +6,20 @@ namespace SourceGit.Models { public static readonly ResetMode[] Supported = [ - 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), + 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 string Key { get; set; } public IBrush Color { get; set; } - public ResetMode(string n, string d, string a, char k, IBrush b) + public ResetMode(string n, string d, string a, string k, IBrush b) { Name = n; Desc = d; diff --git a/src/Views/Reset.axaml b/src/Views/Reset.axaml index 5c3025e9..b3a18e49 100644 --- a/src/Views/Reset.axaml +++ b/src/Views/Reset.axaml @@ -7,7 +7,6 @@ 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"> - + SelectedItem="{Binding SelectedMode, Mode=TwoWay}" + KeyDown="OnResetModeKeyDown"> diff --git a/src/Views/Reset.axaml.cs b/src/Views/Reset.axaml.cs index cefcf426..8c380538 100644 --- a/src/Views/Reset.axaml.cs +++ b/src/Views/Reset.axaml.cs @@ -1,8 +1,6 @@ -using System.Linq; using Avalonia.Controls; using Avalonia.Input; using Avalonia.Interactivity; -using SourceGit.Models; namespace SourceGit.Views { @@ -13,27 +11,28 @@ namespace SourceGit.Views InitializeComponent(); } - private void InputElement_OnKeyDown(object sender, KeyEventArgs e) + protected override void OnLoaded(RoutedEventArgs e) { - var key = e.Key.ToString().ToLower(); - foreach (var item in ResetMode.ItemsSource) + base.OnLoaded(e); + + ResetMode.Focus(); + } + + private void OnResetModeKeyDown(object sender, KeyEventArgs e) + { + if (sender is ComboBox comboBox) { - if (item.GetType() == typeof(ResetMode)) + var key = e.Key.ToString(); + for (int i = 0; i < Models.ResetMode.Supported.Length; i++) { - var resetMode = (ResetMode)item; - if (resetMode.Key.ToString().ToLower() == key) + if (key.Equals(Models.ResetMode.Supported[i].Key, System.StringComparison.OrdinalIgnoreCase)) { - ResetMode.SelectedValue = resetMode; + comboBox.SelectedIndex = i; + e.Handled = true; return; } - } } } - - private void Control_OnLoaded(object sender, RoutedEventArgs e) - { - ResetMode.Focus(); - } } }