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

Commit e25a915

Browse files
committed
Example: show tip when user changes GitHub repo
1 parent 482d710 commit e25a915

File tree

1 file changed

+38
-3
lines changed

1 file changed

+38
-3
lines changed

src/GitHub.InlineReviews/Services/PullRequestStatusBarManager.cs

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@
1616
using GitHub.Logging;
1717
using Serilog;
1818
using ReactiveUI;
19+
using GitHub.VisualStudio;
20+
using Microsoft.VisualStudio.Shell;
21+
using Microsoft;
22+
using GitHub.Services.Vssdk.Services;
23+
using Task = System.Threading.Tasks.Task;
24+
using Microsoft.VisualStudio.Threading;
1925

2026
namespace GitHub.InlineReviews.Services
2127
{
@@ -36,6 +42,7 @@ public class PullRequestStatusBarManager
3642
readonly Lazy<IPullRequestSessionManager> pullRequestSessionManager;
3743
readonly Lazy<ITeamExplorerContext> teamExplorerContext;
3844
readonly Lazy<IConnectionManager> connectionManager;
45+
readonly Lazy<IVsTippingService> tippingService;
3946

4047
[ImportingConstructor]
4148
public PullRequestStatusBarManager(
@@ -44,7 +51,8 @@ public PullRequestStatusBarManager(
4451
IShowCurrentPullRequestCommand showCurrentPullRequestCommand,
4552
Lazy<IPullRequestSessionManager> pullRequestSessionManager,
4653
Lazy<ITeamExplorerContext> teamExplorerContext,
47-
Lazy<IConnectionManager> connectionManager)
54+
Lazy<IConnectionManager> connectionManager,
55+
Lazy<IVsTippingService> tippingService)
4856
{
4957
this.openPullRequestsCommand = new UsageTrackingCommand(usageTracker,
5058
x => x.NumberOfStatusBarOpenPullRequestList, openPullRequestsCommand);
@@ -54,6 +62,8 @@ public PullRequestStatusBarManager(
5462
this.pullRequestSessionManager = pullRequestSessionManager;
5563
this.teamExplorerContext = teamExplorerContext;
5664
this.connectionManager = connectionManager;
65+
this.tippingService = tippingService;
66+
JoinableTaskFactory = ThreadHelper.JoinableTaskFactory;
5767
}
5868

5969
/// <summary>
@@ -90,7 +100,27 @@ async Task RefreshCurrentSession(LocalRepositoryModel repository, IPullRequestSe
90100
}
91101

92102
var viewModel = CreatePullRequestStatusViewModel(session);
93-
ShowStatus(viewModel);
103+
var view = ShowStatus(viewModel);
104+
105+
ShowCallout(view, repository);
106+
}
107+
108+
void ShowCallout(FrameworkElement view, LocalRepositoryModel repository)
109+
{
110+
JoinableTaskFactory.RunAsync(async () =>
111+
{
112+
await JoinableTaskFactory.SwitchToMainThreadAsync();
113+
114+
await Task.Delay(1000);
115+
var calloutId = new Guid("63b813cd-9292-4c0f-aa49-ebd888b791fa");
116+
var title = "GitHub repository opened";
117+
var message = repository.CloneUrl;
118+
var isDismissable = true;
119+
var commandSet = new Guid("E234E66E-BA64-4D71-B304-16F0A4C793F5");
120+
var commandId = (uint)0x4010; // View.TfsTeamExplorer
121+
tippingService.Value.RequestCalloutDisplay(calloutId, title, message,
122+
isDismissable, view, commandSet, commandId);
123+
});
94124
}
95125

96126
async Task<bool> IsDotComOrEnterpriseRepository(LocalRepositoryModel repository)
@@ -128,7 +158,7 @@ PullRequestStatusViewModel CreatePullRequestStatusViewModel(IPullRequestSession
128158
return pullRequestStatusViewModel;
129159
}
130160

131-
void ShowStatus(PullRequestStatusViewModel pullRequestStatusViewModel = null)
161+
PullRequestStatusView ShowStatus(PullRequestStatusViewModel pullRequestStatusViewModel = null)
132162
{
133163
var statusBar = FindSccStatusBar(Application.Current.MainWindow);
134164
if (statusBar != null)
@@ -144,8 +174,11 @@ void ShowStatus(PullRequestStatusViewModel pullRequestStatusViewModel = null)
144174
{
145175
githubStatusBar = new PullRequestStatusView { DataContext = pullRequestStatusViewModel };
146176
statusBar.Items.Insert(0, githubStatusBar);
177+
return githubStatusBar;
147178
}
148179
}
180+
181+
return null;
149182
}
150183

151184
static T Find<T>(StatusBar statusBar)
@@ -166,5 +199,7 @@ StatusBar FindSccStatusBar(Window mainWindow)
166199
var contentControl = mainWindow?.Template?.FindName(StatusBarPartName, mainWindow) as ContentControl;
167200
return contentControl?.Content as StatusBar;
168201
}
202+
203+
JoinableTaskFactory JoinableTaskFactory { get; }
169204
}
170205
}

0 commit comments

Comments
 (0)