Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit 6c7d11d

Browse files
authored
Merge pull request #1079 from github/fixes/1078-glyph-model
Add data context and resources for glyphs
2 parents 2ad7b46 + 0d6bc17 commit 6c7d11d

File tree

4 files changed

+57
-19
lines changed

4 files changed

+57
-19
lines changed

src/GitHub.InlineReviews/Tags/AddInlineCommentGlyph.xaml

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,34 @@
44
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
55
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
66
mc:Ignorable="d">
7-
<Viewbox x:Name="AddViewbox">
8-
<Path Stroke="Black"
9-
Data="M13 2H1c-0.55 0-1 0.45-1 1v8c0 0.55 0.45 1 1 1h2v3.5l3.5-3.5h6.5c0.55 0 1-0.45 1-1V3c0-0.55-0.45-1-1-1z m0 9H6L4 13V11H1V3h12v8z M7,5 L7,9 M5,7 L9,7"/>
10-
</Viewbox>
7+
<UserControl.Resources>
8+
<SolidColorBrush x:Key="DiffChangeBackground" Color="DarkSlateGray" />
9+
<SolidColorBrush x:Key="AddDiffChangeBackground" Color="Green" />
10+
<SolidColorBrush x:Key="RemovedDiffChangeBackground" Color="Red" />
11+
</UserControl.Resources>
12+
13+
<Grid Background="{DynamicResource DiffChangeBackground}">
14+
<Viewbox x:Name="AddViewbox">
15+
<Path
16+
Data="M13 2H1c-0.55 0-1 0.45-1 1v8c0 0.55 0.45 1 1 1h2v3.5l3.5-3.5h6.5c0.55 0 1-0.45 1-1V3c0-0.55-0.45-1-1-1z m0 9H6L4 13V11H1V3h12v8z M7,5 L7,9 M5,7 L9,7">
17+
<Path.Style>
18+
<Style TargetType="Path">
19+
<Style.Triggers>
20+
<DataTrigger Binding="{Binding DiffChangeType}" Value="Add">
21+
<Setter Property="Stroke" Value="{DynamicResource AddDiffChangeBackground}" />
22+
</DataTrigger>
23+
24+
<DataTrigger Binding="{Binding DiffChangeType}" Value="None">
25+
<Setter Property="Stroke" Value="{DynamicResource DiffChangeBackground}" />
26+
</DataTrigger>
27+
28+
<DataTrigger Binding="{Binding DiffChangeType}" Value="Delete">
29+
<Setter Property="Stroke" Value="{DynamicResource RemovedDiffChangeBackground}" />
30+
</DataTrigger>
31+
</Style.Triggers>
32+
</Style>
33+
</Path.Style>
34+
</Path>
35+
</Viewbox>
36+
</Grid>
1137
</UserControl>

src/GitHub.InlineReviews/Tags/InlineCommentGlyphFactory.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,14 @@ static Brush GetBackground(ResourceDictionary dictionary)
6969
public UIElement GenerateGlyph(IWpfTextViewLine line, InlineCommentTag tag)
7070
{
7171
var glyph = CreateGlyph(tag);
72-
glyph.Tag = tag;
72+
glyph.DataContext = tag;
7373

7474
glyph.MouseLeftButtonUp += (s, e) =>
7575
{
7676
if (OpenThreadView(tag)) e.Handled = true;
7777
};
7878

79-
glyph.Background = brushesManager.GetBackground(tag.DiffChangeType);
79+
glyph.Resources["DiffChangeBackground"] = brushesManager.GetBackground(tag.DiffChangeType);
8080
return glyph;
8181
}
8282

src/GitHub.InlineReviews/Tags/ShowInlineCommentGlyph.xaml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,20 @@
55
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
66
mc:Ignorable="d"
77
ToolTipService.ShowDuration="600000" ToolTipService.HasDropShadow="True">
8+
9+
<UserControl.Resources>
10+
<!-- This will be the color of an added/deleted word in the diff view or the indicator margin color -->
11+
<SolidColorBrush x:Key="DiffChangeBackground" Color="DarkSlateGray" />
12+
</UserControl.Resources>
13+
814
<UserControl.ToolTip>
915
<ToolTip x:Name="CommentToolTip" />
1016
</UserControl.ToolTip>
11-
<Viewbox>
12-
<Path Stroke="Black"
17+
18+
<Grid Background="{DynamicResource DiffChangeBackground}">
19+
<Viewbox>
20+
<Path Stroke="Black"
1321
Data="M13 2H1c-0.55 0-1 0.45-1 1v8c0 0.55 0.45 1 1 1h2v3.5l3.5-3.5h6.5c0.55 0 1-0.45 1-1V3c0-0.55-0.45-1-1-1z m0 9H6L4 13V11H1V3h12v8z"/>
14-
</Viewbox>
22+
</Viewbox>
23+
</Grid>
1524
</UserControl>

src/GitHub.InlineReviews/Tags/ShowInlineCommentGlyph.xaml.cs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,22 @@ public ShowInlineCommentGlyph()
1616

1717
protected override void OnToolTipOpening(ToolTipEventArgs e)
1818
{
19-
var tag = Tag as ShowInlineCommentTag;
20-
var comments = tag.Thread.Comments.Select(comment => new PullRequestReviewCommentModel
19+
var tag = DataContext as ShowInlineCommentTag;
20+
if (tag != null)
2121
{
22-
User = comment.User,
23-
Body = comment.Body,
24-
CreatedAt = comment.CreatedAt
25-
});
22+
var comments = tag.Thread.Comments.Select(comment => new PullRequestReviewCommentModel
23+
{
24+
User = comment.User,
25+
Body = comment.Body,
26+
CreatedAt = comment.CreatedAt
27+
});
2628

27-
var viewModel = new TooltipCommentThreadViewModel(comments);
28-
var view = new TooltipCommentThreadView();
29-
view.DataContext = viewModel;
29+
var viewModel = new TooltipCommentThreadViewModel(comments);
30+
var view = new TooltipCommentThreadView();
31+
view.DataContext = viewModel;
3032

31-
CommentToolTip.Content = view;
33+
CommentToolTip.Content = view;
34+
}
3235
}
3336

3437
protected override void OnToolTipClosing(ToolTipEventArgs e)

0 commit comments

Comments
 (0)