mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-06-01 17:24:59 +00:00
refactor<*>: rewrite all codes...
This commit is contained in:
parent
89ff8aa744
commit
30ab8ae954
342 changed files with 17208 additions and 19633 deletions
31
src/Views/Validations/RemoteName.cs
Normal file
31
src/Views/Validations/RemoteName.cs
Normal file
|
@ -0,0 +1,31 @@
|
|||
using System.Globalization;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace SourceGit.Views.Validations {
|
||||
public class RemoteName : ValidationRule {
|
||||
private static readonly Regex REG_FORMAT = new Regex(@"^[\w\-\.]+$");
|
||||
|
||||
public Models.Repository Repo { get; set; }
|
||||
public bool IsOptional { get; set; }
|
||||
|
||||
public override ValidationResult Validate(object value, CultureInfo cultureInfo) {
|
||||
var name = value as string;
|
||||
if (string.IsNullOrEmpty(name)) {
|
||||
return IsOptional ? ValidationResult.ValidResult : new ValidationResult(false, App.Text("EmptyRemoteName"));
|
||||
}
|
||||
|
||||
if (!REG_FORMAT.IsMatch(name)) return new ValidationResult(false, App.Text("BadRemoteName"));
|
||||
|
||||
if (Repo != null) {
|
||||
foreach (var t in Repo.Remotes) {
|
||||
if (t.Name == name) {
|
||||
return new ValidationResult(false, App.Text("DuplicatedRemoteName"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ValidationResult.ValidResult;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue