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

Commit 2c9958a

Browse files
committed
Merge branch 'feature/inline-reviews' of https://github.com/github/VisualStudio into feature/inline-reviews
2 parents 3c2b8ba + 8611aba commit 2c9958a

File tree

8 files changed

+60
-31
lines changed

8 files changed

+60
-31
lines changed

src/GitHub.InlineReviews/InlineCommentMarginProvider.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,18 @@ public IWpfTextViewMargin CreateMargin(IWpfTextViewHost wpfTextViewHost, IWpfTex
4343
{
4444
var textView = wpfTextViewHost.TextView;
4545
var tagAggregator = tagAggregatorFactory.CreateTagAggregator<InlineCommentTag>(textView);
46-
var glyphFactory = new InlineCommentGlyphFactory(peekService, textView, tagAggregator);
46+
var editorFormatMap = editorFormatMapService.GetEditorFormatMap(textView);
47+
var glyphFactory = new InlineCommentGlyphFactory(peekService, textView, tagAggregator, editorFormatMap);
48+
4749
Func<Grid> gridFactory = () => new GlyphMarginGrid();
48-
return CreateMargin(glyphFactory, gridFactory, wpfTextViewHost, parent);
50+
return CreateMargin(glyphFactory, gridFactory, wpfTextViewHost, parent, editorFormatMap);
4951
}
5052

5153
IWpfTextViewMargin CreateMargin<TGlyphTag>(IGlyphFactory<TGlyphTag> glyphFactory, Func<Grid> gridFactory,
52-
IWpfTextViewHost wpfTextViewHost, IWpfTextViewMargin parent) where TGlyphTag : ITag
54+
IWpfTextViewHost wpfTextViewHost, IWpfTextViewMargin parent, IEditorFormatMap editorFormatMap) where TGlyphTag : ITag
5355
{
5456
var tagAggregator = tagAggregatorFactory.CreateTagAggregator<TGlyphTag>(wpfTextViewHost.TextView);
55-
return new GlyphMargin<TGlyphTag>(wpfTextViewHost, glyphFactory, gridFactory, tagAggregator,
56-
editorFormatMapService.GetEditorFormatMap(wpfTextViewHost.TextView),
57+
return new GlyphMargin<TGlyphTag>(wpfTextViewHost, glyphFactory, gridFactory, tagAggregator, editorFormatMap,
5758
MarginPropertiesName, MarginName, true, 17.0);
5859
}
5960
}
Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
using System;
22
using System.Windows;
3-
using System.Windows.Media;
43
using System.Windows.Controls;
5-
using Microsoft.VisualStudio.PlatformUI;
64

75
namespace GitHub.InlineReviews.Tags
86
{
@@ -12,17 +10,9 @@ public AddInlineCommentGlyph()
1210
{
1311
InitializeComponent();
1412

15-
Loaded += AddInlineCommentGlyph_Loaded;
16-
1713
AddViewbox.Visibility = Visibility.Hidden;
1814
MouseEnter += (s, e) => AddViewbox.Visibility = Visibility.Visible;
1915
MouseLeave += (s, e) => AddViewbox.Visibility = Visibility.Hidden;
2016
}
21-
22-
void AddInlineCommentGlyph_Loaded(object sender, RoutedEventArgs e)
23-
{
24-
var backgroundColor = ImageThemingUtilities.GetImageBackgroundColor(this);
25-
Background = new SolidColorBrush(backgroundColor);
26-
}
2717
}
2818
}

src/GitHub.InlineReviews/Tags/AddInlineCommentTag.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using GitHub.Extensions;
33
using GitHub.Services;
4+
using GitHub.Models;
45

