mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-25 21:07:20 -08:00
code_review: PR #714
* remove `string.ToLower` warning * override `OnLoaded` method directly * clean namespace using Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
parent
ea1d966d27
commit
d07a664166
3 changed files with 25 additions and 26 deletions
|
@ -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;
|
||||
|
|
|
@ -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">
|
||||
<StackPanel Orientation="Vertical" Margin="8,0">
|
||||
<TextBlock FontSize="18"
|
||||
|
@ -37,12 +36,13 @@
|
|||
HorizontalAlignment="Right" VerticalAlignment="Center"
|
||||
Margin="0,0,8,0"
|
||||
Text="{DynamicResource Text.Reset.Mode}"/>
|
||||
<ComboBox x:Name="ResetMode" Grid.Row="2" Grid.Column="1"
|
||||
<ComboBox Grid.Row="2" Grid.Column="1"
|
||||
x:Name="ResetMode"
|
||||
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}">
|
||||
SelectedItem="{Binding SelectedMode, Mode=TwoWay}"
|
||||
KeyDown="OnResetModeKeyDown">
|
||||
<ComboBox.ItemTemplate>
|
||||
<DataTemplate DataType="m:ResetMode">
|
||||
<Grid ColumnDefinitions="16,60,*">
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue