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

Commit 10e70eb

Browse files
committed
Open details view when PR status is clicked on
1 parent f141e91 commit 10e70eb

File tree

3 files changed

+73
-19
lines changed

3 files changed

+73
-19
lines changed

src/GitHub.InlineReviews/Services/PullRequestStatusManager.cs

Lines changed: 62 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
using System;
22
using System.Windows;
33
using System.Windows.Media;
4+
using System.Windows.Input;
45
using System.Windows.Controls;
56
using System.Windows.Controls.Primitives;
7+
using System.ComponentModel;
68
using System.ComponentModel.Composition;
79
using GitHub.InlineReviews.Views;
810
using GitHub.InlineReviews.ViewModels;
911
using GitHub.Services;
10-
using System.ComponentModel;
12+
using GitHub.VisualStudio;
13+
using Microsoft.VisualStudio.Shell;
1114

1215
namespace GitHub.InlineReviews.Services
1316
{
@@ -22,29 +25,15 @@ public class PullRequestStatusManager : IPullRequestStatusManager
2225
readonly PullRequestStatusViewModel pullRequestStatusViewModel;
2326

2427
[ImportingConstructor]
25-
public PullRequestStatusManager(IPullRequestSessionManager pullRequestSessionManager) : this(new PullRequestStatusViewModel())
28+
public PullRequestStatusManager(SVsServiceProvider serviceProvider, IPullRequestSessionManager pullRequestSessionManager)
29+
: this(CreatePullRequestStatusViewModel(serviceProvider))
2630
{
2731
this.pullRequestSessionManager = pullRequestSessionManager;
2832

2933
RefreshCurrentSession();
3034
pullRequestSessionManager.PropertyChanged += PullRequestSessionManager_PropertyChanged;
3135
}
3236

33-
void PullRequestSessionManager_PropertyChanged(object sender, PropertyChangedEventArgs e)
34-
{
35-
if (e.PropertyName == nameof(PullRequestSessionManager.CurrentSession))
36-
{
37-
RefreshCurrentSession();
38-
}
39-
}
40-
41-
void RefreshCurrentSession()
42-
{
43-
var pullRequest = pullRequestSessionManager.CurrentSession?.PullRequest;
44-
pullRequestStatusViewModel.Number = pullRequest?.Number;
45-
pullRequestStatusViewModel.Title = pullRequest?.Title;
46-
}
47-
4837
public PullRequestStatusManager(PullRequestStatusViewModel pullRequestStatusViewModel)
4938
{
5039
this.pullRequestStatusViewModel = pullRequestStatusViewModel;
@@ -78,6 +67,27 @@ public void HideStatus()
7867
}
7968
}
8069

70+
static PullRequestStatusViewModel CreatePullRequestStatusViewModel(IServiceProvider serviceProvider)
71+
{
72+
var command = new RaiseVsCommand(serviceProvider, Guids.guidGitHubCmdSetString, PkgCmdIDList.showCurrentPullRequestCommand);
73+
return new PullRequestStatusViewModel(command);
74+
}
75+
76+
void PullRequestSessionManager_PropertyChanged(object sender, PropertyChangedEventArgs e)
77+
{
78+
if (e.PropertyName == nameof(PullRequestSessionManager.CurrentSession))
79+
{
80+
RefreshCurrentSession();
81+
}
82+
}
83+
84+
void RefreshCurrentSession()
85+
{
86+
var pullRequest = pullRequestSessionManager.CurrentSession?.PullRequest;
87+
pullRequestStatusViewModel.Number = pullRequest?.Number;
88+
pullRequestStatusViewModel.Title = pullRequest?.Title;
89+
}
90+
8191
static UserControl FindPullRequestStatusView(StatusBar statusBar)
8292
{
8393
return FindChild<UserControl>(statusBar, GitHubStatusName);
@@ -132,12 +142,46 @@ static T FindChild<T>(DependencyObject parent, string childName) where T : Depen
132142
return foundChild;
133143
}
134144

145+
class RaiseVsCommand : ICommand
146+
{
147+
readonly IServiceProvider serviceProvider;
148+
readonly string guid;
149+
readonly int id;
150+
151+
internal RaiseVsCommand(IServiceProvider serviceProvider, string guid, int id)
152+
{
153+
this.serviceProvider = serviceProvider;
154+
this.guid = guid;
155+
this.id = id;
156+
}
157+
158+
public bool CanExecute(object parameter) => true;
159+
160+
public void Execute(object parameter)
161+
{
162+
try
163+
{
164+
var dte = serviceProvider.GetService(typeof(EnvDTE.DTE)) as EnvDTE.DTE;
165+
object customIn = null;
166+
object customOut = null;
167+
dte.Commands.Raise(guid, id, ref customIn, ref customOut);
168+
}
169+
catch (Exception e)
170+
{
171+
VsOutputLogger.WriteLine("Couldn't raise {0}: {1}", nameof(PkgCmdIDList.openPullRequestsCommand), e);
172+
System.Diagnostics.Trace.WriteLine(e);
173+
}
174+
}
175+
176+
public event EventHandler CanExecuteChanged;
177+
}
178+
135179
class PullRequestStatusManagerInstaller
136180
{
137181
[STAThread]
138182
void Install()
139183
{
140-
var viewModel = new PullRequestStatusViewModel { Number = 666, Title = "A beast of a PR" };
184+
var viewModel = new PullRequestStatusViewModel(null) { Number = 666, Title = "A beast of a PR" };
141185
var provider = new PullRequestStatusManager(viewModel);
142186
provider.HideStatus();
143187
provider.ShowStatus();

src/GitHub.InlineReviews/ViewModels/PullRequestStatusViewModel.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Windows.Input;
23
using System.ComponentModel;
34

45
namespace GitHub.InlineReviews.ViewModels
@@ -8,6 +9,11 @@ public class PullRequestStatusViewModel : INotifyPropertyChanged
89
int? number;
910
string title;
1011

12+
public PullRequestStatusViewModel(ICommand showCurrentPullRequestCommand)
13+
{
14+
ShowCurrentPullRequestCommand = showCurrentPullRequestCommand;
15+
}
16+
1117
public int? Number
1218
{
1319
get { return number; }
@@ -34,6 +40,8 @@ public string Title
3440
}
3541
}
3642

43+
public ICommand ShowCurrentPullRequestCommand { get; }
44+
3745
public event PropertyChangedEventHandler PropertyChanged;
3846
}
3947
}

src/GitHub.InlineReviews/Views/PullRequestStatusView.xaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
d:DesignHeight="20" d:DesignWidth="60">
99

1010
<Grid Visibility="{Binding Number, TargetNullValue=Collapsed}">
11-
<TextBlock>PR# <Run Text="{Binding Number}" /></TextBlock>
11+
<Button Command="{Binding ShowCurrentPullRequestCommand}">
12+
<TextBlock>PR #<Run Text="{Binding Number}" /></TextBlock>
13+
</Button>
1214
<Grid.ToolTip>
1315
<TextBlock Text="{Binding Title}" />
1416
</Grid.ToolTip>

0 commit comments

Comments
 (0)