56
namespace GitHub.InlineReviews.Tags
67
{
@@ -11,8 +12,9 @@ public AddInlineCommentTag(
1112
string commitSha,
1213
string filePath,
1314
int diffLine,
14-
int lineNumber)
15-
: base(session, lineNumber)
15+
int lineNumber,
16+
DiffChangeType diffChangeType)
17+
: base(session, lineNumber, diffChangeType)
1618
{
1719
Guard.ArgumentNotNull(commitSha, nameof(commitSha));
1820

src/GitHub.InlineReviews/Tags/InlineCommentGlyphFactory.cs

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
using System;
22
using System.Windows;
3+
using System.Windows.Media;
34
using System.Windows.Controls;
45
using System.Collections.Generic;
56
using GitHub.InlineReviews.Glyph;
67
using Microsoft.VisualStudio.Text.Editor;
78
using Microsoft.VisualStudio.Text.Tagging;
89
using Microsoft.VisualStudio.Text.Formatting;
10+
using Microsoft.VisualStudio.Text.Classification;
911
using GitHub.InlineReviews.Services;
12+
using GitHub.Models;
1013

1114
namespace GitHub.InlineReviews.Tags
1215
{
@@ -15,15 +18,53 @@ class InlineCommentGlyphFactory : IGlyphFactory<InlineCommentTag>
1518
readonly IInlineCommentPeekService peekService;
1619
readonly ITextView textView;
1720
readonly ITagAggregator<InlineCommentTag> tagAggregator;
21+
readonly BrushesManager brushesManager;
1822

1923
public InlineCommentGlyphFactory(
2024
IInlineCommentPeekService peekService,
2125
ITextView textView,
22-
ITagAggregator<InlineCommentTag> tagAggregator)
26+
ITagAggregator<InlineCommentTag> tagAggregator,
27+
IEditorFormatMap editorFormatMap)
2328
{
2429
this.peekService = peekService;
2530
this.textView = textView;
2631
this.tagAggregator = tagAggregator;
32+
33+
brushesManager = new BrushesManager(editorFormatMap);
34+
}
35+
36+
class BrushesManager
37+
{
38+
readonly Brush addBackground;
39+
readonly Brush deleteBackground;
40+
readonly Brush noneBackground;
41+
42+
internal BrushesManager(IEditorFormatMap editorFormatMap)
43+
{
44+
addBackground = TryGetValue<Brush>(editorFormatMap, "deltadiff.add.word", "Background");
45+
deleteBackground = TryGetValue<Brush>(editorFormatMap, "deltadiff.remove.word", "Background");
46+
noneBackground = TryGetValue<Brush>(editorFormatMap, "Indicator Margin", "Background");
47+
}
48+
49+
T TryGetValue<T>(IEditorFormatMap editorFormatMap, string key, string name) where T : class
50+
{
51+
var properties = editorFormatMap.GetProperties(key);
52+
return properties?[name] as T;
53+
}
54+
55+
internal Brush GetBrush(DiffChangeType diffChangeType)
56+
{
57+
switch (diffChangeType)
58+
{
59+
case DiffChangeType.Add:
60+
return addBackground;
61+
case DiffChangeType.Delete:
62+
return deleteBackground;
63+
case DiffChangeType.None:
64+
default:
65+
return noneBackground;
66+
}
67+
}
2768
}
2869

2970
public UIElement GenerateGlyph(IWpfTextViewLine line, InlineCommentTag tag)
@@ -34,6 +75,7 @@ public UIElement GenerateGlyph(IWpfTextViewLine line, InlineCommentTag tag)
3475
if (OpenThreadView(tag)) e.Handled = true;
3576
};
3677

78+
glyph.Background = brushesManager.GetBrush(tag.DiffChangeType);
3779
return glyph;
3880
}
3981

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using GitHub.Extensions;
22
using GitHub.Services;
3-
using Microsoft.VisualStudio.Text.Editor;
3+
using GitHub.Models;
44
using Microsoft.VisualStudio.Text.Tagging;
55

66
namespace GitHub.InlineReviews.Tags
@@ -9,15 +9,18 @@ abstract class InlineCommentTag : ITag
99
{
1010
public InlineCommentTag(
1111
IPullRequestSession session,
12-
int lineNumber)
12+
int lineNumber,
13+
DiffChangeType diffChangeType)
1314
{
1415
Guard.ArgumentNotNull(session, nameof(session));
1516

1617
LineNumber = lineNumber;
1718
Session = session;
19+
DiffChangeType = diffChangeType;
1820
}
1921

2022
public int LineNumber { get; }
2123
public IPullRequestSession Session { get; }
24+
public DiffChangeType DiffChangeType { get; }
2225
}
2326
}

src/GitHub.InlineReviews/Tags/InlineCommentTagger.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public IEnumerable<ITagSpan<InlineCommentTag>> GetTags(NormalizedSnapshotSpanCol
130130
var snapshotLine = span.Snapshot.GetLineFromLineNumber(lineNumber);
131131
yield return new TagSpan<InlineCommentTag>(
132132
new SnapshotSpan(snapshotLine.Start, snapshotLine.End),
133-
new AddInlineCommentTag(session, file.CommitSha, relativePath, line.DiffLineNumber, lineNumber));
133+
new AddInlineCommentTag(session, file.CommitSha, relativePath, line.DiffLineNumber, lineNumber, line.Type));
134134
}
135135
}
136136
}
Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
using System;
2-
using System.Windows.Media;
32
using System.Windows.Controls;
4-
using Microsoft.VisualStudio.PlatformUI;
53

64
namespace GitHub.InlineReviews.Tags
75
{
@@ -10,14 +8,7 @@ public partial class ShowInlineCommentGlyph : UserControl
108
public ShowInlineCommentGlyph()
119
{
1210
InitializeComponent();
13-
14-
Loaded += ShowInlineCommentGlyph_Loaded;
1511
}
1612

17-
void ShowInlineCommentGlyph_Loaded(object sender, System.Windows.RoutedEventArgs e)
18-
{
19-
var backgroundColor = ImageThemingUtilities.GetImageBackgroundColor(this);
20-
Background = new SolidColorBrush(backgroundColor);
21-
}
2213
}
2314
}

src/GitHub.InlineReviews/Tags/ShowInlineCommentTag.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class ShowInlineCommentTag : InlineCommentTag
1010
public ShowInlineCommentTag(
1111
IPullRequestSession session,
1212
IInlineCommentThreadModel thread)
13-
: base(session, thread.LineNumber)
13+
: base(session, thread.LineNumber, thread.DiffLineType)
1414
{
1515
Guard.ArgumentNotNull(thread, nameof(thread));
1616

0 commit comments

Comments
 (0)