mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-25 14:15:00 +00:00
refactor: commit message
- move issue tracker and commit hash links parsing to view models - parsing links async - make sure matched hash is a valid commit oid - disable `CHILDREN` row in submodule info panel Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
parent
5301a368e0
commit
b75676a7f8
17 changed files with 191 additions and 186 deletions
|
@ -95,8 +95,8 @@
|
|||
</StackPanel>
|
||||
|
||||
<!-- PARENTS -->
|
||||
<TextBlock Grid.Row="1" Grid.Column="0" Classes="info_label" VerticalAlignment="Top" Margin="0,4,0,0" Text="{DynamicResource Text.CommitDetail.Info.Parents}" IsVisible="{Binding Parents.Count, Converter={x:Static c:IntConverters.IsGreaterThanZero}}"/>
|
||||
<ItemsControl Grid.Row="1" Grid.Column="1" Height="24" Margin="12,0,0,0" ItemsSource="{Binding Parents}" IsVisible="{Binding Parents.Count, Converter={x:Static c:IntConverters.IsGreaterThanZero}}">
|
||||
<TextBlock Grid.Row="1" Grid.Column="0" Classes="info_label" VerticalAlignment="Top" Margin="0,4,0,0" Text="{DynamicResource Text.CommitDetail.Info.Parents}" IsVisible="{Binding Parents, Converter={x:Static c:ListConverters.IsNotNullOrEmpty}}"/>
|
||||
<ItemsControl Grid.Row="1" Grid.Column="1" Height="24" Margin="12,0,0,0" ItemsSource="{Binding Parents}" IsVisible="{Binding Parents, Converter={x:Static c:ListConverters.IsNotNullOrEmpty}}">
|
||||
<ItemsControl.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<StackPanel Orientation="Horizontal" VerticalAlignment="Center"/>
|
||||
|
@ -133,8 +133,8 @@
|
|||
</ItemsControl>
|
||||
|
||||
<!-- CHILDREN -->
|
||||
<TextBlock Grid.Row="2" Grid.Column="0" Classes="info_label" VerticalAlignment="Top" Margin="0,4,0,0" Text="{DynamicResource Text.CommitDetail.Info.Children}" IsVisible="{Binding #ThisControl.Children.Count, Converter={x:Static c:IntConverters.IsGreaterThanZero}}"/>
|
||||
<ItemsControl Grid.Row="2" Grid.Column="1" Margin="12,0,0,0" ItemsSource="{Binding #ThisControl.Children}" IsVisible="{Binding #ThisControl.Children.Count, Converter={x:Static c:IntConverters.IsGreaterThanZero}}">
|
||||
<TextBlock Grid.Row="2" Grid.Column="0" Classes="info_label" VerticalAlignment="Top" Margin="0,4,0,0" Text="{DynamicResource Text.CommitDetail.Info.Children}" IsVisible="{Binding #ThisControl.Children, Converter={x:Static c:ListConverters.IsNotNullOrEmpty}}"/>
|
||||
<ItemsControl Grid.Row="2" Grid.Column="1" Margin="12,0,0,0" ItemsSource="{Binding #ThisControl.Children}" IsVisible="{Binding #ThisControl.Children, Converter={x:Static c:ListConverters.IsNotNullOrEmpty}}">
|
||||
<ItemsControl.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<WrapPanel Orientation="Horizontal" VerticalAlignment="Center" ItemHeight="24"/>
|
||||
|
@ -187,8 +187,7 @@
|
|||
<v:CommitMessagePresenter Grid.Row="4" Grid.Column="1"
|
||||
Margin="12,4,8,0"
|
||||
Classes="primary"
|
||||
Message="{Binding #ThisControl.Message}"
|
||||
IssueTrackerRules="{Binding #ThisControl.IssueTrackerRules}"
|
||||
FullMessage="{Binding #ThisControl.FullMessage}"
|
||||
HorizontalAlignment="Stretch"
|
||||
TextWrapping="Wrap">
|
||||
<v:CommitMessagePresenter.DataTemplates>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Avalonia;
|
||||
using Avalonia.Collections;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Interactivity;
|
||||
|
@ -11,13 +11,13 @@ namespace SourceGit.Views
|
|||
{
|
||||
public partial class CommitBaseInfo : UserControl
|
||||
{
|
||||
public static readonly StyledProperty<string> MessageProperty =
|
||||
AvaloniaProperty.Register<CommitBaseInfo, string>(nameof(Message), string.Empty);
|
||||
public static readonly StyledProperty<Models.CommitFullMessage> FullMessageProperty =
|
||||
AvaloniaProperty.Register<CommitBaseInfo, Models.CommitFullMessage>(nameof(FullMessage));
|
||||
|
||||
public string Message
|
||||
public Models.CommitFullMessage FullMessage
|
||||
{
|
||||
get => GetValue(MessageProperty);
|
||||
set => SetValue(MessageProperty, value);
|
||||
get => GetValue(FullMessageProperty);
|
||||
set => SetValue(FullMessageProperty, value);
|
||||
}
|
||||
|
||||
public static readonly StyledProperty<Models.CommitSignInfo> SignInfoProperty =
|
||||
|
@ -38,28 +38,19 @@ namespace SourceGit.Views
|
|||
set => SetValue(SupportsContainsInProperty, value);
|
||||
}
|
||||
|
||||
public static readonly StyledProperty<AvaloniaList<Models.CommitLink>> WebLinksProperty =
|
||||
AvaloniaProperty.Register<CommitBaseInfo, AvaloniaList<Models.CommitLink>>(nameof(WebLinks));
|
||||
public static readonly StyledProperty<List<Models.CommitLink>> WebLinksProperty =
|
||||
AvaloniaProperty.Register<CommitBaseInfo, List<Models.CommitLink>>(nameof(WebLinks));
|
||||
|
||||
public AvaloniaList<Models.CommitLink> WebLinks
|
||||
public List<Models.CommitLink> WebLinks
|
||||
{
|
||||
get => GetValue(WebLinksProperty);
|
||||
set => SetValue(WebLinksProperty, value);
|
||||
}
|
||||
|
||||
public static readonly StyledProperty<AvaloniaList<Models.IssueTrackerRule>> IssueTrackerRulesProperty =
|
||||
AvaloniaProperty.Register<CommitBaseInfo, AvaloniaList<Models.IssueTrackerRule>>(nameof(IssueTrackerRules));
|
||||
public static readonly StyledProperty<List<string>> ChildrenProperty =
|
||||
AvaloniaProperty.Register<CommitBaseInfo, List<string>>(nameof(Children));
|
||||
|
||||
public AvaloniaList<Models.IssueTrackerRule> IssueTrackerRules
|
||||
{
|
||||
get => GetValue(IssueTrackerRulesProperty);
|
||||
set => SetValue(IssueTrackerRulesProperty, value);
|
||||
}
|
||||
|
||||
public static readonly StyledProperty<AvaloniaList<string>> ChildrenProperty =
|
||||
AvaloniaProperty.Register<CommitBaseInfo, AvaloniaList<string>>(nameof(Children));
|
||||
|
||||
public AvaloniaList<string> Children
|
||||
public List<string> Children
|
||||
{
|
||||
get => GetValue(ChildrenProperty);
|
||||
set => SetValue(ChildrenProperty, value);
|
||||
|
|
|
@ -20,12 +20,11 @@
|
|||
<StackPanel Orientation="Vertical">
|
||||
<!-- Base Information -->
|
||||
<v:CommitBaseInfo Content="{Binding Commit}"
|
||||
Message="{Binding FullMessage}"
|
||||
FullMessage="{Binding FullMessage}"
|
||||
SignInfo="{Binding SignInfo}"
|
||||
SupportsContainsIn="True"
|
||||
WebLinks="{Binding WebLinks}"
|
||||
Children="{Binding Children}"
|
||||
IssueTrackerRules="{Binding IssueTrackerRules}"/>
|
||||
Children="{Binding Children}"/>
|
||||
|
||||
<!-- Line -->
|
||||
<Rectangle Height=".65" Margin="8" Fill="{DynamicResource Brush.Border2}"/>
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Avalonia;
|
||||
using Avalonia.Collections;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Documents;
|
||||
using Avalonia.Input;
|
||||
|
@ -13,27 +11,15 @@ using Avalonia.VisualTree;
|
|||
|
||||
namespace SourceGit.Views
|
||||
{
|
||||
public partial class CommitMessagePresenter : SelectableTextBlock
|
||||
public class CommitMessagePresenter : SelectableTextBlock
|
||||
{
|
||||
[GeneratedRegex(@"\b([0-9a-fA-F]{6,40})\b")]
|
||||
private static partial Regex REG_SHA_FORMAT();
|
||||
public static readonly StyledProperty<Models.CommitFullMessage> FullMessageProperty =
|
||||
AvaloniaProperty.Register<CommitMessagePresenter, Models.CommitFullMessage>(nameof(FullMessage));
|
||||
|
||||
public static readonly StyledProperty<string> MessageProperty =
|
||||
AvaloniaProperty.Register<CommitMessagePresenter, string>(nameof(Message));
|
||||
|
||||
public string Message
|
||||
public Models.CommitFullMessage FullMessage
|
||||
{
|
||||
get => GetValue(MessageProperty);
|
||||
set => SetValue(MessageProperty, value);
|
||||
}
|
||||
|
||||
public static readonly StyledProperty<AvaloniaList<Models.IssueTrackerRule>> IssueTrackerRulesProperty =
|
||||
AvaloniaProperty.Register<CommitMessagePresenter, AvaloniaList<Models.IssueTrackerRule>>(nameof(IssueTrackerRules));
|
||||
|
||||
public AvaloniaList<Models.IssueTrackerRule> IssueTrackerRules
|
||||
{
|
||||
get => GetValue(IssueTrackerRulesProperty);
|
||||
set => SetValue(IssueTrackerRulesProperty, value);
|
||||
get => GetValue(FullMessageProperty);
|
||||
set => SetValue(FullMessageProperty, value);
|
||||
}
|
||||
|
||||
protected override Type StyleKeyOverride => typeof(SelectableTextBlock);
|
||||
|
@ -42,69 +28,36 @@ namespace SourceGit.Views
|
|||
{
|
||||
base.OnPropertyChanged(change);
|
||||
|
||||
if (change.Property == MessageProperty || change.Property == IssueTrackerRulesProperty)
|
||||
if (change.Property == FullMessageProperty)
|
||||
{
|
||||
Inlines!.Clear();
|
||||
_inlineCommits.Clear();
|
||||
_matches = null;
|
||||
_lastHover = null;
|
||||
ClearHoveredIssueLink();
|
||||
|
||||
var message = Message;
|
||||
var message = FullMessage?.Message;
|
||||
if (string.IsNullOrEmpty(message))
|
||||
return;
|
||||
|
||||
var matches = new List<Models.Hyperlink>();
|
||||
if (IssueTrackerRules is { Count: > 0 } rules)
|
||||
{
|
||||
foreach (var rule in rules)
|
||||
rule.Matches(matches, message);
|
||||
}
|
||||
|
||||
var shas = REG_SHA_FORMAT().Matches(message);
|
||||
for (int i = 0; i < shas.Count; i++)
|
||||
{
|
||||
var sha = shas[i];
|
||||
if (!sha.Success)
|
||||
continue;
|
||||
|
||||
var start = sha.Index;
|
||||
var len = sha.Length;
|
||||
var intersect = false;
|
||||
foreach (var match in matches)
|
||||
{
|
||||
if (match.Intersect(start, len))
|
||||
{
|
||||
intersect = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!intersect)
|
||||
matches.Add(new Models.Hyperlink(start, len, sha.Groups[1].Value, true));
|
||||
}
|
||||
|
||||
if (matches.Count == 0)
|
||||
var links = FullMessage?.Links;
|
||||
if (links == null || links.Count == 0)
|
||||
{
|
||||
Inlines.Add(new Run(message));
|
||||
return;
|
||||
}
|
||||
|
||||
matches.Sort((l, r) => l.Start - r.Start);
|
||||
_matches = matches;
|
||||
|
||||
var inlines = new List<Inline>();
|
||||
var pos = 0;
|
||||
foreach (var match in matches)
|
||||
foreach (var link in links)
|
||||
{
|
||||
if (match.Start > pos)
|
||||
inlines.Add(new Run(message.Substring(pos, match.Start - pos)));
|
||||
if (link.Start > pos)
|
||||
inlines.Add(new Run(message.Substring(pos, link.Start - pos)));
|
||||
|
||||
var link = new Run(message.Substring(match.Start, match.Length));
|
||||
link.Classes.Add(match.IsCommitSHA ? "commit_link" : "issue_link");
|
||||
inlines.Add(link);
|
||||
var run = new Run(message.Substring(link.Start, link.Length));
|
||||
run.Classes.Add(link.IsCommitSHA ? "commit_link" : "issue_link");
|
||||
inlines.Add(run);
|
||||
|
||||
pos = match.Start + match.Length;
|
||||
pos = link.Start + link.Length;
|
||||
}
|
||||
|
||||
if (pos < message.Length)
|
||||
|
@ -134,7 +87,7 @@ namespace SourceGit.Views
|
|||
scrollViewer.LineDown();
|
||||
}
|
||||
}
|
||||
else if (_matches != null)
|
||||
else if (FullMessage is { Links: { Count: > 0 } links })
|
||||
{
|
||||
var point = e.GetPosition(this) - new Point(Padding.Left, Padding.Top);
|
||||
var x = Math.Min(Math.Max(point.X, 0), Math.Max(TextLayout.WidthIncludingTrailingWhitespace, 0));
|
||||
|
@ -142,25 +95,25 @@ namespace SourceGit.Views
|
|||
point = new Point(x, y);
|
||||
|
||||
var pos = TextLayout.HitTestPoint(point).TextPosition;
|
||||
foreach (var match in _matches)
|
||||
foreach (var link in links)
|
||||
{
|
||||
if (!match.Intersect(pos, 1))
|
||||
if (!link.Intersect(pos, 1))
|
||||
continue;
|
||||
|
||||
if (match == _lastHover)
|
||||
if (link == _lastHover)
|
||||
return;
|
||||
|
||||
SetCurrentValue(CursorProperty, Cursor.Parse("Hand"));
|
||||
|
||||
_lastHover = match;
|
||||
if (!match.IsCommitSHA)
|
||||
_lastHover = link;
|
||||
if (!link.IsCommitSHA)
|
||||
{
|
||||
ToolTip.SetTip(this, match.Link);
|
||||
ToolTip.SetTip(this, link.Link);
|
||||
ToolTip.SetIsOpen(this, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
ProcessHoverCommitLink(match);
|
||||
ProcessHoverCommitLink(link);
|
||||
}
|
||||
|
||||
return;
|
||||
|
@ -361,7 +314,6 @@ namespace SourceGit.Views
|
|||
}
|
||||
}
|
||||
|
||||
private List<Models.Hyperlink> _matches = null;
|
||||
private Models.Hyperlink _lastHover = null;
|
||||
private Dictionary<string, Models.Commit> _inlineCommits = new();
|
||||
}
|
||||
|
|
|
@ -257,7 +257,7 @@
|
|||
<ContentControl.DataTemplates>
|
||||
<DataTemplate DataType="m:RevisionSubmodule">
|
||||
<Border Margin="0,0,0,8" BorderThickness="1" BorderBrush="{DynamicResource Brush.Border1}" Background="{DynamicResource Brush.Window}">
|
||||
<v:CommitBaseInfo MaxHeight="256" Margin="0,0,0,4" Content="{Binding Commit}" Message="{Binding FullMessage}"/>
|
||||
<v:CommitBaseInfo MaxHeight="256" Margin="0,0,0,4" Content="{Binding Commit}" FullMessage="{Binding FullMessage}"/>
|
||||
</Border>
|
||||
</DataTemplate>
|
||||
</ContentControl.DataTemplates>
|
||||
|
@ -271,7 +271,7 @@
|
|||
<Path Width="16" Height="16" Data="{StaticResource Icons.DoubleDown}" HorizontalAlignment="Center" IsVisible="{Binding Old, Converter={x:Static ObjectConverters.IsNotNull}}"/>
|
||||
|
||||
<Border Margin="0,8,0,0" BorderThickness="1" BorderBrush="Green" Background="{DynamicResource Brush.Window}">
|
||||
<v:CommitBaseInfo MaxHeight="256" Margin="0,0,0,4" Content="{Binding New.Commit}" Message="{Binding New.FullMessage}"/>
|
||||
<v:CommitBaseInfo MaxHeight="256" Margin="0,0,0,4" Content="{Binding New.Commit}" FullMessage="{Binding New.FullMessage}"/>
|
||||
</Border>
|
||||
</StackPanel>
|
||||
</ScrollViewer>
|
||||
|
|
|
@ -63,7 +63,7 @@
|
|||
<Grid RowDefinitions="Auto,*" Margin="8,0">
|
||||
<TextBlock Grid.Row="0" Margin="0,8,0,0" Text="{DynamicResource Text.CommitDetail.Files.Submodule}" FontSize="18" FontWeight="Bold" HorizontalAlignment="Center" Foreground="{DynamicResource Brush.FG2}"/>
|
||||
<ScrollViewer Grid.Row="1" Margin="0,16,0,0" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto">
|
||||
<v:CommitBaseInfo Content="{Binding Commit}" Message="{Binding FullMessage}"/>
|
||||
<v:CommitBaseInfo Content="{Binding Commit}" FullMessage="{Binding FullMessage}"/>
|
||||
</ScrollViewer>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
|
|
|
@ -44,7 +44,7 @@
|
|||
<Popup PlacementTarget="{Binding #TxtSearchRevisionFiles}"
|
||||
Placement="BottomEdgeAlignedLeft"
|
||||
HorizontalOffset="-8" VerticalAlignment="-8"
|
||||
IsOpen="{Binding IsRevisionFileSearchSuggestionOpen}">
|
||||
IsOpen="{Binding RevisionFileSearchSuggestion, Converter={x:Static c:ListConverters.IsNotNullOrEmpty}}">
|
||||
<Border Margin="8" VerticalAlignment="Top" Effect="drop-shadow(0 0 8 #80000000)">
|
||||
<Border Background="{DynamicResource Brush.Popup}" CornerRadius="4" Padding="4" BorderThickness="0.65" BorderBrush="{DynamicResource Brush.Accent}">
|
||||
<ListBox x:Name="SearchSuggestionBox"
|
||||
|
|
|
@ -23,7 +23,7 @@ namespace SourceGit.Views
|
|||
}
|
||||
else if (e.Key == Key.Down || e.Key == Key.Up)
|
||||
{
|
||||
if (vm.IsRevisionFileSearchSuggestionOpen)
|
||||
if (vm.RevisionFileSearchSuggestion.Count > 0)
|
||||
{
|
||||
SearchSuggestionBox.Focus(NavigationMethod.Tab);
|
||||
SearchSuggestionBox.SelectedIndex = 0;
|
||||
|
@ -33,12 +33,7 @@ namespace SourceGit.Views
|
|||
}
|
||||
else if (e.Key == Key.Escape)
|
||||
{
|
||||
if (vm.IsRevisionFileSearchSuggestionOpen)
|
||||
{
|
||||
vm.RevisionFileSearchSuggestion.Clear();
|
||||
vm.IsRevisionFileSearchSuggestionOpen = false;
|
||||
}
|
||||
|
||||
vm.CancelRevisionFileSuggestions();
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
|
@ -57,7 +52,7 @@ namespace SourceGit.Views
|
|||
|
||||
if (e.Key == Key.Escape)
|
||||
{
|
||||
vm.RevisionFileSearchSuggestion.Clear();
|
||||
vm.CancelRevisionFileSuggestions();
|
||||
e.Handled = true;
|
||||
}
|
||||
else if (e.Key == Key.Enter && SearchSuggestionBox.SelectedItem is string content)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue