fix: when base is current worktree, the diff content of selected change is wrong

* remove warnings in JetBrains Rider (it seems JetBrains can NOT recognize Binding.TargetNullValue)
This commit is contained in:
leo 2024-07-27 21:35:57 +08:00
parent 4612cecf10
commit 20b45a1cf4
No known key found for this signature in database
7 changed files with 31 additions and 42 deletions

View file

@ -80,7 +80,7 @@ namespace SourceGit.Models
/// <param name="change"></param>
public DiffOption(string baseRevision, string targetRevision, Change change)
{
_revisions.Add(baseRevision);
_revisions.Add(string.IsNullOrEmpty(baseRevision) ? "-R" : baseRevision);
_revisions.Add(targetRevision);
_path = change.Path;
_orgPath = change.OriginalPath;

6
src/Models/Null.cs Normal file
View file

@ -0,0 +1,6 @@
namespace SourceGit.Models
{
public class Null
{
}
}

View file

@ -52,7 +52,7 @@
<TrimmerRootAssembly Include="Avalonia.Themes.Fluent" />
</ItemGroup>
<ItemGroup>
<ItemGroup Condition="'$(Configuration)' == 'Release'">
<LinkerArg Include="-mmacosx-version-min=11.0" Condition="$([MSBuild]::IsOSPlatform('OSX'))"/>
</ItemGroup>
</Project>

View file

@ -15,7 +15,7 @@ namespace SourceGit.ViewModels
{
_repo = repo;
Mode = null;
Mode = new Models.Null();
View = new Views.Discard { DataContext = this };
}
@ -26,7 +26,7 @@ namespace SourceGit.ViewModels
_isUnstaged = isUnstaged;
if (_changes == null)
Mode = null;
Mode = new Models.Null();
else if (_changes.Count == 1)
Mode = _changes[0].Path;
else

View file

@ -71,8 +71,8 @@ namespace SourceGit.ViewModels
public RevisionCompare(string repo, Models.Commit startPoint, Models.Commit endPoint)
{
_repo = repo;
_startPoint = startPoint;
_endPoint = endPoint;
_startPoint = (object)startPoint ?? new Models.Null();
_endPoint = (object)endPoint ?? new Models.Null();
Task.Run(Refresh);
}

View file

@ -2,6 +2,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:m="using:SourceGit.Models"
xmlns:vm="using:SourceGit.ViewModels"
xmlns:c="using:SourceGit.Converters"
mc:Ignorable="d" d:DesignWidth="500" d:DesignHeight="450"
@ -14,19 +15,15 @@
<Grid Margin="0,16,0,8" RowDefinitions="32,32" ColumnDefinitions="120,*">
<TextBlock Grid.Row="0" Grid.Column="0" Margin="0,0,8,0" HorizontalAlignment="Right" Text="{DynamicResource Text.Discard.Changes}"/>
<ContentControl Grid.Row="0" Grid.Column="1">
<ContentControl.Content>
<Binding Path="Mode">
<Binding.TargetNullValue>
<StackPanel Orientation="Horizontal">
<Path Width="12" Height="12" Margin="0,2,0,0" Data="{StaticResource Icons.Folder.Open}"/>
<TextBlock Text="{DynamicResource Text.Discard.All}" Margin="4,0,0,0"/>
</StackPanel>
</Binding.TargetNullValue>
</Binding>
</ContentControl.Content>
<ContentControl Grid.Row="0" Grid.Column="1" Content="{Binding Mode}">
<ContentControl.DataTemplates>
<DataTemplate DataType="m:Null">
<StackPanel Orientation="Horizontal">
<Path Width="12" Height="12" Margin="0,2,0,0" Data="{StaticResource Icons.Folder.Open}"/>
<TextBlock Text="{DynamicResource Text.Discard.All}" Margin="4,0,0,0"/>
</StackPanel>
</DataTemplate>
<DataTemplate DataType="x:String">
<StackPanel Orientation="Horizontal">
<Path Width="12" Height="12" Data="{StaticResource Icons.File}"/>
@ -37,7 +34,7 @@
<DataTemplate DataType="x:Int32">
<StackPanel Orientation="Horizontal">
<Path Width="12" Height="12" Data="{StaticResource Icons.File}"/>
<TextBlock Text="{Binding, Converter={x:Static c:StringConverters.FormatByResourceKey}, ConverterParameter='Discard.Total'}" Margin="4,0,0,0"/>
<TextBlock Text="{Binding Converter={x:Static c:StringConverters.FormatByResourceKey}, ConverterParameter='Discard.Total'}" Margin="4,0,0,0"/>
</StackPanel>
</DataTemplate>
</ContentControl.DataTemplates>

View file

@ -11,6 +11,12 @@
x:DataType="vm:RevisionCompare"
Background="{DynamicResource Brush.Window}">
<UserControl.DataTemplates>
<DataTemplate DataType="m:Null">
<Border HorizontalAlignment="Center" VerticalAlignment="Center" Background="{DynamicResource Brush.Accent}" CornerRadius="4">
<TextBlock Text="{DynamicResource Text.Worktree}" Classes="monospace" Margin="4,2" Foreground="#FFDDDDDD"/>
</Border>
</DataTemplate>
<DataTemplate DataType="m:Commit">
<Grid RowDefinitions="Auto,*">
<Grid Grid.Row="0" ColumnDefinitions="Auto,*,Auto,Auto,Auto">
@ -33,17 +39,7 @@
<Grid Grid.Row="0" Margin="48,0,48,4" ColumnDefinitions="*,48,*">
<!-- Base Revision -->
<Border Grid.Column="0" BorderBrush="{DynamicResource Brush.Border2}" BorderThickness="1" Background="{DynamicResource Brush.Contents}" CornerRadius="4" Padding="4">
<ContentControl>
<ContentControl.Content>
<Binding Path="StartPoint">
<Binding.TargetNullValue>
<Border HorizontalAlignment="Center" VerticalAlignment="Center" Background="{DynamicResource Brush.Accent}" CornerRadius="4">
<TextBlock Text="{DynamicResource Text.Worktree}" Classes="monospace" Margin="4,2" Foreground="#FFDDDDDD"/>
</Border>
</Binding.TargetNullValue>
</Binding>
</ContentControl.Content>
</ContentControl>
<ContentControl Content="{Binding StartPoint}"/>
</Border>
<!-- Swap Button -->
@ -53,17 +49,7 @@
<!-- Right Revision -->
<Border Grid.Column="2" BorderBrush="{DynamicResource Brush.Border2}" BorderThickness="1" Background="{DynamicResource Brush.Contents}" CornerRadius="4" Padding="4">
<ContentControl>
<ContentControl.Content>
<Binding Path="EndPoint">
<Binding.TargetNullValue>
<Border HorizontalAlignment="Center" VerticalAlignment="Center" Background="{DynamicResource Brush.Accent}" CornerRadius="4">
<TextBlock Text="{DynamicResource Text.Worktree}" Classes="monospace" Margin="4,2" Foreground="#FFDDDDDD"/>
</Border>
</Binding.TargetNullValue>
</Binding>
</ContentControl.Content>
</ContentControl>
<ContentControl Content="{Binding EndPoint}"/>
</Border>
</Grid>