feat: add clear history button to commit message template/history dropdown (#1756)

* feat: add clear history button to commit message template/history dropdown

- Added ClearCommitMessageHistory method to WorkingCopy ViewModel with user confirmation
- Added "Clear History" menu item to commit message picker dropdown
- Implemented thread-safe collection clearing using Dispatcher.UIThread.Invoke
- Added localization support for clear history button and confirmation dialog
- Follows existing codebase patterns for destructive operations with async/await

* fix: dotnet format
This commit is contained in:
ギャップ
2025-08-22 09:44:38 +02:00
committed by GitHub
parent e2cd5bac7b
commit c40296946d
3 changed files with 26 additions and 0 deletions

View File

@@ -856,6 +856,8 @@
<x:String x:Key="Text.WorkingCopy.IncludeUntracked" xml:space="preserve">INCLUDE UNTRACKED FILES</x:String>
<x:String x:Key="Text.WorkingCopy.NoCommitHistories" xml:space="preserve">NO RECENT INPUT MESSAGES</x:String>
<x:String x:Key="Text.WorkingCopy.NoCommitTemplates" xml:space="preserve">NO COMMIT TEMPLATES</x:String>
<x:String x:Key="Text.WorkingCopy.ClearCommitHistories" xml:space="preserve">Clear History</x:String>
<x:String x:Key="Text.WorkingCopy.ConfirmClearHistories" xml:space="preserve">Are you sure you want to clear all commit message history? This action cannot be undone.</x:String>
<x:String x:Key="Text.WorkingCopy.ResetAuthor" xml:space="preserve">Reset Author</x:String>
<x:String x:Key="Text.WorkingCopy.SignOff" xml:space="preserve">SignOff</x:String>
<x:String x:Key="Text.WorkingCopy.Staged" xml:space="preserve">STAGED</x:String>

View File

@@ -606,6 +606,15 @@ namespace SourceGit.ViewModels
CommitMessage = tmpl.Apply(_repo.CurrentBranch, _staged);
}
public async Task ClearCommitMessageHistory()
{
if (await App.AskConfirmAsync(App.Text("WorkingCopy.ConfirmClearHistories")))
Dispatcher.UIThread.Invoke(() =>
{
_repo.Settings.CommitMessages.Clear();
});
}
public async Task CommitAsync(bool autoStage, bool autoPush, Models.CommitCheckPassed checkPassed = Models.CommitCheckPassed.None)
{
if (string.IsNullOrWhiteSpace(_commitMessage))

View File

@@ -269,6 +269,21 @@ namespace SourceGit.Views
menu.Items.Add(item);
}
menu.Items.Add(new MenuItem() { Header = "-" });
var clearHistoryItem = new MenuItem()
{
Header = App.Text("WorkingCopy.ClearCommitHistories"),
Icon = App.CreateMenuIcon("Icons.Clear")
};
clearHistoryItem.Click += async (_, e) =>
{
await vm.ClearCommitMessageHistory();
e.Handled = true;
};
menu.Items.Add(clearHistoryItem);
}
menu.Placement = PlacementMode.TopEdgeAlignedLeft;