diff --git a/src/Models/Hyperlink.cs b/src/Models/Hyperlink.cs new file mode 100644 index 00000000..3abcf9ae --- /dev/null +++ b/src/Models/Hyperlink.cs @@ -0,0 +1,31 @@ +using Avalonia.Controls.Documents; + +namespace SourceGit.Models +{ + public class Hyperlink + { + public int Start { get; set; } = 0; + public int Length { get; set; } = 0; + public string Link { get; set; } = ""; + public bool IsCommitSHA { get; set; } = false; + + public Hyperlink(int start, int length, string link, bool isCommitSHA = false) + { + Start = start; + Length = length; + Link = link; + IsCommitSHA = isCommitSHA; + } + + public bool Intersect(int start, int length) + { + if (start == Start) + return true; + + if (start < Start) + return start + length > Start; + + return start < Start + Length; + } + } +} diff --git a/src/Models/IssueTrackerRule.cs b/src/Models/IssueTrackerRule.cs index 618fa166..29487a16 100644 --- a/src/Models/IssueTrackerRule.cs +++ b/src/Models/IssueTrackerRule.cs @@ -1,29 +1,10 @@ using System.Collections.Generic; using System.Text.RegularExpressions; -using Avalonia.Controls.Documents; + using CommunityToolkit.Mvvm.ComponentModel; namespace SourceGit.Models { - public class IssueTrackerMatch - { - public int Start { get; set; } = 0; - public int Length { get; set; } = 0; - public string URL { get; set; } = ""; - public Run Link { get; set; } = null; - - public bool Intersect(int start, int length) - { - if (start == Start) - return true; - - if (start < Start) - return start + length > Start; - - return start < Start + Length; - } - } - public class IssueTrackerRule : ObservableObject { public string Name @@ -65,7 +46,7 @@ namespace SourceGit.Models set => SetProperty(ref _urlTemplate, value); } - public void Matches(List outs, string message) + public void Matches(List outs, string message) { if (_regex == null || string.IsNullOrEmpty(_urlTemplate)) return; @@ -92,17 +73,15 @@ namespace SourceGit.Models if (intersect) continue; - var range = new IssueTrackerMatch(); - range.Start = start; - range.Length = len; - range.URL = _urlTemplate; + var link = _urlTemplate; for (var j = 1; j < match.Groups.Count; j++) { var group = match.Groups[j]; if (group.Success) - range.URL = range.URL.Replace($"${j}", group.Value); + link = link.Replace($"${j}", group.Value); } + var range = new Hyperlink(start, len, link); outs.Add(range); } } diff --git a/src/Models/RepositorySettings.cs b/src/Models/RepositorySettings.cs index da7c1ff4..06e60a87 100644 --- a/src/Models/RepositorySettings.cs +++ b/src/Models/RepositorySettings.cs @@ -125,19 +125,6 @@ namespace SourceGit.Models return rule; } - public IssueTrackerRule AddCommitLinkIssueTracker() - { - var rule = new IssueTrackerRule() - { - Name = "Commit Link", - RegexString = @"\b([0-9a-fA-F]{8,40})\b", - URLTemplate = "https://test/$1", - }; - - IssueTrackerRules.Add(rule); - return rule; - } - public IssueTrackerRule AddGithubIssueTracker(string repoURL) { var rule = new IssueTrackerRule() diff --git a/src/Resources/Locales/en_US.axaml b/src/Resources/Locales/en_US.axaml index 9e837768..88634189 100644 --- a/src/Resources/Locales/en_US.axaml +++ b/src/Resources/Locales/en_US.axaml @@ -131,7 +131,6 @@ Email address GIT ISSUE TRACKER - Add Sample Commit HASH Rule Add Sample Github Rule Add Sample Jira Rule New Rule diff --git a/src/Resources/Locales/zh_CN.axaml b/src/Resources/Locales/zh_CN.axaml index 4aa29cc7..b7c3e5d1 100644 --- a/src/Resources/Locales/zh_CN.axaml +++ b/src/Resources/Locales/zh_CN.axaml @@ -134,7 +134,6 @@ 邮箱地址 GIT配置 ISSUE追踪 - 新增匹配提交HASH规则 新增匹配Github Issue规则 新增匹配Jira规则 新增自定义规则 diff --git a/src/Resources/Locales/zh_TW.axaml b/src/Resources/Locales/zh_TW.axaml index 16728c86..6d51c588 100644 --- a/src/Resources/Locales/zh_TW.axaml +++ b/src/Resources/Locales/zh_TW.axaml @@ -134,7 +134,6 @@ 郵箱地址 GIT配置 ISSUE追蹤 - 新增匹配提交HASH規則 新增匹配Github Issue規則 新增匹配Jira規則 新增自定義規則 diff --git a/src/Resources/Styles.axaml b/src/Resources/Styles.axaml index 535d1c44..30ce7083 100644 --- a/src/Resources/Styles.axaml +++ b/src/Resources/Styles.axaml @@ -284,6 +284,10 @@ +