refactor: rewrite git apply implementation

- Do not translate commandline options for `git`
- Re-design combox layout for `git apply` popup

Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
leo 2025-03-17 15:30:32 +08:00
parent ddfc868df3
commit cdd1926e2f
No known key found for this signature in database
12 changed files with 36 additions and 99 deletions

View file

@ -2,14 +2,22 @@
{
public class ApplyWhiteSpaceMode
{
public static readonly ApplyWhiteSpaceMode[] Supported =
[
new ApplyWhiteSpaceMode("No Warn", "Turns off the trailing whitespace warning", "nowarn"),
new ApplyWhiteSpaceMode("Warn", "Outputs warnings for a few such errors, but applies", "warn"),
new ApplyWhiteSpaceMode("Error", "Raise errors and refuses to apply the patch", "error"),
new ApplyWhiteSpaceMode("Error All", "Similar to 'error', but shows more", "error-all"),
];
public string Name { get; set; }
public string Desc { get; set; }
public string Arg { get; set; }
public ApplyWhiteSpaceMode(string n, string d, string a)
{
Name = App.Text(n);
Desc = App.Text(d);
Name = n;
Desc = d;
Arg = a;
}
}

View file

@ -25,18 +25,10 @@
<x:String x:Key="Text.AIAssistant.Tip" xml:space="preserve">Verwende OpenAI, um Commit-Nachrichten zu generieren</x:String>
<x:String x:Key="Text.AIAssistant.Use" xml:space="preserve">Als Commit-Nachricht verwenden</x:String>
<x:String x:Key="Text.Apply" xml:space="preserve">Patch</x:String>
<x:String x:Key="Text.Apply.Error" xml:space="preserve">Fehler</x:String>
<x:String x:Key="Text.Apply.Error.Desc" xml:space="preserve">Fehler werfen und anwenden des Patches verweigern</x:String>
<x:String x:Key="Text.Apply.ErrorAll" xml:space="preserve">Alle Fehler</x:String>
<x:String x:Key="Text.Apply.ErrorAll.Desc" xml:space="preserve">Ähnlich wie 'Fehler', zeigt aber mehr an</x:String>
<x:String x:Key="Text.Apply.File" xml:space="preserve">Patch-Datei:</x:String>
<x:String x:Key="Text.Apply.File.Placeholder" xml:space="preserve">Wähle die anzuwendende .patch-Datei</x:String>
<x:String x:Key="Text.Apply.IgnoreWS" xml:space="preserve">Ignoriere Leerzeichenänderungen</x:String>
<x:String x:Key="Text.Apply.NoWarn" xml:space="preserve">Keine Warnungen</x:String>
<x:String x:Key="Text.Apply.NoWarn.Desc" xml:space="preserve">Keine Warnung vor Leerzeichen am Zeilenende</x:String>
<x:String x:Key="Text.Apply.Title" xml:space="preserve">Patch anwenden</x:String>
<x:String x:Key="Text.Apply.Warn" xml:space="preserve">Warnen</x:String>
<x:String x:Key="Text.Apply.Warn.Desc" xml:space="preserve">Gibt eine Warnung für ein paar solcher Fehler aus, aber wendet es an</x:String>
<x:String x:Key="Text.Apply.WS" xml:space="preserve">Leerzeichen:</x:String>
<x:String x:Key="Text.ApplyStash" xml:space="preserve">Stash anwenden</x:String>
<x:String x:Key="Text.ApplyStash.DropAfterApply" xml:space="preserve">Nach dem Anwenden löschen</x:String>

View file

@ -22,18 +22,10 @@
<x:String x:Key="Text.AIAssistant.Tip" xml:space="preserve">Use AI to generate commit message</x:String>
<x:String x:Key="Text.AIAssistant.Use" xml:space="preserve">APPLY AS COMMIT MESSAGE</x:String>
<x:String x:Key="Text.Apply" xml:space="preserve">Patch</x:String>
<x:String x:Key="Text.Apply.Error" xml:space="preserve">Error</x:String>
<x:String x:Key="Text.Apply.Error.Desc" xml:space="preserve">Raise errors and refuses to apply the patch</x:String>
<x:String x:Key="Text.Apply.ErrorAll" xml:space="preserve">Error All</x:String>
<x:String x:Key="Text.Apply.ErrorAll.Desc" xml:space="preserve">Similar to 'error', but shows more</x:String>
<x:String x:Key="Text.Apply.File" xml:space="preserve">Patch File:</x:String>
<x:String x:Key="Text.Apply.File.Placeholder" xml:space="preserve">Select .patch file to apply</x:String>
<x:String x:Key="Text.Apply.IgnoreWS" xml:space="preserve">Ignore whitespace changes</x:String>
<x:String x:Key="Text.Apply.NoWarn" xml:space="preserve">No Warn</x:String>
<x:String x:Key="Text.Apply.NoWarn.Desc" xml:space="preserve">Turns off the trailing whitespace warning</x:String>
<x:String x:Key="Text.Apply.Title" xml:space="preserve">Apply Patch</x:String>
<x:String x:Key="Text.Apply.Warn" xml:space="preserve">Warn</x:String>
<x:String x:Key="Text.Apply.Warn.Desc" xml:space="preserve">Outputs warnings for a few such errors, but applies</x:String>
<x:String x:Key="Text.Apply.WS" xml:space="preserve">Whitespace:</x:String>
<x:String x:Key="Text.ApplyStash" xml:space="preserve">Apply Stash</x:String>
<x:String x:Key="Text.ApplyStash.DropAfterApply" xml:space="preserve">Delete after applying</x:String>

View file

@ -25,18 +25,10 @@
<x:String x:Key="Text.AIAssistant.Tip" xml:space="preserve">Usar OpenAI para generar mensaje de commit</x:String>
<x:String x:Key="Text.AIAssistant.Use" xml:space="preserve">APLICAR CÓMO MENSAJE DE COMMIT</x:String>
<x:String x:Key="Text.Apply" xml:space="preserve">Aplicar Parche</x:String>
<x:String x:Key="Text.Apply.Error" xml:space="preserve">Error</x:String>
<x:String x:Key="Text.Apply.Error.Desc" xml:space="preserve">Genera errores y se niega a aplicar el parche</x:String>
<x:String x:Key="Text.Apply.ErrorAll" xml:space="preserve">Error Todo</x:String>
<x:String x:Key="Text.Apply.ErrorAll.Desc" xml:space="preserve">Similar a 'error', pero muestra más</x:String>
<x:String x:Key="Text.Apply.File" xml:space="preserve">Archivo del Parche:</x:String>
<x:String x:Key="Text.Apply.File.Placeholder" xml:space="preserve">Seleccionar archivo .patch para aplicar</x:String>
<x:String x:Key="Text.Apply.IgnoreWS" xml:space="preserve">Ignorar cambios de espacios en blanco</x:String>
<x:String x:Key="Text.Apply.NoWarn" xml:space="preserve">Sin Advertencia</x:String>
<x:String x:Key="Text.Apply.NoWarn.Desc" xml:space="preserve">Desactiva la advertencia de espacios en blanco al final</x:String>
<x:String x:Key="Text.Apply.Title" xml:space="preserve">Aplicar Parche</x:String>
<x:String x:Key="Text.Apply.Warn" xml:space="preserve">Advertencia</x:String>
<x:String x:Key="Text.Apply.Warn.Desc" xml:space="preserve">Genera advertencias para algunos de estos errores, pero aplica</x:String>
<x:String x:Key="Text.Apply.WS" xml:space="preserve">Espacios en Blanco:</x:String>
<x:String x:Key="Text.ApplyStash" xml:space="preserve">Aplicar Stash</x:String>
<x:String x:Key="Text.ApplyStash.DropAfterApply" xml:space="preserve">Borrar después de aplicar</x:String>

View file

@ -23,18 +23,10 @@
<x:String x:Key="Text.AIAssistant" xml:space="preserve">Assistant IA</x:String>
<x:String x:Key="Text.AIAssistant.Tip" xml:space="preserve">Utiliser l'IA pour générer un message de commit</x:String>
<x:String x:Key="Text.Apply" xml:space="preserve">Appliquer</x:String>
<x:String x:Key="Text.Apply.Error" xml:space="preserve">Erreur</x:String>
<x:String x:Key="Text.Apply.Error.Desc" xml:space="preserve">Soulever les erreurs et refuser d'appliquer le patch</x:String>
<x:String x:Key="Text.Apply.ErrorAll" xml:space="preserve">Toutes les erreurs</x:String>
<x:String x:Key="Text.Apply.ErrorAll.Desc" xml:space="preserve">Similaire à 'Erreur', mais plus détaillé</x:String>
<x:String x:Key="Text.Apply.File" xml:space="preserve">Fichier de patch :</x:String>
<x:String x:Key="Text.Apply.File.Placeholder" xml:space="preserve">Selectionner le fichier .patch à appliquer</x:String>
<x:String x:Key="Text.Apply.IgnoreWS" xml:space="preserve">Ignorer les changements d'espaces blancs</x:String>
<x:String x:Key="Text.Apply.NoWarn" xml:space="preserve">Pas d'avertissement</x:String>
<x:String x:Key="Text.Apply.NoWarn.Desc" xml:space="preserve">Désactiver l'avertissement sur les espaces blancs terminaux</x:String>
<x:String x:Key="Text.Apply.Title" xml:space="preserve">Appliquer le patch</x:String>
<x:String x:Key="Text.Apply.Warn" xml:space="preserve">Avertissement</x:String>
<x:String x:Key="Text.Apply.Warn.Desc" xml:space="preserve">Affiche des avertissements pour ce type d'erreurs tout en appliquant le patch</x:String>
<x:String x:Key="Text.Apply.WS" xml:space="preserve">Espaces blancs :</x:String>
<x:String x:Key="Text.Archive" xml:space="preserve">Archiver...</x:String>
<x:String x:Key="Text.Archive.File" xml:space="preserve">Enregistrer l'archive sous :</x:String>

View file

@ -25,18 +25,10 @@
<x:String x:Key="Text.AIAssistant.Tip" xml:space="preserve">Usa AI per generare il messaggio di commit</x:String>
<x:String x:Key="Text.AIAssistant.Use" xml:space="preserve">APPLICA COME MESSAGGIO DI COMMIT</x:String>
<x:String x:Key="Text.Apply" xml:space="preserve">Applica</x:String>
<x:String x:Key="Text.Apply.Error" xml:space="preserve">Errore</x:String>
<x:String x:Key="Text.Apply.Error.Desc" xml:space="preserve">Genera errori e si rifiuta di applicare la patch</x:String>
<x:String x:Key="Text.Apply.ErrorAll" xml:space="preserve">Tutti gli errori</x:String>
<x:String x:Key="Text.Apply.ErrorAll.Desc" xml:space="preserve">Simile a 'errore', ma mostra di più</x:String>
<x:String x:Key="Text.Apply.File" xml:space="preserve">File Patch:</x:String>
<x:String x:Key="Text.Apply.File.Placeholder" xml:space="preserve">Seleziona file .patch da applicare</x:String>
<x:String x:Key="Text.Apply.IgnoreWS" xml:space="preserve">Ignora modifiche agli spazi</x:String>
<x:String x:Key="Text.Apply.NoWarn" xml:space="preserve">Nessun avviso</x:String>
<x:String x:Key="Text.Apply.NoWarn.Desc" xml:space="preserve">Disattiva l'avviso sugli spazi finali</x:String>
<x:String x:Key="Text.Apply.Title" xml:space="preserve">Applica Patch</x:String>
<x:String x:Key="Text.Apply.Warn" xml:space="preserve">Avviso</x:String>
<x:String x:Key="Text.Apply.Warn.Desc" xml:space="preserve">Mostra avvisi per alcuni errori, ma applica comunque</x:String>
<x:String x:Key="Text.Apply.WS" xml:space="preserve">Spazi:</x:String>
<x:String x:Key="Text.ApplyStash" xml:space="preserve">Applica lo stash</x:String>
<x:String x:Key="Text.ApplyStash.DropAfterApply" xml:space="preserve">Rimuovi dopo aver applicato</x:String>

View file

@ -48,18 +48,10 @@
<x:String x:Key="Text.AIAssistant" xml:space="preserve">Assietente IA</x:String>
<x:String x:Key="Text.AIAssistant.Tip" xml:space="preserve">Utilizar IA para gerar mensagem de commit</x:String>
<x:String x:Key="Text.Apply" xml:space="preserve">Patch</x:String>
<x:String x:Key="Text.Apply.Error" xml:space="preserve">Erro</x:String>
<x:String x:Key="Text.Apply.Error.Desc" xml:space="preserve">Erros levantados e se recusa a aplicar o patch</x:String>
<x:String x:Key="Text.Apply.ErrorAll" xml:space="preserve">Erro Total</x:String>
<x:String x:Key="Text.Apply.ErrorAll.Desc" xml:space="preserve">Semelhante a 'erro', mas mostra mais</x:String>
<x:String x:Key="Text.Apply.File" xml:space="preserve">Arquivo de Patch:</x:String>
<x:String x:Key="Text.Apply.File.Placeholder" xml:space="preserve">Selecione o arquivo .patch para aplicar</x:String>
<x:String x:Key="Text.Apply.IgnoreWS" xml:space="preserve">Ignorar mudanças de espaço em branco</x:String>
<x:String x:Key="Text.Apply.NoWarn" xml:space="preserve">Sem Aviso</x:String>
<x:String x:Key="Text.Apply.NoWarn.Desc" xml:space="preserve">Desativa o aviso de espaço em branco no final</x:String>
<x:String x:Key="Text.Apply.Title" xml:space="preserve">Aplicar Patch</x:String>
<x:String x:Key="Text.Apply.Warn" xml:space="preserve">Aviso</x:String>
<x:String x:Key="Text.Apply.Warn.Desc" xml:space="preserve">Emite avisos para alguns erros, mas aplica</x:String>
<x:String x:Key="Text.Apply.WS" xml:space="preserve">Espaço em Branco:</x:String>
<x:String x:Key="Text.Archive" xml:space="preserve">Arquivar...</x:String>
<x:String x:Key="Text.Archive.File" xml:space="preserve">Salvar Arquivo Como:</x:String>

View file

@ -25,18 +25,10 @@
<x:String x:Key="Text.AIAssistant.Tip" xml:space="preserve">Использовать OpenAI для создания сообщения о ревизии</x:String>
<x:String x:Key="Text.AIAssistant.Use" xml:space="preserve">ПРИМЕНИТЬ КАК СООБЩЕНИЕ РЕВИЗИИ</x:String>
<x:String x:Key="Text.Apply" xml:space="preserve">Исправить </x:String>
<x:String x:Key="Text.Apply.Error" xml:space="preserve">Ошибка</x:String>
<x:String x:Key="Text.Apply.Error.Desc" xml:space="preserve">Выдает ошибки и отказывается применять заплатку</x:String>
<x:String x:Key="Text.Apply.ErrorAll" xml:space="preserve">Все ошибки</x:String>
<x:String x:Key="Text.Apply.ErrorAll.Desc" xml:space="preserve">Аналогично «ошибке», но показывает больше</x:String>
<x:String x:Key="Text.Apply.File" xml:space="preserve">Файл заплатки:</x:String>
<x:String x:Key="Text.Apply.File.Placeholder" xml:space="preserve">Выберите файл .patch для применения</x:String>
<x:String x:Key="Text.Apply.IgnoreWS" xml:space="preserve">Игнорировать изменения пробелов</x:String>
<x:String x:Key="Text.Apply.NoWarn" xml:space="preserve">Нет предупреждений</x:String>
<x:String x:Key="Text.Apply.NoWarn.Desc" xml:space="preserve">Отключить предупреждения о пробелах в конце</x:String>
<x:String x:Key="Text.Apply.Title" xml:space="preserve">Применить заплатку</x:String>
<x:String x:Key="Text.Apply.Warn" xml:space="preserve">Предупреждать</x:String>
<x:String x:Key="Text.Apply.Warn.Desc" xml:space="preserve">Выдавать предупреждения о нескольких таких ошибках, но применять</x:String>
<x:String x:Key="Text.Apply.WS" xml:space="preserve">Пробел:</x:String>
<x:String x:Key="Text.ApplyStash" xml:space="preserve">Отложить</x:String>
<x:String x:Key="Text.ApplyStash.DropAfterApply" xml:space="preserve">Удалить после применения</x:String>

View file

@ -25,18 +25,10 @@
<x:String x:Key="Text.AIAssistant.Tip" xml:space="preserve">使用AI助手生成提交信息</x:String>
<x:String x:Key="Text.AIAssistant.Use" xml:space="preserve">应用本次生成</x:String>
<x:String x:Key="Text.Apply" xml:space="preserve">应用补丁(apply)</x:String>
<x:String x:Key="Text.Apply.Error" xml:space="preserve">错误</x:String>
<x:String x:Key="Text.Apply.Error.Desc" xml:space="preserve">输出错误,并终止应用补丁</x:String>
<x:String x:Key="Text.Apply.ErrorAll" xml:space="preserve">更多错误</x:String>
<x:String x:Key="Text.Apply.ErrorAll.Desc" xml:space="preserve">与【错误】级别相似,但输出内容更多</x:String>
<x:String x:Key="Text.Apply.File" xml:space="preserve">补丁文件 </x:String>
<x:String x:Key="Text.Apply.File.Placeholder" xml:space="preserve">选择补丁文件</x:String>
<x:String x:Key="Text.Apply.IgnoreWS" xml:space="preserve">忽略空白符号</x:String>
<x:String x:Key="Text.Apply.NoWarn" xml:space="preserve">忽略</x:String>
<x:String x:Key="Text.Apply.NoWarn.Desc" xml:space="preserve">关闭所有警告</x:String>
<x:String x:Key="Text.Apply.Title" xml:space="preserve">应用补丁</x:String>
<x:String x:Key="Text.Apply.Warn" xml:space="preserve">警告</x:String>
<x:String x:Key="Text.Apply.Warn.Desc" xml:space="preserve">应用补丁,输出关于空白符的警告</x:String>
<x:String x:Key="Text.Apply.WS" xml:space="preserve">空白符号处理 </x:String>
<x:String x:Key="Text.ApplyStash" xml:space="preserve">应用贮藏</x:String>
<x:String x:Key="Text.ApplyStash.DropAfterApply" xml:space="preserve">在成功应用后丢弃该贮藏</x:String>

View file

@ -25,18 +25,10 @@
<x:String x:Key="Text.AIAssistant.Tip" xml:space="preserve">使用 AI 產生提交訊息</x:String>
<x:String x:Key="Text.AIAssistant.Use" xml:space="preserve">套用為提交訊息</x:String>
<x:String x:Key="Text.Apply" xml:space="preserve">套用修補檔 (apply patch)</x:String>
<x:String x:Key="Text.Apply.Error" xml:space="preserve">錯誤</x:String>
<x:String x:Key="Text.Apply.Error.Desc" xml:space="preserve">輸出錯誤,並中止套用修補檔</x:String>
<x:String x:Key="Text.Apply.ErrorAll" xml:space="preserve">更多錯誤</x:String>
<x:String x:Key="Text.Apply.ErrorAll.Desc" xml:space="preserve">與 [錯誤] 級別相似,但輸出更多內容</x:String>
<x:String x:Key="Text.Apply.File" xml:space="preserve">修補檔:</x:String>
<x:String x:Key="Text.Apply.File.Placeholder" xml:space="preserve">選擇修補檔</x:String>
<x:String x:Key="Text.Apply.IgnoreWS" xml:space="preserve">忽略空白符號</x:String>
<x:String x:Key="Text.Apply.NoWarn" xml:space="preserve">忽略</x:String>
<x:String x:Key="Text.Apply.NoWarn.Desc" xml:space="preserve">關閉所有警告</x:String>
<x:String x:Key="Text.Apply.Title" xml:space="preserve">套用修補檔</x:String>
<x:String x:Key="Text.Apply.Warn" xml:space="preserve">警告</x:String>
<x:String x:Key="Text.Apply.Warn.Desc" xml:space="preserve">套用修補檔,輸出關於空白字元的警告</x:String>
<x:String x:Key="Text.Apply.WS" xml:space="preserve">空白字元處理:</x:String>
<x:String x:Key="Text.ApplyStash" xml:space="preserve">套用擱置變更</x:String>
<x:String x:Key="Text.ApplyStash.DropAfterApply" xml:space="preserve">套用擱置變更後刪除</x:String>

View file

@ -1,5 +1,4 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations;
using System.IO;
using System.Threading.Tasks;
@ -21,12 +20,6 @@ namespace SourceGit.ViewModels
set => SetProperty(ref _ignoreWhiteSpace, value);
}
public List<Models.ApplyWhiteSpaceMode> WhiteSpaceModes
{
get;
private set;
}
public Models.ApplyWhiteSpaceMode SelectedWhiteSpaceMode
{
get;
@ -37,23 +30,14 @@ namespace SourceGit.ViewModels
{
_repo = repo;
WhiteSpaceModes = new List<Models.ApplyWhiteSpaceMode> {
new Models.ApplyWhiteSpaceMode("Apply.NoWarn", "Apply.NoWarn.Desc", "nowarn"),
new Models.ApplyWhiteSpaceMode("Apply.Warn", "Apply.Warn.Desc", "warn"),
new Models.ApplyWhiteSpaceMode("Apply.Error", "Apply.Error.Desc", "error"),
new Models.ApplyWhiteSpaceMode("Apply.ErrorAll", "Apply.ErrorAll.Desc", "error-all")
};
SelectedWhiteSpaceMode = WhiteSpaceModes[0];
SelectedWhiteSpaceMode = Models.ApplyWhiteSpaceMode.Supported[0];
View = new Views.Apply() { DataContext = this };
}
public static ValidationResult ValidatePatchFile(string file, ValidationContext _)
{
if (File.Exists(file))
{
return ValidationResult.Success;
}
return new ValidationResult($"File '{file}' can NOT be found!!!");
}

View file

@ -39,17 +39,34 @@
<ComboBox Grid.Row="1" Grid.Column="1"
Height="28" Padding="8,0"
VerticalAlignment="Center" HorizontalAlignment="Stretch"
ItemsSource="{Binding WhiteSpaceModes}"
ItemsSource="{Binding Source={x:Static m:ApplyWhiteSpaceMode.Supported}}"
SelectedItem="{Binding SelectedWhiteSpaceMode, Mode=TwoWay}"
IsEnabled="{Binding !IgnoreWhiteSpace}">
IsEnabled="{Binding !IgnoreWhiteSpace}"
Grid.IsSharedSizeScope="True">
<ComboBox.ItemTemplate>
<DataTemplate x:DataType="{x:Type m:ApplyWhiteSpaceMode}">
<StackPanel Orientation="Horizontal" Height="20" VerticalAlignment="Center">
<TextBlock Text="{Binding Name}"/>
<TextBlock Text="{Binding Desc}" Margin="8,0,0,0" FontSize="11" Foreground="{DynamicResource Brush.FG2}"/>
</StackPanel>
<DataTemplate DataType="m:ApplyWhiteSpaceMode">
<Grid Height="20" VerticalAlignment="Center">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" SharedSizeGroup="ApplyModeNameColumn"/>
<ColumnDefinition Width="Auto" SharedSizeGroup="ApplyModeDescColumn"/>
<ColumnDefinition Width="Auto" SharedSizeGroup="ApplyModeArgsColumn"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Text="{Binding Name}"/>
<TextBlock Grid.Column="1" Text="{Binding Desc}" Margin="8,0" FontSize="11" Foreground="{DynamicResource Brush.FG2}"/>
<TextBlock Grid.Column="2" Text="{Binding Arg}" HorizontalAlignment="Right" FontSize="11" Foreground="{DynamicResource Brush.FG2}"/>
</Grid>
</DataTemplate>
</ComboBox.ItemTemplate>
<ComboBox.SelectionBoxItemTemplate>
<DataTemplate DataType="m:ApplyWhiteSpaceMode">
<Grid ColumnDefinitions="Auto,*">
<TextBlock Grid.Column="0" Text="{Binding Name}" Margin="0,0,8,0"/>
<TextBlock Grid.Column="1" Text="{Binding Desc}" HorizontalAlignment="Right" FontSize="11" Foreground="{DynamicResource Brush.FG2}"/>
</Grid>
</DataTemplate>
</ComboBox.SelectionBoxItemTemplate>
</ComboBox>
<CheckBox Grid.Row="2" Grid.Column="1"