feature: shows the git configured commit template in Template/Histories popup (#846)

This commit is contained in:
leo 2024-12-30 19:40:58 +08:00
parent 8d12227227
commit 82fc261743
No known key found for this signature in database

View file

@ -1351,8 +1351,9 @@ namespace SourceGit.ViewModels
{ {
var menu = new ContextMenu(); var menu = new ContextMenu();
var gitTemplate = new Commands.Config(_repo.FullPath).Get("commit.template");
var templateCount = _repo.Settings.CommitTemplates.Count; var templateCount = _repo.Settings.CommitTemplates.Count;
if (templateCount == 0) if (templateCount == 0 && string.IsNullOrEmpty(gitTemplate))
{ {
menu.Items.Add(new MenuItem() menu.Items.Add(new MenuItem()
{ {
@ -1376,6 +1377,29 @@ namespace SourceGit.ViewModels
}; };
menu.Items.Add(item); menu.Items.Add(item);
} }
if (!string.IsNullOrEmpty(gitTemplate))
{
var friendlyName = gitTemplate;
if (!OperatingSystem.IsWindows())
{
var home = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
var prefixLen = home.EndsWith('/') ? home.Length - 1 : home.Length;
if (gitTemplate.StartsWith(home, StringComparison.Ordinal))
friendlyName = "~" + gitTemplate.Substring(prefixLen);
}
var gitTemplateItem = new MenuItem();
gitTemplateItem.Header = new Views.NameHighlightedTextBlock("WorkingCopy.UseCommitTemplate", friendlyName);
gitTemplateItem.Icon = App.CreateMenuIcon("Icons.Code");
gitTemplateItem.Click += (_, e) =>
{
if (File.Exists(gitTemplate))
CommitMessage = File.ReadAllText(gitTemplate);
e.Handled = true;
};
menu.Items.Add(gitTemplateItem);
}
} }
menu.Items.Add(new MenuItem() { Header = "-" }); menu.Items.Add(new MenuItem() { Header = "-" });