refactor: use Binding.TargetNullValue instead of empty class Models.CompareTargetWorktree

This commit is contained in:
leo 2024-07-24 11:16:28 +08:00
parent 6038fecab4
commit 0dee3a1969
No known key found for this signature in database
3 changed files with 25 additions and 29 deletions

View file

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

View file

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

View file

@ -10,9 +10,8 @@
x:Class="SourceGit.Views.RevisionCompare" x:Class="SourceGit.Views.RevisionCompare"
x:DataType="vm:RevisionCompare" x:DataType="vm:RevisionCompare"
Background="{DynamicResource Brush.Window}"> Background="{DynamicResource Brush.Window}">
<UserControl.Resources> <UserControl.DataTemplates>
<!-- Template for Models.Commit --> <DataTemplate DataType="m:Commit">
<DataTemplate DataType="m:Commit" x:Key="CommitInfoTemplate">
<Grid RowDefinitions="Auto,*"> <Grid RowDefinitions="Auto,*">
<Grid Grid.Row="0" ColumnDefinitions="Auto,*,Auto,Auto,Auto"> <Grid Grid.Row="0" ColumnDefinitions="Auto,*,Auto,Auto,Auto">
<v:Avatar Width="16" Height="16" VerticalAlignment="Center" IsHitTestVisible="False" User="{Binding Author}"/> <v:Avatar Width="16" Height="16" VerticalAlignment="Center" IsHitTestVisible="False" User="{Binding Author}"/>
@ -27,25 +26,23 @@
<TextBlock Grid.Row="1" Classes="monospace" Text="{Binding Subject}" VerticalAlignment="Bottom"/> <TextBlock Grid.Row="1" Classes="monospace" Text="{Binding Subject}" VerticalAlignment="Bottom"/>
</Grid> </Grid>
</DataTemplate> </DataTemplate>
</UserControl.DataTemplates>
<!-- Template for Models.CompareTargetWorktree -->
<DataTemplate DataType="m:CompareTargetWorktree" x:Key="WorktreeTemplate">
<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>
</UserControl.Resources>
<Grid RowDefinitions="50,*" Margin="4"> <Grid RowDefinitions="50,*" Margin="4">
<!-- Compare Revision Info --> <!-- Compare Revision Info -->
<Grid Grid.Row="0" Margin="48,0,48,4" ColumnDefinitions="*,48,*"> <Grid Grid.Row="0" Margin="48,0,48,4" ColumnDefinitions="*,48,*">
<!-- Base Revision --> <!-- Base Revision -->
<Border Grid.Column="0" BorderBrush="{DynamicResource Brush.Border2}" BorderThickness="1" Background="{DynamicResource Brush.Contents}" CornerRadius="4" Padding="4"> <Border Grid.Column="0" BorderBrush="{DynamicResource Brush.Border2}" BorderThickness="1" Background="{DynamicResource Brush.Contents}" CornerRadius="4" Padding="4">
<ContentControl Content="{Binding StartPoint}"> <ContentControl>
<ContentControl.DataTemplates> <ContentControl.Content>
<StaticResource ResourceKey="CommitInfoTemplate"/> <Binding Path="StartPoint">
<StaticResource ResourceKey="WorktreeTemplate"/> <Binding.TargetNullValue>
</ContentControl.DataTemplates> <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>
</Border> </Border>
@ -56,11 +53,16 @@
<!-- Right Revision --> <!-- Right Revision -->
<Border Grid.Column="2" BorderBrush="{DynamicResource Brush.Border2}" BorderThickness="1" Background="{DynamicResource Brush.Contents}" CornerRadius="4" Padding="4"> <Border Grid.Column="2" BorderBrush="{DynamicResource Brush.Border2}" BorderThickness="1" Background="{DynamicResource Brush.Contents}" CornerRadius="4" Padding="4">
<ContentControl Content="{Binding EndPoint}"> <ContentControl>
<ContentControl.DataTemplates> <ContentControl.Content>
<StaticResource ResourceKey="CommitInfoTemplate"/> <Binding Path="EndPoint">
<StaticResource ResourceKey="WorktreeTemplate"/> <Binding.TargetNullValue>
</ContentControl.DataTemplates> <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>
</Border> </Border>
</Grid> </Grid>