Merge branch 'develop' into feature/treedatagrid

# Conflicts:
#	src/Views/CommitDetail.axaml
This commit is contained in:
leo 2024-05-29 13:09:25 +08:00
commit 179887339e
10 changed files with 95 additions and 15 deletions

View file

@ -582,6 +582,12 @@ namespace SourceGit.Models
public string New { get; set; } = string.Empty;
}
public class SubmoduleDiff
{
public Commit Old { get; set; } = null;
public Commit New { get; set; } = null;
}
public class DiffResult
{
public bool IsBinary { get; set; } = false;

View file

@ -4,11 +4,11 @@ namespace SourceGit.Models
{
public partial class Remote
{
[GeneratedRegex(@"^http[s]?://([\w\-]+@)?[\w\.\-]+(\:[0-9]+)?/[\w\-/]+/[\w\-\.]+\.git$")]
[GeneratedRegex(@"^http[s]?://([\w\-]+@)?[\w\.\-]+(\:[0-9]+)?/[\w\-/]+/[\w\-\.]+(\.git)?$")]
private static partial Regex REG_HTTPS();
[GeneratedRegex(@"^[\w\-]+@[\w\.\-]+(\:[0-9]+)?:[\w\-/]+/[\w\-\.]+\.git$")]
[GeneratedRegex(@"^[\w\-]+@[\w\.\-]+(\:[0-9]+)?:[\w\-/]+/[\w\-\.]+(\.git)?$")]
private static partial Regex REG_SSH1();
[GeneratedRegex(@"^ssh://([\w\-]+@)?[\w\.\-]+(\:[0-9]+)?/[\w\-/]+/[\w\-\.]+\.git$")]
[GeneratedRegex(@"^ssh://([\w\-]+@)?[\w\.\-]+(\:[0-9]+)?/[\w\-/]+/[\w\-\.]+(\.git)?$")]
private static partial Regex REG_SSH2();
private static readonly Regex[] URL_FORMATS = [

View file

@ -161,6 +161,8 @@
<x:String x:Key="Text.Diff.NoChange" xml:space="preserve">NO CHANGES OR ONLY EOL CHANGES</x:String>
<x:String x:Key="Text.Diff.Prev" xml:space="preserve">Previous Difference</x:String>
<x:String x:Key="Text.Diff.SideBySide" xml:space="preserve">Side-By-Side Diff</x:String>
<x:String x:Key="Text.Diff.Submodule" xml:space="preserve">SUBMODULE</x:String>
<x:String x:Key="Text.Diff.Submodule.New" xml:space="preserve">NEW</x:String>
<x:String x:Key="Text.Diff.SyntaxHighlight" xml:space="preserve">Syntax Highlighting</x:String>
<x:String x:Key="Text.Diff.UseMerger" xml:space="preserve">Open In Merge Tool</x:String>
<x:String x:Key="Text.Diff.VisualLines.Decr" xml:space="preserve">Decrease Number of Visible Lines</x:String>

View file

@ -161,6 +161,8 @@
<x:String x:Key="Text.Diff.NoChange" xml:space="preserve">没有变更或仅有换行符差异</x:String>
<x:String x:Key="Text.Diff.Prev" xml:space="preserve">上一个差异</x:String>
<x:String x:Key="Text.Diff.SideBySide" xml:space="preserve">分列对比</x:String>
<x:String x:Key="Text.Diff.Submodule" xml:space="preserve">子模块</x:String>
<x:String x:Key="Text.Diff.Submodule.New" xml:space="preserve">新增</x:String>
<x:String x:Key="Text.Diff.SyntaxHighlight" xml:space="preserve">语法高亮</x:String>
<x:String x:Key="Text.Diff.UseMerger" xml:space="preserve">使用外部合并工具查看</x:String>
<x:String x:Key="Text.Diff.VisualLines.Decr" xml:space="preserve">减少可见的行数</x:String>

View file

@ -72,7 +72,7 @@
<Style Selector="TextBlock.italic">
<Setter Property="FontStyle" Value="Italic"/>
</Style>
<Style Selector="TextBlock.monospace">
<Style Selector="TextBlock.monospace, SelectableTextBlock.monospace">
<Setter Property="FontFamily" Value="{Binding Source={x:Static vm:Preference.Instance}, Path=MonospaceFont}"/>
</Style>
<Style Selector="TextBlock.group_header_label">

View file

@ -127,10 +127,33 @@ namespace SourceGit.ViewModels
var rs = null as object;
if (latest.TextDiff != null)
{
var repo = Preference.FindRepository(_repo);
if (repo != null && repo.Submodules.Contains(_option.Path))
{
var submoduleDiff = new Models.SubmoduleDiff();
var submoduleRoot = $"{_repo}/{_option.Path}".Replace("\\", "/");
foreach (var line in latest.TextDiff.Lines)
{
if (line.Type == Models.TextDiffLineType.Added)
{
var sha = line.Content.Substring("Subproject commit ".Length);
submoduleDiff.New = new Commands.QuerySingleCommit(submoduleRoot, sha).Result();
}
else if (line.Type == Models.TextDiffLineType.Deleted)
{
var sha = line.Content.Substring("Subproject commit ".Length);
submoduleDiff.Old = new Commands.QuerySingleCommit(submoduleRoot, sha).Result();
}
}
rs = submoduleDiff;
}
else
{
latest.TextDiff.File = _option.Path;
rs = latest.TextDiff;
}
}
else if (latest.IsBinary)
{
var oldPath = string.IsNullOrEmpty(_option.OrgPath) ? _option.Path : _option.OrgPath;
@ -182,7 +205,7 @@ namespace SourceGit.ViewModels
{
FileModeChange = latest.FileModeChange;
Content = rs;
IsTextDiff = latest.TextDiff != null;
IsTextDiff = rs is Models.TextDiff;
IsLoading = false;
});
});

View file

@ -111,9 +111,6 @@
<SelectableTextBlock Text="{Binding FullMessage}" FontFamily="{Binding Source={x:Static vm:Preference.Instance}, Path=MonospaceFont}" TextWrapping="Wrap"/>
</ScrollViewer>
</Grid>
<!-- Line -->
<Rectangle Height=".65" Margin="8" Fill="{DynamicResource Brush.Border2}" VerticalAlignment="Center"/>
</StackPanel>
</DataTemplate>
</UserControl.DataTemplates>

View file

@ -1,3 +1,4 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Input;
@ -5,6 +6,15 @@ namespace SourceGit.Views
{
public partial class CommitBaseInfo : UserControl
{
public static readonly StyledProperty<bool> CanNavigateProperty =
AvaloniaProperty.Register<CommitBaseInfo, bool>(nameof(CanNavigate), true);
public bool CanNavigate
{
get => GetValue(CanNavigateProperty);
set => SetValue(CanNavigateProperty, value);
}
public CommitBaseInfo()
{
InitializeComponent();
@ -12,10 +22,9 @@ namespace SourceGit.Views
private void OnParentSHAPressed(object sender, PointerPressedEventArgs e)
{
if (DataContext is ViewModels.CommitDetail detail)
{
if (DataContext is ViewModels.CommitDetail detail && CanNavigate)
detail.NavigateTo((sender as Control).DataContext as string);
}
e.Handled = true;
}
}

View file

@ -17,12 +17,15 @@
<TextBlock Classes="tab_header" Text="{DynamicResource Text.CommitDetail.Info}"/>
</TabItem.Header>
<Grid RowDefinitions="Auto,*">
<Grid RowDefinitions="Auto,1,*">
<!-- Base Information -->
<v:CommitBaseInfo Grid.Row="0" Content="{Binding Commit}"/>
<!-- Line -->
<Rectangle Grid.Row="1" Height=".65" Margin="8" Fill="{DynamicResource Brush.Border2}" VerticalAlignment="Center"/>
<!-- Change List -->
<v:ChangeCollectionView Grid.Row="1"
<v:ChangeCollectionView Grid.Row="2"
Margin="72,0,8,0"
IsWorkingCopy="False"
ViewMode="List"

View file

@ -126,6 +126,44 @@
</StackPanel>
</DataTemplate>
<!-- Submodule Diff -->
<DataTemplate DataType="m:SubmoduleDiff">
<Grid Background="{DynamicResource Brush.Contents}" RowDefinitions="Auto,*">
<TextBlock Grid.Row="0"
Text="{DynamicResource Text.Diff.Submodule}"
Margin="8,8,8,8"
FontSize="18" FontWeight="Bold"
Foreground="{DynamicResource Brush.FG2}"
HorizontalAlignment="Center"/>
<ScrollViewer Grid.Row="1" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto">
<StackPanel Orientation="Vertical" Margin="8,0">
<Border IsVisible="{Binding Old, Converter={x:Static ObjectConverters.IsNotNull}}">
<ContentControl Content="{Binding Old}">
<ContentControl.DataTemplates>
<DataTemplate DataType="m:Commit">
<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" CanNavigate="False" Content="{Binding}"/>
</Border>
</DataTemplate>
</ContentControl.DataTemplates>
</ContentControl>
</Border>
<Border Height="16" HorizontalAlignment="Center" Background="Green" CornerRadius="8" IsVisible="{Binding Old, Converter={x:Static ObjectConverters.IsNull}}">
<TextBlock Classes="monospace" Text="{DynamicResource Text.Diff.Submodule.New}" Margin="8,0" FontSize="10"/>
</Border>
<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" CanNavigate="False" Content="{Binding New}"/>
</Border>
</StackPanel>
</ScrollViewer>
</Grid>
</DataTemplate>
<!-- Image Diff -->
<DataTemplate DataType="m:ImageDiff">
<Grid RowDefinitions="Auto,*,Auto" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="8,8,8,0">