From b40ca42d73af7de40f42b13ba2e6594750be6367 Mon Sep 17 00:00:00 2001 From: leo Date: Sun, 18 Feb 2024 15:44:05 +0800 Subject: [PATCH] feature: finish recent commit message picker --- src/Converters/IntConverters.cs | 17 ++--------------- src/ViewModels/WorkingCopy.cs | 32 ++++++++++++++++++++++++++++++++ src/Views/Extensions.cs | 12 ------------ src/Views/Repository.axaml | 2 +- src/Views/WorkingCopy.axaml | 1 + src/Views/WorkingCopy.axaml.cs | 9 +++++++++ 6 files changed, 45 insertions(+), 28 deletions(-) delete mode 100644 src/Views/Extensions.cs diff --git a/src/Converters/IntConverters.cs b/src/Converters/IntConverters.cs index 95f4a57a..4a97a90d 100644 --- a/src/Converters/IntConverters.cs +++ b/src/Converters/IntConverters.cs @@ -1,6 +1,4 @@ using Avalonia.Data.Converters; -using System; -using System.Globalization; namespace SourceGit.Converters { public static class IntConverters { @@ -10,18 +8,7 @@ namespace SourceGit.Converters { public static FuncValueConverter IsZero = new FuncValueConverter(v => v == 0); - public class NotEqualConverter : IValueConverter { - public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { - int v = (int)value; - int target = (int)parameter; - return v != target; - } - - public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { - throw new NotImplementedException(); - } - } - - public static NotEqualConverter NotEqual = new NotEqualConverter(); + public static FuncValueConverter IsOne = + new FuncValueConverter(v => v == 1); } } diff --git a/src/ViewModels/WorkingCopy.cs b/src/ViewModels/WorkingCopy.cs index a6ef0bb4..6fc6e39d 100644 --- a/src/ViewModels/WorkingCopy.cs +++ b/src/ViewModels/WorkingCopy.cs @@ -557,6 +557,38 @@ namespace SourceGit.ViewModels { return menu; } + public ContextMenu CreateContextMenuForCommitMessages() { + var menu = new ContextMenu(); + if (_repo.CommitMessages.Count == 0) { + var empty = new MenuItem(); + empty.Header = App.Text("WorkingCopy.NoCommitHistories"); + empty.IsEnabled = false; + menu.Items.Add(empty); + return menu; + } + + 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.CommitMessages) { + var dump = message; + + var item = new MenuItem(); + item.Header = dump; + item.Click += (o, e) => { + CommitMessage = dump; + e.Handled = true; + }; + + menu.Items.Add(item); + } + + return menu; + } + private Avalonia.Controls.Shapes.Path CreateMenuIcon(string key) { var icon = new Avalonia.Controls.Shapes.Path(); icon.Width = 12; diff --git a/src/Views/Extensions.cs b/src/Views/Extensions.cs deleted file mode 100644 index 9ce5ba1f..00000000 --- a/src/Views/Extensions.cs +++ /dev/null @@ -1,12 +0,0 @@ -using Avalonia.Markup.Xaml; -using System; - -namespace SourceGit.Views { - public class IntExtension : MarkupExtension { - public int Value { get; set; } - public IntExtension(int value) { this.Value = value; } - public override object ProvideValue(IServiceProvider serviceProvider) { - return Value; - } - } -} diff --git a/src/Views/Repository.axaml b/src/Views/Repository.axaml index db0dedf9..23c544c5 100644 --- a/src/Views/Repository.axaml +++ b/src/Views/Repository.axaml @@ -446,7 +446,7 @@ diff --git a/src/Views/WorkingCopy.axaml.cs b/src/Views/WorkingCopy.axaml.cs index a99e8258..dc58ee91 100644 --- a/src/Views/WorkingCopy.axaml.cs +++ b/src/Views/WorkingCopy.axaml.cs @@ -384,5 +384,14 @@ namespace SourceGit.Views { if (change != null && !outs.Contains(change)) outs.Add(change); } } + + private void OnOpenCommitMessagePicker(object sender, RoutedEventArgs e) { + if (sender is Button button && DataContext is ViewModels.WorkingCopy vm) { + var menu = vm.CreateContextMenuForCommitMessages(); + menu.Placement = PlacementMode.TopEdgeAlignedLeft; + menu.Open(button); + e.Handled = true; + } + } } }