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

Commit 93c6738

Browse files
committed
Show how many comments there are on current document
1 parent 4a4ba04 commit 93c6738

File tree

4 files changed

+43
-10
lines changed

4 files changed

+43
-10
lines changed

src/GitHub.InlineReviews/CommentsMargin.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
using System;
22
using System.Windows;
3+
using GitHub.Services;
34
using Microsoft.VisualStudio.Text.Editor;
45
using GitHub.InlineReviews.Views;
56
using GitHub.InlineReviews.ViewModels;
67
using GitHub.InlineReviews.Commands;
7-
using System.Windows.Input;
88

99
namespace GitHub.InlineReviews
1010
{
@@ -29,9 +29,10 @@ internal class CommentsMargin : IWpfTextViewMargin
2929
/// Initializes a new instance of the <see cref="ToggleCommentsMargin"/> class for a given <paramref name="textView"/>.
3030
/// </summary>
3131
/// <param name="textView">The <see cref="IWpfTextView"/> to attach the margin to.</param>
32-
public CommentsMargin(IWpfTextView textView, IEnableInlineCommentsCommand enableInlineCommentsCommand)
32+
public CommentsMargin(IWpfTextView textView, IEnableInlineCommentsCommand enableInlineCommentsCommand,
33+
IPullRequestSessionManager sessionManager)
3334
{
34-
var viewModel = new CommentsMarginViewModel(enableInlineCommentsCommand);
35+
var viewModel = new CommentsMarginViewModel(sessionManager, textView.TextBuffer, enableInlineCommentsCommand);
3536
visualElement = new CommentsMarginView { DataContext = viewModel, ClipToBounds = true };
3637
}
3738

src/GitHub.InlineReviews/CommentsMarginProvider.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
using System;
22
using System.ComponentModel.Composition;
3-
using GitHub.InlineReviews.Commands;
43
using Microsoft.VisualStudio.Utilities;
54
using Microsoft.VisualStudio.Text.Editor;
5+
using GitHub.Services;
6+
using GitHub.InlineReviews.Commands;
67

78
namespace GitHub.InlineReviews
89
{
@@ -18,11 +19,13 @@ namespace GitHub.InlineReviews
1819
internal sealed class CommentsMarginFactory : IWpfTextViewMarginProvider
1920
{
2021
readonly IEnableInlineCommentsCommand enableInlineCommentsCommand;
22+
readonly IPullRequestSessionManager sessionManager;
2123

2224
[ImportingConstructor]
23-
public CommentsMarginFactory(IEnableInlineCommentsCommand enableInlineCommentsCommand)
25+
public CommentsMarginFactory(IEnableInlineCommentsCommand enableInlineCommentsCommand, IPullRequestSessionManager sessionManager)
2426
{
2527
this.enableInlineCommentsCommand = enableInlineCommentsCommand;
28+
this.sessionManager = sessionManager;
2629
}
2730

2831
/// <summary>
@@ -35,7 +38,7 @@ public CommentsMarginFactory(IEnableInlineCommentsCommand enableInlineCommentsCo
3538
/// </returns>
3639
public IWpfTextViewMargin CreateMargin(IWpfTextViewHost wpfTextViewHost, IWpfTextViewMargin marginContainer)
3740
{
38-
return new CommentsMargin(wpfTextViewHost.TextView, enableInlineCommentsCommand);
41+
return new CommentsMargin(wpfTextViewHost.TextView, enableInlineCommentsCommand, sessionManager);
3942
}
4043
}
4144
}

src/GitHub.InlineReviews/ViewModels/CommentsMarginViewModel.cs

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,44 @@
11
using System.Windows.Input;
2+
using GitHub.Services;
3+
using GitHub.Extensions;
4+
using Microsoft.VisualStudio.Text;
5+
using ReactiveUI;
6+
using Task = System.Threading.Tasks.Task;
27

38
namespace GitHub.InlineReviews.ViewModels
49
{
5-
public class CommentsMarginViewModel
10+
public class CommentsMarginViewModel : ReactiveObject
611
{
7-
public CommentsMarginViewModel(ICommand enableInlineComments)
12+
readonly IPullRequestSessionManager sessionManager;
13+
readonly ITextBuffer textBuffer;
14+
15+
int commentsInFile;
16+
17+
public CommentsMarginViewModel(IPullRequestSessionManager sessionManager, ITextBuffer textBuffer, ICommand enableInlineComments)
818
{
19+
this.sessionManager = sessionManager;
20+
this.textBuffer = textBuffer;
21+
922
EnableInlineComments = enableInlineComments;
23+
InitializeAsync().Forget();
24+
}
25+
26+
async Task InitializeAsync()
27+
{
28+
await sessionManager.EnsureInitialized();
29+
var relativePath = sessionManager.GetRelativePath(textBuffer);
30+
if (relativePath != null)
31+
{
32+
var sessionFile = await sessionManager.CurrentSession.GetFile(relativePath);
33+
CommentsInFile = sessionFile?.InlineCommentThreads?.Count ?? -1;
34+
}
1035
}
1136

12-
public int CommentsInFile { get; } = 777;
37+
public int CommentsInFile
38+
{
39+
get { return commentsInFile; }
40+
private set { this.RaiseAndSetIfChanged(ref commentsInFile, value); }
41+
}
1342

1443
public ICommand EnableInlineComments { get; }
1544
}

src/GitHub.InlineReviews/Views/CommentsMarginView.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
</Button.Content>
2525
</Button>
2626
<Hyperlink>
27-
<Run Text="{Binding CommentsInFile, Mode=OneWay}"/>
27+
<Run Text="{Binding CommentsInFile}"/>
2828
</Hyperlink>
2929
</TextBlock>
3030
</Grid>

0 commit comments

Comments
 (0)