Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 28 additions & 7 deletions src/Views/CommitBaseInfo.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,34 @@

<!-- REFS -->
<TextBlock Grid.Row="3" Grid.Column="0" Classes="info_label" VerticalAlignment="Top" Margin="0,4,0,0" Text="{DynamicResource Text.CommitDetail.Info.Refs}" IsVisible="{Binding HasDecorators}"/>
<Border Grid.Row="3" Grid.Column="1" Margin="12,0,0,0" MinHeight="24" IsVisible="{Binding HasDecorators}">
<v:CommitRefsPresenter Foreground="{DynamicResource Brush.FG1}"
FontSize="12"
AllowWrap="True"
Margin="0,4,0,0"
UseGraphColor="False"/>
</Border>
<ItemsControl Grid.Row="3" Grid.Column="1" Margin="12,4,0,0" ItemsSource="{Binding Decorators}" IsVisible="{Binding HasDecorators}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>

<ItemsControl.ItemTemplate>
<DataTemplate DataType="m:Decorator">
<StackPanel Orientation="Horizontal" Margin="0,0,16,4" VerticalAlignment="Center">
<v:CommitRefsPresenter Decorator="{Binding}"
Foreground="{DynamicResource Brush.FG1}"
FontSize="12"
UseGraphColor="False"
VerticalAlignment="Center"/>
<Button Classes="icon_button"
Width="14" Height="14"
Padding="0"
Margin="2,0,0,0"
Cursor="Hand"
Click="OnCopyRefName"
ToolTip.Tip="{DynamicResource Text.Copy}">
<Path Width="10" Height="10" Data="{StaticResource Icons.Copy}" Fill="{DynamicResource Brush.FG2}"/>
</Button>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>

<!-- Messages -->
<TextBlock Grid.Row="4" Grid.Column="0" Classes="info_label" VerticalAlignment="Top" Margin="0,4,0,0" Text="{DynamicResource Text.CommitDetail.Info.Message}" />
Expand Down
8 changes: 8 additions & 0 deletions src/Views/CommitBaseInfo.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ protected override void OnUnloaded(RoutedEventArgs e)
_iconResetTimer?.Dispose();
}

private async void OnCopyRefName(object sender, RoutedEventArgs e)
{
if (sender is Button { DataContext: Models.Decorator decorator })
await this.CopyTextAsync(decorator.Name);

e.Handled = true;
}

private async void OnCopyCommitSHA(object sender, RoutedEventArgs e)
{
if (sender is Button { DataContext: Models.Commit commit })
Expand Down
23 changes: 19 additions & 4 deletions src/Views/CommitRefsPresenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@ public bool ShowTags
set => SetValue(ShowTagsProperty, value);
}

public static readonly StyledProperty<Models.Decorator> DecoratorProperty =
AvaloniaProperty.Register<CommitRefsPresenter, Models.Decorator>(nameof(Decorator));

public Models.Decorator Decorator
{
get => GetValue(DecoratorProperty);
set => SetValue(DecoratorProperty, value);
}

static CommitRefsPresenter()
{
AffectsMeasure<CommitRefsPresenter>(
Expand All @@ -91,7 +100,8 @@ static CommitRefsPresenter()
ForegroundProperty,
UseGraphColorProperty,
BackgroundProperty,
ShowTagsProperty);
ShowTagsProperty,
DecoratorProperty);
}

public Models.Decorator DecoratorAt(Point point)
Expand Down Expand Up @@ -174,16 +184,21 @@ protected override Size MeasureOverride(Size availableSize)
{
_items.Clear();

if (DataContext is not Models.Commit commit)
var commit = DataContext as Models.Commit;
IList<Models.Decorator> refs;
if (Decorator != null)
refs = new[] { Decorator };
else if (commit != null)
refs = commit.Decorators;
else
return new Size(0, 0);

var refs = commit.Decorators;
if (refs is { Count: > 0 })
{
var typeface = new Typeface(FontFamily);
var typefaceBold = new Typeface(FontFamily, FontStyle.Normal, FontWeight.Bold);
var fg = Foreground;
var normalBG = UseGraphColor ? Models.CommitGraph.Pens[commit.Color].Brush : Brushes.Gray;
var normalBG = UseGraphColor && commit != null ? Models.CommitGraph.Pens[commit.Color].Brush : Brushes.Gray;
var labelSize = FontSize;
var requiredHeight = 16.0;
var x = 0.0;
Expand Down