style<CommitViewer>: better layout for committer and author

This commit is contained in:
leo 2020-11-23 19:00:14 +08:00
parent 9d9e741aa5
commit d42da5f5fa
2 changed files with 188 additions and 170 deletions

View file

@ -22,24 +22,73 @@
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!-- Base information -->
<Grid Grid.Row="0">
<!-- Author and committer -->
<Grid Grid.Row="0" Margin="0,8">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="72"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<!-- Author -->
<Grid Grid.Column="0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition x:Name="refRow" Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition x:Name="committerRow" Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="96"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Image Grid.Row="0" Grid.RowSpan="3" Grid.Column="0" Width="64" Height="64" x:Name="authorAvatar" HorizontalAlignment="Right"/>
<TextBlock Grid.Row="0" Grid.Column="1" Margin="15,0,0,0" Text="AUTHOR" Opacity=".6" Foreground="{StaticResource Brush.FG}"/>
<StackPanel Grid.Row="1" Grid.Column="1" Orientation="Horizontal" Margin="12,0,0,0">
<TextBox x:Name="authorName" IsReadOnly="True" Background="Transparent" Foreground="{StaticResource Brush.FG}" BorderThickness="0"/>
<TextBox x:Name="authorEmail" Margin="4,0,0,0" IsReadOnly="True" Background="Transparent" Foreground="{StaticResource Brush.FG2}" BorderThickness="0"/>
</StackPanel>
<TextBox Grid.Row="2" Grid.Column="1" Margin="12,0,0,0" x:Name="authorTime" IsReadOnly="True" Background="Transparent" Foreground="{StaticResource Brush.FG2}" FontSize="11" BorderThickness="0"/>
</Grid>
<!-- Committer -->
<Grid Grid.Column="1" x:Name="committerPanel">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="96"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Image Grid.Row="0" Grid.RowSpan="3" Grid.Column="0" Width="64" Height="64" x:Name="committerAvatar" HorizontalAlignment="Right"/>
<TextBlock Grid.Row="0" Grid.Column="1" Margin="15,0,0,0" Text="COMMITTER" Opacity=".6" Foreground="{StaticResource Brush.FG}"/>
<StackPanel Grid.Row="1" Grid.Column="1" Margin="12,0,0,0" Orientation="Horizontal">
<TextBox x:Name="committerName" IsReadOnly="True" Background="Transparent" Foreground="{StaticResource Brush.FG}" BorderThickness="0" FontSize="13"/>
<TextBox x:Name="committerEmail" Margin="4,0,0,0" IsReadOnly="True" Background="Transparent" Foreground="{StaticResource Brush.FG2}" BorderThickness="0"/>
</StackPanel>
<TextBox Grid.Row="2" Grid.Column="1" Margin="12,0,0,0" x:Name="committerTime" IsReadOnly="True" Background="Transparent" Foreground="{StaticResource Brush.FG2}" FontSize="11" BorderThickness="0"/>
</Grid>
</Grid>
<Rectangle Grid.Row="1" Height="1" Margin="8" Fill="{StaticResource Brush.Border2}"/>
<!-- Base information -->
<Grid Grid.Row="2">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition x:Name="refRow" Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition x:Name="descRow" Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="96"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
@ -51,12 +100,13 @@
x:Name="SHA"
IsReadOnly="True"
Background="Transparent"
FontFamily="Consolas"
BorderThickness="0"
Margin="11,0,0,0"/>
<!-- PARENTS -->
<Label Grid.Row="0" Grid.Column="2" Content="PARENTS" HorizontalAlignment="Right" Opacity=".6"/>
<ItemsControl Grid.Row="0" Grid.Column="3" x:Name="parents" Margin="8,0,0,0">
<Label Grid.Row="1" Grid.Column="0" Content="PARENTS" HorizontalAlignment="Right" Opacity=".6"/>
<ItemsControl Grid.Row="1" Grid.Column="1" x:Name="parents" Margin="8,0,0,0">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel Orientation="Horizontal" VerticalAlignment="Center"/>
@ -65,7 +115,7 @@
<ItemsControl.ItemTemplate>
<DataTemplate>
<Label Margin="0,0,8,0">
<Label Margin="0,0,8,0" FontFamily="Consolas">
<Hyperlink RequestNavigate="NavigateParent" NavigateUri="{Binding .}" ToolTip="NAVIGATE TO COMMIT">
<Run Text="{Binding .}"/>
</Hyperlink>
@ -75,8 +125,8 @@
</ItemsControl>
<!-- Refs -->
<Label Grid.Row="1" Grid.Column="0" Content="REFS" HorizontalAlignment="Right" Opacity=".6"/>
<ItemsControl Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="3" x:Name="refs" Margin="8,0,0,0">
<Label Grid.Row="2" Grid.Column="0" Content="REFS" HorizontalAlignment="Right" Opacity=".6"/>
<ItemsControl Grid.Row="2" Grid.Column="1" x:Name="refs" Margin="8,0,0,0">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel Orientation="Horizontal" VerticalAlignment="Center"/>
@ -123,89 +173,25 @@
</ItemsControl.ItemTemplate>
</ItemsControl>
<!-- AUTHOR -->
<Label Grid.Row="2" Grid.Column="0" Content="AUTHOR" HorizontalAlignment="Right" Opacity=".6"/>
<TextBox
x:Name="author"
Grid.Row="2" Grid.Column="1"
IsReadOnly="True"
Background="Transparent"
AcceptsReturn="True"
BorderThickness="0"
Margin="11,0,0,0"/>
<!-- AUTHOR TIME -->
<Label Grid.Row="2" Grid.Column="2" Content="AUTHOR TIME" HorizontalAlignment="Right" Opacity=".6"/>
<TextBox
Grid.Row="2" Grid.Column="3"
x:Name="authorTime"
IsReadOnly="True"
Background="Transparent"
AcceptsReturn="True"
BorderThickness="0"
Margin="8,0,0,0"/>
<!-- COMMITTER -->
<Label Grid.Row="3" Grid.Column="0" Content="COMMIT" HorizontalAlignment="Right" Opacity=".6"/>
<!-- SUBJECT -->
<Label Grid.Row="3" Grid.Column="0" Content="SUBJECT" HorizontalAlignment="Right" Opacity=".6"/>
<TextBox
Grid.Row="3" Grid.Column="1"
x:Name="committer"
IsReadOnly="True"
Background="Transparent"
AcceptsReturn="True"
BorderThickness="0"
Margin="11,0,0,0"/>
<!-- COMMIT TIME -->
<Label Grid.Row="3" Grid.Column="2" Content="COMMIT TIME" HorizontalAlignment="Right" Opacity=".6"/>
<TextBox
Grid.Row="3" Grid.Column="3"
x:Name="committerTime"
IsReadOnly="True"
Background="Transparent"
AcceptsReturn="True"
BorderThickness="0"
Margin="8,0,0,0"/>
</Grid>
<Border Grid.Column="1" Padding="8,8,8,0">
<Image x:Name="avatar" VerticalAlignment="Top"/>
</Border>
</Grid>
<Rectangle Grid.Row="1" Height="1" Margin="8" Fill="{StaticResource Brush.Border2}"/>
<!-- Commit message -->
<Grid Grid.Row="2">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="96"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<!-- SUBJECT -->
<Label Grid.Row="0" Grid.Column="0" Content="SUBJECT" HorizontalAlignment="Right" Opacity=".6"/>
<TextBox
Grid.Row="0" Grid.Column="1"
x:Name="subject"
IsReadOnly="True"
Background="Transparent"
FontFamily="Consolas"
BorderThickness="0"
Margin="8,0,16,0"/>
Margin="11,0,16,0"/>
<!-- MESSAGE -->
<Label Grid.Row="1" Grid.Column="0" Content="DESCRIPTION" HorizontalAlignment="Right" VerticalAlignment="Top" Opacity=".6"/>
<Label Grid.Row="4" Grid.Column="0" Content="DESCRIPTION" HorizontalAlignment="Right" VerticalAlignment="Top" Opacity=".6"/>
<TextBox
Grid.Row="1" Grid.Column="1"
Grid.Row="4" Grid.Column="1"
x:Name="message"
IsReadOnly="True"
Background="Transparent"
BorderThickness="0"
VerticalAlignment="Center"
FontSize="11"
Margin="11,8,0,0"/>
</Grid>

