Skip to content

Commit

Permalink
Merge pull request #382 from varKeytrap/master
Browse files Browse the repository at this point in the history
Added Custom support for TextType
  • Loading branch information
NaBian authored Jul 11, 2020
2 parents 40cc0f6 + ea8c8a9 commit 6c61113
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 23 deletions.
12 changes: 12 additions & 0 deletions src/Shared/HandyControl_Shared/Controls/Attach/InfoElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,17 @@ public static void SetMaxContentHeight(DependencyObject element, double value)

public static double GetMaxContentHeight(DependencyObject element)
=> (double) element.GetValue(MaxContentHeightProperty);

/// <summary>
/// 正则表达式
/// </summary>
public static readonly DependencyProperty RegexPatternProperty = DependencyProperty.RegisterAttached(
"RegexPattern", typeof(string), typeof(InfoElement), new PropertyMetadata(default(string)));

public static void SetRegexPattern(DependencyObject element, string value)
=> element.SetValue(RegexPatternProperty, value);

public static string GetRegexPattern(DependencyObject element)
=> (string) element.GetValue(RegexPatternProperty);
}
}
13 changes: 10 additions & 3 deletions src/Shared/HandyControl_Shared/Controls/Input/TextBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public bool IsError

public string ErrorStr
{
get => (string) GetValue(ErrorStrProperty);
get => (string)GetValue(ErrorStrProperty);
set => SetValue(ErrorStrProperty, value);
}

Expand All @@ -58,7 +58,7 @@ public string ErrorStr

public TextType TextType
{
get => (TextType) GetValue(TextTypeProperty);
get => (TextType)GetValue(TextTypeProperty);
set => SetValue(TextTypeProperty, value);
}

Expand Down Expand Up @@ -88,7 +88,14 @@ public virtual bool VerifyData()
{
if (TextType != TextType.Common)
{
result = Text.IsKindOf(TextType) ? OperationResult.Success() : OperationResult.Failed(Properties.Langs.Lang.FormatError);
var regexPattern = InfoElement.GetRegexPattern(this);
result = string.IsNullOrEmpty(regexPattern)
? Text.IsKindOf(TextType)
? OperationResult.Success()
: OperationResult.Failed(Properties.Langs.Lang.FormatError)
: Text.IsKindOf(regexPattern)
? OperationResult.Success()
: OperationResult.Failed(Properties.Langs.Lang.FormatError);
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion src/Shared/HandyControl_Shared/Data/Enum/TextType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ public enum TextType
NDouble,
Double,
NnDouble,
NpDouble,
NpDouble
}
}
4 changes: 2 additions & 2 deletions src/Shared/HandyControl_Shared/HandyControl_Shared.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,8 @@
<Compile Include="$(MSBuildThisFileDirectory)Tools\Pool\SimplePool!1.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Tools\Pool\SynchronizedPool!1.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Tools\Queue\Deque!1.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Tools\RegularJudgment.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Tools\RegularPatterns.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Tools\RegexJudgment.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Tools\RegexPatterns.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Tools\StyleSelector\ButtonGroupItemStyleSelector.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Tools\StyleSelector\ComboBoxItemCapsuleStyleSelector.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Tools\StyleSelector\TabItemCapsuleStyleSelector.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ protected override Geometry GetCurrentValueCore(Geometry defaultOriginValue, Geo
{
var geometryStr = defaultDestinationValue.ToString(CultureInfo.InvariantCulture);
AnimationHelper.DecomposeGeometryStr(geometryStr, out _numbersTo);
_strings = Regex.Split(geometryStr, RegularPatterns.DigitsPattern);
_strings = Regex.Split(geometryStr, RegexPatterns.DigitsPattern);
}

