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

Commit 25fbc2f

Browse files
Adding autocomplete functionality to inline comment view, pull request review and conversation view comments
1 parent be1ab80 commit 25fbc2f

File tree

15 files changed

+169
-90
lines changed

15 files changed

+169
-90
lines changed

src/GitHub.App/SampleData/CommentViewModelDesigner.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Reactive;
44
using System.Threading.Tasks;
55
using GitHub.Models;
6+
using GitHub.Services;
67
using GitHub.ViewModels;
78
using ReactiveUI;
89

@@ -37,6 +38,7 @@ public CommentViewModelDesigner()
3738
public ReactiveCommand<Unit, Unit> CommitEdit { get; }
3839
public ReactiveCommand<Unit, Unit> OpenOnGitHub { get; } = ReactiveCommand.Create(() => { });
3940
public ReactiveCommand<Unit, Unit> Delete { get; }
41+
public IAutoCompleteAdvisor AutoCompleteAdvisor { get; }
4042

4143
public Task InitializeAsync(ICommentThreadViewModel thread, ActorModel currentUser, CommentModel comment, CommentEditState state)
4244
{

src/GitHub.App/SampleData/PullRequestReviewAuthoringViewModelDesigner.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Reactive;
44
using System.Threading.Tasks;
55
using GitHub.Models;
6+
using GitHub.Services;
67
using GitHub.ViewModels.GitHubPane;
78
using ReactiveUI;
89

@@ -53,6 +54,7 @@ public PullRequestReviewAuthoringViewModelDesigner()
5354
public ReactiveCommand<Unit, Unit> Comment { get; }
5455
public ReactiveCommand<Unit, Unit> RequestChanges { get; }
5556
public ReactiveCommand<Unit, Unit> Cancel { get; }
57+
public IAutoCompleteAdvisor AutoCompleteAdvisor { get; }
5658

5759
public Task InitializeAsync(
5860
LocalRepositoryModel localRepository,

src/GitHub.App/ViewModels/CommentViewModel.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,14 @@ public class CommentViewModel : ViewModelBase, ICommentViewModel
4141
/// Initializes a new instance of the <see cref="CommentViewModel"/> class.
4242
/// </summary>
4343
/// <param name="commentService">The comment service.</param>
44+
/// <param name="autoCompleteAdvisor">The auto complete advisor.</param>
4445
[ImportingConstructor]
45-
public CommentViewModel(ICommentService commentService)
46+
public CommentViewModel(ICommentService commentService, IAutoCompleteAdvisor autoCompleteAdvisor)
4647
{
4748
Guard.ArgumentNotNull(commentService, nameof(commentService));
49+
Guard.ArgumentNotNull(autoCompleteAdvisor, nameof(autoCompleteAdvisor));
4850

51+
AutoCompleteAdvisor = autoCompleteAdvisor;
4952
this.commentService = commentService;
5053

5154
var canDeleteObservable = this.WhenAnyValue(
@@ -190,6 +193,9 @@ public ICommentThreadViewModel Thread
190193
/// <inheritdoc/>
191194
public ReactiveCommand<Unit, Unit> Delete { get; }
192195

196+
/// <inheritdoc/>
197+
public IAutoCompleteAdvisor AutoCompleteAdvisor { get; }
198+
193199
/// <inheritdoc/>
194200
public Task InitializeAsync(
195201
ICommentThreadViewModel thread,

src/GitHub.App/ViewModels/Documents/IssueishCommentViewModel.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ public sealed class IssueishCommentViewModel : CommentViewModel, IIssueishCommen
2323
/// Initializes a new instance of the <see cref="CommentViewModel"/> class.
2424
/// </summary>
2525
/// <param name="commentService">The comment service.</param>
26+
/// <param name="autoCompleteAdvisor"></param>
2627
[ImportingConstructor]
27-
public IssueishCommentViewModel(ICommentService commentService)
28-
: base(commentService)
28+
public IssueishCommentViewModel(ICommentService commentService, IAutoCompleteAdvisor autoCompleteAdvisor)
29+
: base(commentService, autoCompleteAdvisor)
2930
{
3031
CloseOrReopen = ReactiveCommand.CreateFromTask(
3132
DoCloseOrReopen,

src/GitHub.App/ViewModels/GitHubPane/PullRequestReviewAuthoringViewModel.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ public PullRequestReviewAuthoringViewModel(
4545
IPullRequestEditorService editorService,
4646
IPullRequestSessionManager sessionManager,
4747
IMessageDraftStore draftStore,
48-
IPullRequestFilesViewModel files)
49-
: this(pullRequestService, editorService, sessionManager,draftStore, files, DefaultScheduler.Instance)
48+
IPullRequestFilesViewModel files,
49+
IAutoCompleteAdvisor autoCompleteAdvisor)
50+
: this(pullRequestService, editorService, sessionManager,draftStore, files, autoCompleteAdvisor, DefaultScheduler.Instance)
5051
{
5152
}
5253

@@ -56,12 +57,14 @@ public PullRequestReviewAuthoringViewModel(
5657
IPullRequestSessionManager sessionManager,
5758
IMessageDraftStore draftStore,
5859
IPullRequestFilesViewModel files,
60+
IAutoCompleteAdvisor autoCompleteAdvisor,
5961
IScheduler timerScheduler)
6062
{
6163
Guard.ArgumentNotNull(editorService, nameof(editorService));
6264
Guard.ArgumentNotNull(sessionManager, nameof(sessionManager));
6365
Guard.ArgumentNotNull(draftStore, nameof(draftStore));
6466
Guard.ArgumentNotNull(files, nameof(files));
67+
Guard.ArgumentNotNull(autoCompleteAdvisor, nameof(autoCompleteAdvisor));
6568
Guard.ArgumentNotNull(timerScheduler, nameof(timerScheduler));
6669

6770
this.pullRequestService = pullRequestService;
@@ -77,6 +80,7 @@ public PullRequestReviewAuthoringViewModel(
7780
.ToProperty(this, x => x.CanApproveRequestChanges);
7881

7982
Files = files;
83+
AutoCompleteAdvisor = autoCompleteAdvisor;
8084

8185
var hasBodyOrComments = this.WhenAnyValue(
8286
x => x.Body,
@@ -118,6 +122,9 @@ public PullRequestDetailModel PullRequestModel
118122
/// <inheritdoc/>
119123
public IPullRequestFilesViewModel Files { get; }
120124

125+
/// <inheritdoc/>
126+
public IAutoCompleteAdvisor AutoCompleteAdvisor { get; }
127+
121128
/// <inheritdoc/>
122129
public string Body
123130
{

src/GitHub.App/ViewModels/PullRequestReviewCommentViewModel.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@ public class PullRequestReviewCommentViewModel : CommentViewModel, IPullRequestR
2525
/// <summary>
2626
/// Initializes a new instance of the <see cref="PullRequestReviewCommentViewModel"/> class.
2727
/// </summary>
28-
/// <param name="commentService">The comment service</param>
28+
/// <param name="commentService">The comment service.</param>
29+
/// <param name="autoCompleteAdvisor">The auto complete advisor.</param>
2930
[ImportingConstructor]
30-
public PullRequestReviewCommentViewModel(ICommentService commentService)
31-
: base(commentService)
31+
public PullRequestReviewCommentViewModel(ICommentService commentService,
32+
IAutoCompleteAdvisor autoCompleteAdvisor)
33+
: base(commentService, autoCompleteAdvisor)
3234
{
3335
canStartReview = this.WhenAnyValue(
3436
x => x.IsPending,

src/GitHub.Exports.Reactive/ViewModels/GitHubPane/IPullRequestReviewAuthoringViewModel.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Reactive;
44
using System.Threading.Tasks;
55
using GitHub.Models;
6+
using GitHub.Services;
67
using ReactiveUI;
78

89
namespace GitHub.ViewModels.GitHubPane
@@ -87,6 +88,11 @@ public interface IPullRequestReviewAuthoringViewModel : IPanePageViewModel, IDis
8788
/// </summary>
8889
ReactiveCommand<Unit, Unit> Cancel { get; }
8990

91+
/// <summary>
92+
/// Provides an AutoCompleteAdvisor.
93+
/// </summary>
94+
IAutoCompleteAdvisor AutoCompleteAdvisor { get; }
95+
9096
/// <summary>
9197
/// Initializes the view model for creating a new review.
9298
/// </summary>

src/GitHub.Exports.Reactive/ViewModels/ICommentViewModel.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Reactive;
3+
using GitHub.Services;
34
using ReactiveUI;
45

56
namespace GitHub.ViewModels
@@ -119,5 +120,10 @@ public interface ICommentViewModel : IViewModel
119120
/// Deletes a comment.
120121
/// </summary>
121122
ReactiveCommand<Unit, Unit> Delete { get; }
123+
124+
/// <summary>
125+
/// Provides an AutoCompleteAdvisor.
126+
/// </summary>
127+
IAutoCompleteAdvisor AutoCompleteAdvisor { get; }
122128
}
123129
}

src/GitHub.VisualStudio.UI/Views/Documents/IssueishCommentView.xaml

Lines changed: 47 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -128,39 +128,53 @@
128128
<Separator Grid.Column="1" Grid.ColumnSpan="2" Grid.Row="0" Margin="0 0 0 4"
129129
Background="{DynamicResource GitHubButtonBorderBrush}"/>
130130

131-
<ui:PromptTextBox Name="body"
132-
Grid.Column="2"
133-
Grid.Row="1"
134-
AcceptsReturn="True"
135-
AcceptsTab="True"
136-
IsReadOnly="{Binding IsReadOnly}"
137-
Margin="4 0 4 4"
138-
Text="{Binding Body, UpdateSourceTrigger=PropertyChanged}"
139-
TextWrapping="Wrap"
140-
VerticalAlignment="Center"
141-
GotFocus="ReplyPlaceholder_GotFocus"
142-
Loaded="body_Loaded"
143-
SpellCheck.IsEnabled="True">
144-
<ui:PromptTextBox.Style>
145-
<Style TargetType="ui:PromptTextBox" BasedOn="{StaticResource GitHubVsPromptTextBox}">
146-
<Setter Property="Height" Value="28"/>
147-
<Setter Property="PromptText" Value="Reply..."/>
148-
149-
<Style.Triggers>
150-
<DataTrigger Binding="{Binding EditState}" Value="Editing">
151-
<Setter Property="MinHeight" Value="100"/>
152-
<Setter Property="PromptText" Value="Leave a comment"/>
153-
</DataTrigger>
154-
</Style.Triggers>
155-
156-
<Style.Resources>
157-
<Style TargetType="TextBlock">
158-
<Setter Property="Foreground" Value="{DynamicResource GitHubVsToolWindowText}" />
159-
</Style>
160-
</Style.Resources>
161-
</Style>
162-
</ui:PromptTextBox.Style>
163-
</ui:PromptTextBox>
131+
<ghfvs:AutoCompleteBox
132+
133+
Grid.Column="2"
134+
Grid.Row="1"
135+
Margin="4 0 4 4"
136+
Advisor="{Binding AutoCompleteAdvisor}"
137+
>
138+
<ghfvs:AutoCompleteBox.ItemTemplate>
139+
<DataTemplate>
140+
<ghfvs:AutoCompleteSuggestionView ViewModel="{Binding}" />
141+
</DataTemplate>
142+
</ghfvs:AutoCompleteBox.ItemTemplate>
143+
<ghfvs:AutoCompleteBox.InputElement>
144+
<ghfvs:TextBoxAutoCompleteTextInput>
145+
<ui:PromptTextBox Name="body"
146+
AcceptsReturn="True"
147+
AcceptsTab="True"
148+
IsReadOnly="{Binding IsReadOnly}"
149+
Text="{Binding Body, UpdateSourceTrigger=PropertyChanged}"
150+
TextWrapping="Wrap"
151+
VerticalAlignment="Center"
152+
GotFocus="ReplyPlaceholder_GotFocus"
153+
Loaded="body_Loaded"
154+
SpellCheck.IsEnabled="True">
155+
<ui:PromptTextBox.Style>
156+
<Style TargetType="ui:PromptTextBox" BasedOn="{StaticResource GitHubVsPromptTextBox}">
157+
<Setter Property="Height" Value="28"/>
158+
<Setter Property="PromptText" Value="Reply..."/>
159+
160+
<Style.Triggers>
161+
<DataTrigger Binding="{Binding EditState}" Value="Editing">
162+
<Setter Property="MinHeight" Value="100"/>
163+
<Setter Property="PromptText" Value="Leave a comment"/>
164+
</DataTrigger>
165+
</Style.Triggers>
166+
167+
<Style.Resources>
168+
<Style TargetType="TextBlock">
169+
<Setter Property="Foreground" Value="{DynamicResource GitHubVsToolWindowText}" />
170+
</Style>
171+
</Style.Resources>
172+
</Style>
173+
</ui:PromptTextBox.Style>
174+
</ui:PromptTextBox>
175+
</ghfvs:TextBoxAutoCompleteTextInput>
176+
</ghfvs:AutoCompleteBox.InputElement>
177+
</ghfvs:AutoCompleteBox>
164178

165179
<DockPanel Grid.Column="2" Grid.Row="2"
166180
Margin="0 4"

src/GitHub.VisualStudio.UI/Views/GitHubPane/PullRequestReviewAuthoringView.xaml

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,30 @@
4141
</TextBlock>
4242
<TextBlock Foreground="{DynamicResource GitHubVsGrayText}" Text="{Binding PullRequestModel.Title}" TextWrapping="Wrap"/>
4343
<TextBlock Margin="0 12 0 4" Text="{x:Static ghfvs:Resources.YourReviewSummary}"/>
44-
<TextBox AcceptsReturn="True"
45-
Background="{DynamicResource VsBrush.BrandedUIBackground}"
46-
Foreground="{DynamicResource VsBrush.BrandedUIText}"
47-
BorderBrush="{DynamicResource VsBrush.ActiveBorder}"
48-
Margin="0 4"
49-
MinHeight="120"
50-
Padding="0 4"
51-
TextWrapping="Wrap"
52-
Text="{Binding Body}"
53-
SpellCheck.IsEnabled="True"/>
5444

45+
<ui:AutoCompleteBox
46+
Padding="0 4"
47+
Margin="0 4"
48+
Advisor="{Binding AutoCompleteAdvisor}">
49+
<ui:AutoCompleteBox.ItemTemplate>
50+
<DataTemplate>
51+
<ui:AutoCompleteSuggestionView ViewModel="{Binding}" />
52+
</DataTemplate>
53+
</ui:AutoCompleteBox.ItemTemplate>
54+
<ui:AutoCompleteBox.InputElement>
55+
<ui:TextBoxAutoCompleteTextInput>
56+
<TextBox AcceptsReturn="True"
57+
Background="{DynamicResource VsBrush.BrandedUIBackground}"
58+
Foreground="{DynamicResource VsBrush.BrandedUIText}"
59+
BorderBrush="{DynamicResource VsBrush.ActiveBorder}"
60+
MinHeight="120"
61+
TextWrapping="Wrap"
62+
Text="{Binding Body}"
63+
SpellCheck.IsEnabled="True"/>
64+
</ui:TextBoxAutoCompleteTextInput>
65+
</ui:AutoCompleteBox.InputElement>
66+
</ui:AutoCompleteBox>
67+
5568
<StackPanel Margin="0 4" Orientation="Horizontal">
5669
<ui:DropDownButton AutoCloseOnClick="True" Foreground="{DynamicResource GHBlueLinkButtonTextBrush}">
5770
<ui:GitHubActionLink>Submit review</ui:GitHubActionLink>

0 commit comments

Comments
 (0)