ux: re-design submodule preview in revision files

This commit is contained in:
leo 2024-06-19 14:24:49 +08:00
parent e17e4b9a53
commit a168b05ac6
No known key found for this signature in database
6 changed files with 38 additions and 17 deletions

View file

@ -587,16 +587,10 @@ namespace SourceGit.Models
public string New { get; set; } = string.Empty;
}
public class SubmoduleRevision
{
public Commit Commit { get; set; } = null;
public string FullMessage { get; set; } = string.Empty;
}
public class SubmoduleDiff
{
public SubmoduleRevision Old { get; set; } = null;
public SubmoduleRevision New { get; set; } = null;
public RevisionSubmodule Old { get; set; } = null;
public RevisionSubmodule New { get; set; } = null;
}
public class DiffResult

View file

@ -25,6 +25,7 @@ namespace SourceGit.Models
public class RevisionSubmodule
{
public string SHA { get; set; }
public Commit Commit { get; set; } = null;
public string FullMessage { get; set; } = string.Empty;
}
}

View file

@ -201,7 +201,34 @@ namespace SourceGit.ViewModels
});
break;
case Models.ObjectType.Commit:
ViewRevisionFileContent = new Models.RevisionSubmodule() { SHA = file.SHA };
Task.Run(() =>
{
var submoduleRoot = Path.Combine(_repo, file.Path);
var commit = new Commands.QuerySingleCommit(submoduleRoot, file.SHA).Result();
if (commit != null)
{
var body = new Commands.QueryCommitFullMessage(submoduleRoot, file.SHA).Result();
Dispatcher.UIThread.Invoke(() =>
{
ViewRevisionFileContent = new Models.RevisionSubmodule()
{
Commit = commit,
FullMessage = body,
};
});
}
else
{
Dispatcher.UIThread.Invoke(() =>
{
ViewRevisionFileContent = new Models.RevisionSubmodule()
{
Commit = new Models.Commit() { SHA = file.SHA },
FullMessage = string.Empty,
};
});
}
});
break;
default:
ViewRevisionFileContent = null;

View file

@ -210,16 +210,16 @@ namespace SourceGit.ViewModels
return size > 0 ? (new Bitmap(stream), size) : (null, size);
}
private Models.SubmoduleRevision QuerySubmoduleRevision(string repo, string sha)
private Models.RevisionSubmodule QuerySubmoduleRevision(string repo, string sha)
{
var commit = new Commands.QuerySingleCommit(repo, sha).Result();
if (commit != null)
{
var body = new Commands.QueryCommitFullMessage(repo, sha).Result();
return new Models.SubmoduleRevision() { Commit = commit, FullMessage = body };
return new Models.RevisionSubmodule() { Commit = commit, FullMessage = body };
}
return new Models.SubmoduleRevision()
return new Models.RevisionSubmodule()
{
Commit = new Models.Commit() { SHA = sha },
FullMessage = string.Empty,

View file

@ -151,7 +151,7 @@
<Border IsVisible="{Binding Old, Converter={x:Static ObjectConverters.IsNotNull}}">
<ContentControl Content="{Binding Old}">
<ContentControl.DataTemplates>
<DataTemplate DataType="m:SubmoduleRevision">
<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" CanNavigate="False" Content="{Binding Commit}" Message="{Binding FullMessage}"/>
</Border>

View file

@ -78,10 +78,9 @@
</DataTemplate>
<DataTemplate DataType="m:RevisionSubmodule">
<StackPanel Orientation="Vertical" HorizontalAlignment="Center" VerticalAlignment="Center">
<StackPanel Orientation="Vertical" HorizontalAlignment="Stretch" Margin="8,8,8,0">
<TextBlock Text="{DynamicResource Text.CommitDetail.Files.Submodule}" FontSize="18" FontWeight="Bold" HorizontalAlignment="Center" Foreground="{DynamicResource Brush.FG2}"/>
<Path Width="64" Height="64" Margin="0,16,0,0" Data="{StaticResource Icons.Submodule}" Fill="{DynamicResource Brush.FG2}"/>
<SelectableTextBlock Margin="0,16,0,0" Text="{Binding SHA}" HorizontalAlignment="Center" Foreground="{DynamicResource Brush.FG2}"/>
<v:CommitBaseInfo Margin="0,16,0,0" CanNavigate="False" Content="{Binding Commit}" Message="{Binding FullMessage}"/>
</StackPanel>
</DataTemplate>
</ContentControl.DataTemplates>