sourcegit/src/ViewModels/Apply.cs
leo cdd1926e2f
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>
2025-03-17 15:30:32 +08:00

62 lines
1.8 KiB
C#

using System.ComponentModel.DataAnnotations;
using System.IO;
using System.Threading.Tasks;
namespace SourceGit.ViewModels
{
public class Apply : Popup
{
[Required(ErrorMessage = "Patch file is required!!!")]
[CustomValidation(typeof(Apply), nameof(ValidatePatchFile))]
public string PatchFile
{
get => _patchFile;
set => SetProperty(ref _patchFile, value, true);
}
public bool IgnoreWhiteSpace
{
get => _ignoreWhiteSpace;
set => SetProperty(ref _ignoreWhiteSpace, value);
}
public Models.ApplyWhiteSpaceMode SelectedWhiteSpaceMode
{
get;
set;
}
public Apply(Repository repo)
{
_repo = repo;
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!!!");
}
public override Task<bool> Sure()
{
_repo.SetWatcherEnabled(false);
ProgressDescription = "Apply patch...";
return Task.Run(() =>
{
var succ = new Commands.Apply(_repo.FullPath, _patchFile, _ignoreWhiteSpace, SelectedWhiteSpaceMode.Arg, null).Exec();
CallUIThread(() => _repo.SetWatcherEnabled(true));
return succ;
});
}
private readonly Repository _repo = null;
private string _patchFile = string.Empty;
private bool _ignoreWhiteSpace = true;
}
}