View file

@ -89,14 +89,55 @@ namespace SourceGit.UI {
SHA.Text = commit.SHA;
refs.ItemsSource = commit.Decorators;
parents.ItemsSource = parentIds;
author.Text = $"{commit.Author.Name} <{commit.Author.Email}>";
authorTime.Text = commit.Author.Time;
committer.Text = $"{commit.Committer.Name} <{commit.Committer.Email}>";
committerTime.Text = commit.Committer.Time;
subject.Text = commit.Subject;
message.Text = commit.Message.Trim();
byte[] hash = MD5.Create().ComputeHash(Encoding.Default.GetBytes(commit.Author.Email.ToLower().Trim()));
var commitMsg = commit.Message.Trim();
if (string.IsNullOrEmpty(commitMsg)) {
descRow.Height = new GridLength(0);
} else {
descRow.Height = GridLength.Auto;
message.Text = commitMsg;
}
authorName.Text = commit.Author.Name;
authorEmail.Text = commit.Author.Email;
authorTime.Text = commit.Author.Time;
if (commit.Committer.Email == commit.Author.Email) {
if (commit.Committer.Time == commit.Author.Time) {
committerPanel.Visibility = Visibility.Hidden;
SetAvatar(authorAvatar, commit.Author.Email);
} else {
committerPanel.Visibility = Visibility.Visible;
committerName.Text = commit.Committer.Name;
committerEmail.Text = commit.Committer.Email;
committerTime.Text = commit.Committer.Time;
SetAvatar(authorAvatar, commit.Author.Email);
SetAvatar(committerAvatar, commit.Committer.Email, false);
}
} else {
committerPanel.Visibility = Visibility.Visible;
committerName.Text = commit.Committer.Name;
committerEmail.Text = commit.Committer.Email;
committerTime.Text = commit.Committer.Time;
SetAvatar(authorAvatar, commit.Author.Email);
SetAvatar(committerAvatar, commit.Committer.Email);
}
if (commit.Decorators.Count == 0) {
refRow.Height = new GridLength(0);
} else {
refRow.Height = GridLength.Auto;
}
}
private void SetAvatar(Image img, string email, bool save = true) {
byte[] hash = MD5.Create().ComputeHash(Encoding.Default.GetBytes(email.ToLower().Trim()));
string md5 = "";
for (int i = 0; i < hash.Length; i++) md5 += hash[i].ToString("x2");
md5 = md5.ToLower();
@ -105,9 +146,10 @@ namespace SourceGit.UI {
string filePath = Path.Combine(AVATAR_PATH, md5);
if (File.Exists(filePath)) {
avatar.Source = new BitmapImage(new Uri(filePath));
img.Source = new BitmapImage(new Uri(filePath));
} else {
var bitmap = new BitmapImage(new Uri("https://www.gravatar.com/avatar/" + md5 + "?d=mp"));
if (save) {
bitmap.DownloadCompleted += (o, e) => {
var owner = o as BitmapImage;
if (owner != null) {
@ -118,19 +160,9 @@ namespace SourceGit.UI {
}
}
};
avatar.Source = bitmap;
}
img.Source = bitmap;
if (commit.Decorators.Count == 0) {
refRow.Height = new GridLength(0);
committerRow.Height = GridLength.Auto;
} else {
refRow.Height = GridLength.Auto;
if (commit.Committer.Email == commit.Author.Email && commit.Committer.Time == commit.Author.Time) {
committerRow.Height = new GridLength(0);
} else {
committerRow.Height = GridLength.Auto;
}
}
}