mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-22 20:37:19 -08:00
feature<WorkingCopy>: finish recent commit message picker
This commit is contained in:
parent
88b9b0fb2f
commit
b40ca42d73
6 changed files with 45 additions and 28 deletions
|
@ -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<int, bool> IsZero =
|
||||
new FuncValueConverter<int, bool>(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<int, bool> IsOne =
|
||||
new FuncValueConverter<int, bool>(v => v == 1);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -446,7 +446,7 @@
|
|||
<TextBlock Grid.Column="0" Margin="8,0" FontWeight="Bold" Foreground="{DynamicResource Brush.FG3}" Text="{DynamicResource Text.Conflict.Tip}"/>
|
||||
<Button Grid.Column="1" Classes="flat" FontWeight="Regular" Content="{DynamicResource Text.Repository.Resolve}" Height="20" Padding="8,0" Margin="4,0" Command="{Binding GotoResolve}">
|
||||
<Button.IsVisible>
|
||||
<Binding Path="SelectedViewIndex" Converter="{x:Static c:IntConverters.NotEqual}" ConverterParameter="{v:Int 1}"/>
|
||||
<Binding Path="SelectedViewIndex" Converter="{x:Static c:IntConverters.IsOne}"/>
|
||||
</Button.IsVisible>
|
||||
</Button>
|
||||
<Button Grid.Column="2" Classes="flat primary" FontWeight="Regular" Content="{DynamicResource Text.Repository.Continue}" Height="20" Padding="8,0" Margin="4,0" Command="{Binding ContinueMerge}" IsVisible="{Binding !HasUnsolvedConflict}"/>
|
||||
|
|
|
@ -354,6 +354,7 @@
|
|||
<Button Grid.Column="0"
|
||||
Classes="icon_button"
|
||||
Width="14" Height="14"
|
||||
Click="OnOpenCommitMessagePicker"
|
||||
ToolTip.Tip="{DynamicResource Text.WorkingCopy.MessageHistories}">
|
||||
<Path Width="14" Height="14" Fill="{DynamicResource Brush.FG2}" Data="{StaticResource Icons.List}"/>
|
||||
</Button>
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue