Skip to content

Commit c402969

Browse files
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
1 parent e2cd5ba commit c402969

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

src/Resources/Locales/en_US.axaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,8 @@
856856
<x:String x:Key="Text.WorkingCopy.IncludeUntracked" xml:space="preserve">INCLUDE UNTRACKED FILES</x:String>
857857
<x:String x:Key="Text.WorkingCopy.NoCommitHistories" xml:space="preserve">NO RECENT INPUT MESSAGES</x:String>
858858
<x:String x:Key="Text.WorkingCopy.NoCommitTemplates" xml:space="preserve">NO COMMIT TEMPLATES</x:String>
859+
<x:String x:Key="Text.WorkingCopy.ClearCommitHistories" xml:space="preserve">Clear History</x:String>
860+
<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>
859861
<x:String x:Key="Text.WorkingCopy.ResetAuthor" xml:space="preserve">Reset Author</x:String>
860862
<x:String x:Key="Text.WorkingCopy.SignOff" xml:space="preserve">SignOff</x:String>
861863
<x:String x:Key="Text.WorkingCopy.Staged" xml:space="preserve">STAGED</x:String>

src/ViewModels/WorkingCopy.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,15 @@ public void ApplyCommitMessageTemplate(Models.CommitTemplate tmpl)
606606
CommitMessage = tmpl.Apply(_repo.CurrentBranch, _staged);
607607
}
608608

609+
public async Task ClearCommitMessageHistory()
610+
{
611+
if (await App.AskConfirmAsync(App.Text("WorkingCopy.ConfirmClearHistories")))
612+
Dispatcher.UIThread.Invoke(() =>
613+
{
614+
_repo.Settings.CommitMessages.Clear();
615+
});
616+
}
617+
609618
public async Task CommitAsync(bool autoStage, bool autoPush, Models.CommitCheckPassed checkPassed = Models.CommitCheckPassed.None)
610619
{
611620
if (string.IsNullOrWhiteSpace(_commitMessage))

src/Views/CommitMessageTextBox.axaml.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,21 @@ private async void OnOpenCommitMessagePicker(object sender, RoutedEventArgs e)
269269

270270
menu.Items.Add(item);
271271
}
272+
273+
menu.Items.Add(new MenuItem() { Header = "-" });
274+
275+
var clearHistoryItem = new MenuItem()
276+
{
277+
Header = App.Text("WorkingCopy.ClearCommitHistories"),
278+
Icon = App.CreateMenuIcon("Icons.Clear")
279+
};
280+
clearHistoryItem.Click += async (_, e) =>
281+
{
282+
await vm.ClearCommitMessageHistory();
283+
e.Handled = true;
284+
};
285+
286+
menu.Items.Add(clearHistoryItem);
272287
}
273288

274289
menu.Placement = PlacementMode.TopEdgeAlignedLeft;

0 commit comments

Comments
 (0)