UpdateValue();
Expand Down Expand Up @@ -150,7 +150,7 @@ private static void OnToChanged(DependencyObject d, DependencyPropertyChangedEve
{
var geometryStr = geometry.ToString(CultureInfo.InvariantCulture);
AnimationHelper.DecomposeGeometryStr(geometryStr, out obj._numbersTo);
obj._strings = Regex.Split(geometryStr, RegularPatterns.DigitsPattern);
obj._strings = Regex.Split(geometryStr, RegexPatterns.DigitsPattern);
obj.UpdateValue();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public string[] Strings
return null;
}

return _strings ??= Regex.Split(_keyFrames[0].Value.ToString(CultureInfo.InvariantCulture), RegularPatterns.DigitsPattern);
return _strings ??= Regex.Split(_keyFrames[0].Value.ToString(CultureInfo.InvariantCulture), RegexPatterns.DigitsPattern);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static DoubleAnimation CreateAnimation(double toValue, double millisecond

internal static void DecomposeGeometryStr(string geometryStr, out double[] arr)
{
var collection = Regex.Matches(geometryStr, RegularPatterns.DigitsPattern);
var collection = Regex.Matches(geometryStr, RegexPatterns.DigitsPattern);
arr = new double[collection.Count];
for (var i = 0; i < collection.Count; i++)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ namespace HandyControl.Tools
/// <summary>
/// 包含一些正则验证操作
/// </summary>
public static class RegularJudgment
public static class RegexJudgment
{
private static readonly RegularPatterns RegularPatterns = new RegularPatterns();
private static readonly RegexPatterns RegexPatterns = new RegexPatterns();

/// <summary>
/// 判断字符串格式是否符合某种要求
Expand All @@ -32,7 +32,7 @@ public static bool IsKindOf(this string text, TextType textType)
{
if (textType == TextType.Common) return true;
return Regex.IsMatch(text,
RegularPatterns.GetValue(Enum.GetName(typeof(TextType), textType) + "Pattern").ToString());
RegexPatterns.GetValue(Enum.GetName(typeof(TextType), textType) + "Pattern").ToString());
}

/// <summary>
Expand All @@ -42,7 +42,7 @@ public static bool IsKindOf(this string text, TextType textType)
/// <returns>方法返回布尔值</returns>
public static bool IsEmail(this string email)
{
return Regex.IsMatch(email, RegularPatterns.MailPattern);
return Regex.IsMatch(email, RegexPatterns.MailPattern);
}

/// <summary>
Expand All @@ -55,11 +55,11 @@ public static bool IsIp(this string ip, IpType ipType)
{
switch (ipType)
{
case IpType.A: return Regex.IsMatch(ip, RegularPatterns.IpAPattern);
case IpType.B: return Regex.IsMatch(ip, RegularPatterns.IpBPattern);
case IpType.C: return Regex.IsMatch(ip, RegularPatterns.IpCPattern);
case IpType.D: return Regex.IsMatch(ip, RegularPatterns.IpDPattern);
case IpType.E: return Regex.IsMatch(ip, RegularPatterns.IpEPattern);
case IpType.A: return Regex.IsMatch(ip, RegexPatterns.IpAPattern);
case IpType.B: return Regex.IsMatch(ip, RegexPatterns.IpBPattern);
case IpType.C: return Regex.IsMatch(ip, RegexPatterns.IpCPattern);
case IpType.D: return Regex.IsMatch(ip, RegexPatterns.IpDPattern);
case IpType.E: return Regex.IsMatch(ip, RegexPatterns.IpEPattern);
default: return false;
}
}
Expand All @@ -71,7 +71,7 @@ public static bool IsIp(this string ip, IpType ipType)
/// <returns>方法返回布尔值</returns>
public static bool IsIp(this string ip)
{
return Regex.IsMatch(ip, RegularPatterns.IpPattern);
return Regex.IsMatch(ip, RegexPatterns.IpPattern);
}

/// <summary>
Expand All @@ -81,7 +81,7 @@ public static bool IsIp(this string ip)
/// <returns>方法返回布尔值</returns>
public static bool IsChinese(this string str)
{
return Regex.IsMatch(str, RegularPatterns.ChinesePattern);
return Regex.IsMatch(str, RegexPatterns.ChinesePattern);
}

/// <summary>
Expand All @@ -91,7 +91,7 @@ public static bool IsChinese(this string str)
/// <returns>方法返回布尔值</returns>
public static bool IsUrl(this string str)
{
return Regex.IsMatch(str, RegularPatterns.UrlPattern);
return Regex.IsMatch(str, RegexPatterns.UrlPattern);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/// <summary>
/// 包含一些正则验证所需要的字符串
/// </summary>
public sealed class RegularPatterns
public sealed class RegexPatterns
{
/// <summary>
/// 邮件正则匹配表达式
Expand Down

0 comments on commit 6c61113

Please sign in to comment.