diff --git a/src/Models/CommitTemplate.cs b/src/Models/CommitTemplate.cs new file mode 100644 index 00000000..d67d4839 --- /dev/null +++ b/src/Models/CommitTemplate.cs @@ -0,0 +1,22 @@ +using CommunityToolkit.Mvvm.ComponentModel; + +namespace SourceGit.Models +{ + public class CommitTemplate : ObservableObject + { + public string Name + { + get => _name; + set => SetProperty(ref _name, value); + } + + public string Content + { + get => _content; + set => SetProperty(ref _content, value); + } + + private string _name = string.Empty; + private string _content = string.Empty; + } +} diff --git a/src/Models/RepositorySettings.cs b/src/Models/RepositorySettings.cs index bf15c4f4..788e00a8 100644 --- a/src/Models/RepositorySettings.cs +++ b/src/Models/RepositorySettings.cs @@ -70,6 +70,12 @@ namespace SourceGit.Models set; } = new AvaloniaList(); + public AvaloniaList CommitTemplates + { + get; + set; + } = new AvaloniaList(); + public AvaloniaList CommitMessages { get; diff --git a/src/Resources/Icons.axaml b/src/Resources/Icons.axaml index 5f148b50..46f229b9 100644 --- a/src/Resources/Icons.axaml +++ b/src/Resources/Icons.axaml @@ -12,7 +12,9 @@ M512 57c251 0 455 204 455 455S763 967 512 967 57 763 57 512 261 57 512 57zm181 274c-11-11-29-11-40 0L512 472 371 331c-11-11-29-11-40 0-11 11-11 29 0 40L471 512 331 653c-11 11-11 29 0 40 11 11 29 11 40 0l141-141 141 141c11 11 29 11 40 0 11-11 11-29 0-40L552 512l141-141c11-11 11-29 0-40z M797 829a49 49 0 1049 49 49 49 0 00-49-49zm147-114A49 49 0 10992 764a49 49 0 00-49-49zM928 861a49 49 0 1049 49A49 49 0 00928 861zm-5-586L992 205 851 64l-71 71a67 67 0 00-94 0l235 235a67 67 0 000-94zm-853 128a32 32 0 00-32 50 1291 1291 0 0075 112L288 552c20 0 25 21 8 37l-93 86a1282 1282 0 00120 114l100-32c19-6 28 15 14 34l-40 55c26 19 53 36 82 53a89 89 0 00115-20 1391 1391 0 00256-485l-188-188s-306 224-595 198z M1280 704c0 141-115 256-256 256H288C129 960 0 831 0 672c0-126 80-232 192-272A327 327 0 01192 384c0-177 143-320 320-320 119 0 222 64 277 160C820 204 857 192 896 192c106 0 192 86 192 192 0 24-5 48-13 69C1192 477 1280 580 1280 704zm-493-128H656V352c0-18-14-32-32-32h-96c-18 0-32 14-32 32v224h-131c-29 0-43 34-23 55l211 211c12 12 33 12 45 0l211-211c20-20 6-55-23-55z + M853 102H171C133 102 102 133 102 171v683C102 891 133 922 171 922h683C891 922 922 891 922 853V171C922 133 891 102 853 102zM390 600l-48 48L205 512l137-137 48 48L301 512l88 88zM465 819l-66-18L559 205l66 18L465 819zm218-171L634 600 723 512l-88-88 48-48L819 512 683 649z M796 471A292 292 0 00512 256a293 293 0 00-284 215H0v144h228A293 293 0 00512 832a291 291 0 00284-217H1024V471h-228M512 688A146 146 0 01366 544A145 145 0 01512 400c80 0 146 63 146 144A146 146 0 01512 688 + M796 561a5 5 0 014 7l-39 90a5 5 0 004 7h100a5 5 0 014 8l-178 247a5 5 0 01-9-4l32-148a5 5 0 00-5-6h-89a5 5 0 01-4-7l86-191a5 5 0 014-3h88zM731 122a73 73 0 0173 73v318a54 54 0 00-8-1h-88a54 54 0 00-49 32l-86 191a54 54 0 00-5 22l0 4a54 54 0 0053 50h35L636 902H244a73 73 0 01-73-73V195a73 73 0 0173-73h488zm-219 366h-195v73h195v-73zm146-146H317v73h341v-73z M645 448l64 64 220-221L704 64l-64 64 115 115H128v90h628zM375 576l-64-64-220 224L314 960l64-64-116-115H896v-90H262z M608 0q48 0 88 23t63 63 23 87v70h55q35 0 67 14t57 38 38 57 14 67V831q0 34-14 66t-38 57-57 38-67 13H426q-34 0-66-13t-57-38-38-57-14-66v-70h-56q-34 0-66-14t-57-38-38-57-13-67V174q0-47 23-87T109 23 196 0h412m175 244H426q-46 0-86 22T278 328t-26 85v348H608q47 0 86-22t63-62 25-85l1-348m-269 318q18 0 31 13t13 31-13 31-31 13-31-13-13-31 13-31 31-13m0-212q13 0 22 9t11 22v125q0 14-9 23t-22 10-23-7-11-22l-1-126q0-13 10-23t23-10z M896 811l-128 0c-23 0-43-19-43-43 0-23 19-43 43-43l107 0c13 0 21-9 21-21L896 107c0-13-9-21-21-21L448 85c-13 0-21 9-21 21l0 21c0 23-19 43-43 43-23 0-43-19-43-43L341 85c0-47 38-85 85-85l469 0c47 0 85 38 85 85l0 640C981 772 943 811 896 811zM683 299l0 640c0 47-38 85-85 85L128 1024c-47 0-85-38-85-85L43 299c0-47 38-85 85-85l469 0C644 213 683 252 683 299zM576 299 149 299c-13 0-21 9-21 21l0 597c0 13 9 21 21 21l427 0c13 0 21-9 21-21L597 320C597 307 589 299 576 299z diff --git a/src/Resources/Locales/de_DE.axaml b/src/Resources/Locales/de_DE.axaml index 95c61443..c656a869 100644 --- a/src/Resources/Locales/de_DE.axaml +++ b/src/Resources/Locales/de_DE.axaml @@ -595,9 +595,7 @@ STRG + Enter KONFLIKTE ERKANNT DATEI KONFLIKTE GELÖST - LETZTE COMMIT-NACHRICHTEN NICHT-VERFOLGTE DATEIEN INKLUDIEREN - NACHRICHTEN HISTORIE KEINE BISHERIGEN COMMIT-NACHRICHTEN GESTAGED UNSTAGEN diff --git a/src/Resources/Locales/en_US.axaml b/src/Resources/Locales/en_US.axaml index 37d046de..d8a6b4e9 100644 --- a/src/Resources/Locales/en_US.axaml +++ b/src/Resources/Locales/en_US.axaml @@ -122,6 +122,9 @@ Enter commit subject Description Repository Configure + COMMIT TEMPLATE + Template Name: + Template Content: Email Address Email address GIT @@ -589,13 +592,13 @@ You can stage this file now. COMMIT COMMIT & PUSH + Template/Histories CTRL + Enter CONFLICTS DETECTED FILE CONFLICTS ARE RESOLVED - RECENT INPUT MESSAGES INCLUDE UNTRACKED FILES - MESSAGE HISTORIES NO RECENT INPUT MESSAGES + NO COMMIT TEMPLATES STAGED UNSTAGE UNSTAGE ALL @@ -603,6 +606,7 @@ STAGE STAGE ALL VIEW ASSUME UNCHANGED + Template: ${0}$ Right-click the selected file(s), and make your choice to resolve conflicts. WORKTREE Copy Path diff --git a/src/Resources/Locales/pt_BR.axaml b/src/Resources/Locales/pt_BR.axaml index 69574263..71c42efd 100644 --- a/src/Resources/Locales/pt_BR.axaml +++ b/src/Resources/Locales/pt_BR.axaml @@ -581,9 +581,7 @@ CTRL + Enter CONFLITOS DETECTADOS CONFLITOS DE ARQUIVOS RESOLVIDOS - MENSAGENS RECENTES DE ENTRADA INCLUIR ARQUIVOS NÃO RASTREADOS - HISTÓRICO DE MENSAGENS NENHUMA MENSAGEM DE ENTRADA RECENTE STAGED DESSTAGEAR diff --git a/src/Resources/Locales/zh_CN.axaml b/src/Resources/Locales/zh_CN.axaml index cbd82bd8..742fcb80 100644 --- a/src/Resources/Locales/zh_CN.axaml +++ b/src/Resources/Locales/zh_CN.axaml @@ -125,6 +125,9 @@ 填写提交信息主题 详细描述 仓库配置 + 提交信息模板 + 模板名 : + 模板内容 : 电子邮箱 邮箱地址 GIT配置 @@ -591,13 +594,13 @@ 现在您已可将其加入暂存区中 提交 提交并推送 + 历史输入/模板 CTRL + Enter 检测到冲突 文件冲突已解决 - 最近输入的提交信息 显示未跟踪文件 - 历史提交信息 没有提交信息记录 + 没有可应用的提交信息模板 已暂存 从暂存区移除选中 从暂存区移除所有 @@ -605,6 +608,7 @@ 暂存选中 暂存所有 查看忽略变更文件 + 模板:${0}$ 请选中冲突文件,打开右键菜单,选择合适的解决方式 本地工作树 复制工作树路径 diff --git a/src/Resources/Locales/zh_TW.axaml b/src/Resources/Locales/zh_TW.axaml index 75fd2753..5ff3ff58 100644 --- a/src/Resources/Locales/zh_TW.axaml +++ b/src/Resources/Locales/zh_TW.axaml @@ -125,6 +125,9 @@ 填寫提交信息主題 詳細描述 倉庫配置 + 提交資訊範本 + 範本名稱 : + 範本內容 : 電子郵箱 郵箱地址 GIT配置 @@ -591,13 +594,13 @@ 現在您已可將其加入暫存區中 提交 提交併推送 + 歷史輸入/範本 CTRL + Enter 檢測到衝突 檔案衝突已解決 - 最近輸入的提交資訊 顯示未跟蹤檔案 - 歷史提交資訊 沒有提交資訊記錄 + 沒有可應用的提交資訊範本 已暫存 從暫存區移除選中 從暫存區移除所有 @@ -605,6 +608,7 @@ 暫存選中 暫存所有 檢視忽略變更檔案 + 範本:${0}$ 請選中衝突檔案,開啟右鍵選單,選擇合適的解決方式 本地工作樹 拷贝工作樹路徑 diff --git a/src/ViewModels/RepositoryConfigure.cs b/src/ViewModels/RepositoryConfigure.cs index f252a075..b72345ee 100644 --- a/src/ViewModels/RepositoryConfigure.cs +++ b/src/ViewModels/RepositoryConfigure.cs @@ -42,6 +42,17 @@ namespace SourceGit.ViewModels set => SetProperty(ref _httpProxy, value); } + public AvaloniaList CommitTemplates + { + get => _repo.Settings.CommitTemplates; + } + + public Models.CommitTemplate SelectedCommitTemplate + { + get => _selectedCommitTemplate; + set => SetProperty(ref _selectedCommitTemplate, value); + } + public AvaloniaList IssueTrackerRules { get => _repo.Settings.IssueTrackerRules; @@ -77,6 +88,20 @@ namespace SourceGit.ViewModels HttpProxy = string.Empty; } + public void AddCommitTemplate() + { + var template = new Models.CommitTemplate() { Name = "New Template" }; + _repo.Settings.CommitTemplates.Add(template); + SelectedCommitTemplate = template; + } + + public void RemoveSelectedCommitTemplate() + { + if (_selectedCommitTemplate != null) + _repo.Settings.CommitTemplates.Remove(_selectedCommitTemplate); + SelectedCommitTemplate = null; + } + public void AddSampleGithubIssueTracker() { foreach (var remote in _repo.Remotes) @@ -106,7 +131,8 @@ namespace SourceGit.ViewModels public void RemoveSelectedIssueTracker() { - _repo.Settings.RemoveIssueTracker(_selectedIssueTrackerRule); + if (_selectedIssueTrackerRule != null) + _repo.Settings.RemoveIssueTracker(_selectedIssueTrackerRule); SelectedIssueTrackerRule = null; } @@ -141,6 +167,7 @@ namespace SourceGit.ViewModels private readonly Repository _repo = null; private readonly Dictionary _cached = null; private string _httpProxy; + private Models.CommitTemplate _selectedCommitTemplate = null; private Models.IssueTrackerRule _selectedIssueTrackerRule = null; } } diff --git a/src/ViewModels/WorkingCopy.cs b/src/ViewModels/WorkingCopy.cs index 36ab33ca..9f795921 100644 --- a/src/ViewModels/WorkingCopy.cs +++ b/src/ViewModels/WorkingCopy.cs @@ -1127,34 +1127,62 @@ namespace SourceGit.ViewModels public ContextMenu CreateContextMenuForCommitMessages() { var menu = new ContextMenu(); - if (_repo.Settings.CommitMessages.Count == 0) + + var templateCount = _repo.Settings.CommitTemplates.Count; + if (templateCount == 0) { - var empty = new MenuItem(); - empty.Header = App.Text("WorkingCopy.NoCommitHistories"); - empty.IsEnabled = false; - menu.Items.Add(empty); - return menu; + menu.Items.Add(new MenuItem() + { + Header = App.Text("WorkingCopy.NoCommitTemplates"), + Icon = App.CreateMenuIcon("Icons.Code"), + IsEnabled = false + }); + } + else + { + for (int i = 0; i < templateCount; i++) + { + var template = _repo.Settings.CommitTemplates[i]; + var item = new MenuItem(); + item.Header = new Views.NameHighlightedTextBlock("WorkingCopy.UseCommitTemplate", template.Name); + item.Icon = App.CreateMenuIcon("Icons.Code"); + item.Click += (_, e) => + { + CommitMessage = template.Content; + e.Handled = true; + }; + menu.Items.Add(item); + } } - var tip = new MenuItem(); - tip.Header = App.Text("WorkingCopy.HasCommitHistories"); - tip.IsEnabled = false; - menu.Items.Add(tip); menu.Items.Add(new MenuItem() { Header = "-" }); - foreach (var message in _repo.Settings.CommitMessages) + var historiesCount = _repo.Settings.CommitMessages.Count; + if (historiesCount == 0) { - var dump = message; - - var item = new MenuItem(); - item.Header = dump; - item.Click += (_, e) => + menu.Items.Add(new MenuItem() { - CommitMessage = dump; - e.Handled = true; - }; + Header = App.Text("WorkingCopy.NoCommitHistories"), + Icon = App.CreateMenuIcon("Icons.Histories"), + IsEnabled = false + }); + } + else + { + for (int i = 0; i < historiesCount; i++) + { + var message = _repo.Settings.CommitMessages[i]; + var item = new MenuItem(); + item.Header = message; + item.Icon = App.CreateMenuIcon("Icons.Histories"); + item.Click += (_, e) => + { + CommitMessage = message; + e.Handled = true; + }; - menu.Items.Add(item); + menu.Items.Add(item); + } } return menu; diff --git a/src/Views/RepositoryConfigure.axaml b/src/Views/RepositoryConfigure.axaml index 79bd7a85..5ecaee22 100644 --- a/src/Views/RepositoryConfigure.axaml +++ b/src/Views/RepositoryConfigure.axaml @@ -112,6 +112,91 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Views/WorkingCopy.axaml b/src/Views/WorkingCopy.axaml index 4727ce20..7acba84a 100644 --- a/src/Views/WorkingCopy.axaml +++ b/src/Views/WorkingCopy.axaml @@ -176,10 +176,12 @@