feature: embed commit detail page in file histories

This commit is contained in:
leo 2024-03-26 15:56:38 +08:00
parent e443e1657b
commit 6d2e10cec2
3 changed files with 35 additions and 20 deletions

View file

@ -36,10 +36,12 @@ namespace SourceGit.ViewModels
if (value == null) if (value == null)
{ {
DiffContext = null; DiffContext = null;
DetailContext.Commit = null;
} }
else else
{ {
DiffContext = new DiffContext(_repo, new Models.DiffOption(value, _file), _diffContext); DiffContext = new DiffContext(_repo, new Models.DiffOption(value, _file), _diffContext);
DetailContext.Commit = value;
} }
} }
} }
@ -51,10 +53,17 @@ namespace SourceGit.ViewModels
set => SetProperty(ref _diffContext, value); set => SetProperty(ref _diffContext, value);
} }
public CommitDetail DetailContext
{
get => _detailContext;
set => SetProperty(ref _detailContext, value);
}
public FileHistories(string repo, string file) public FileHistories(string repo, string file)
{ {
_repo = repo; _repo = repo;
_file = file; _file = file;
_detailContext = new CommitDetail(repo);
Task.Run(() => Task.Run(() =>
{ {
@ -68,17 +77,12 @@ namespace SourceGit.ViewModels
}); });
} }
public void NavigateToCommit(string commitSHA)
{
var repo = Preference.FindRepository(_repo);
if (repo != null) repo.NavigateToCommit(commitSHA);
}
private readonly string _repo = string.Empty; private readonly string _repo = string.Empty;
private readonly string _file = string.Empty; private readonly string _file = string.Empty;
private bool _isLoading = true; private bool _isLoading = true;
private List<Models.Commit> _commits = null; private List<Models.Commit> _commits = null;
private Models.Commit _selectedCommit = null; private Models.Commit _selectedCommit = null;
private DiffContext _diffContext = null; private DiffContext _diffContext = null;
private CommitDetail _detailContext = null;
} }
} }

View file

@ -89,7 +89,7 @@
<Grid Grid.Row="0" ColumnDefinitions="Auto,*,Auto,Auto"> <Grid Grid.Row="0" ColumnDefinitions="Auto,*,Auto,Auto">
<v:Avatar Grid.Column="0" Width="16" Height="16" VerticalAlignment="Center" IsHitTestVisible="False" User="{Binding Author}"/> <v:Avatar Grid.Column="0" Width="16" Height="16" VerticalAlignment="Center" IsHitTestVisible="False" User="{Binding Author}"/>
<TextBlock Grid.Column="1" Classes="monospace" Text="{Binding Author.Name}" Margin="8,0,0,0"/> <TextBlock Grid.Column="1" Classes="monospace" Text="{Binding Author.Name}" Margin="8,0,0,0"/>
<TextBlock Grid.Column="2" Classes="monospace" Text="{Binding SHA, Converter={x:Static c:StringConverters.ToShortSHA}}" Foreground="DarkOrange" Margin="8,0,0,0" TextDecorations="Underline" Cursor="Hand" PointerPressed="OnPressedSHA"/> <TextBlock Grid.Column="2" Classes="monospace" Text="{Binding SHA, Converter={x:Static c:StringConverters.ToShortSHA}}" Foreground="DarkOrange" Margin="8,0,0,0" TextDecorations="Underline" Cursor="Hand"/>
<TextBlock Grid.Column="3" Classes="monospace" Text="{Binding AuthorTimeShortStr}" Foreground="{DynamicResource Brush.FG2}" Margin="8,0,0,0"/> <TextBlock Grid.Column="3" Classes="monospace" Text="{Binding AuthorTimeShortStr}" Foreground="{DynamicResource Brush.FG2}" Margin="8,0,0,0"/>
</Grid> </Grid>
@ -109,14 +109,36 @@
BorderThickness="1,0,0,0" BorderThickness="1,0,0,0"
BorderBrush="{DynamicResource Brush.Border2}"/> BorderBrush="{DynamicResource Brush.Border2}"/>
<Grid Grid.Column="2"> <Grid Grid.Column="2" RowDefinitions="*,3,*" Margin="0,4,4,4">
<ContentControl Margin="0,4,4,4" Content="{Binding DiffContext}"> <ContentControl Grid.Row="0" Content="{Binding DiffContext}">
<ContentControl.DataTemplates> <ContentControl.DataTemplates>
<DataTemplate DataType="vm:DiffContext"> <DataTemplate DataType="vm:DiffContext">
<v:DiffView/> <v:DiffView/>
</DataTemplate> </DataTemplate>
</ContentControl.DataTemplates> </ContentControl.DataTemplates>
</ContentControl> </ContentControl>
<GridSplitter Grid.Row="1"
MinHeight="1"
HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
Background="Transparent"/>
<Grid Grid.Row="2">
<Border Background="{DynamicResource Brush.Window}">
<Path Width="128" Height="128"
Data="{StaticResource Icons.Detail}"
HorizontalAlignment="Center"
Fill="{DynamicResource Brush.FG2}"/>
</Border>
<ContentControl Content="{Binding DetailContext}">
<ContentControl.DataTemplates>
<DataTemplate DataType="vm:CommitDetail">
<v:CommitDetail/>
</DataTemplate>
</ContentControl.DataTemplates>
</ContentControl>
</Grid>
</Grid> </Grid>
</Grid> </Grid>

View file

@ -38,16 +38,5 @@ namespace SourceGit.Views
{ {
BeginMoveDrag(e); BeginMoveDrag(e);
} }
private void OnPressedSHA(object sender, PointerPressedEventArgs e)
{
if (sender is TextBlock block)
{
var histories = DataContext as ViewModels.FileHistories;
histories.NavigateToCommit(block.Text);
}
e.Handled = true;
}
} }
} }