Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/GitHub.Exports/Services/IVsTippingService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;
using System.Windows;

namespace GitHub.Services
{
public interface IVsTippingService
{
void RequestCalloutDisplay(Guid calloutId, string title, string message,
bool isPermanentlyDismissible, FrameworkElement targetElement, Guid vsCommandGroupId, uint vsCommandId);
}
}
46 changes: 38 additions & 8 deletions src/GitHub.InlineReviews/Services/PullRequestStatusBarManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using GitHub.Logging;
using Serilog;
using ReactiveUI;
using GitHub.VisualStudio;

namespace GitHub.InlineReviews.Services
{
Expand All @@ -36,6 +37,7 @@ public class PullRequestStatusBarManager
readonly Lazy<IPullRequestSessionManager> pullRequestSessionManager;
readonly Lazy<ITeamExplorerContext> teamExplorerContext;
readonly Lazy<IConnectionManager> connectionManager;
readonly Lazy<IVsTippingService> tippingService;

[ImportingConstructor]
public PullRequestStatusBarManager(
Expand All @@ -44,7 +46,8 @@ public PullRequestStatusBarManager(
IShowCurrentPullRequestCommand showCurrentPullRequestCommand,
Lazy<IPullRequestSessionManager> pullRequestSessionManager,
Lazy<ITeamExplorerContext> teamExplorerContext,
Lazy<IConnectionManager> connectionManager)
Lazy<IConnectionManager> connectionManager,
Lazy<IVsTippingService> tippingService)
{
this.openPullRequestsCommand = new UsageTrackingCommand(usageTracker,
x => x.NumberOfStatusBarOpenPullRequestList, openPullRequestsCommand);
Expand All @@ -54,6 +57,7 @@ public PullRequestStatusBarManager(
this.pullRequestSessionManager = pullRequestSessionManager;
this.teamExplorerContext = teamExplorerContext;
this.connectionManager = connectionManager;
this.tippingService = tippingService;
}

/// <summary>
Expand Down Expand Up @@ -82,15 +86,38 @@ public void StartShowingStatus()

async Task RefreshCurrentSession(ILocalRepositoryModel repository, IPullRequestSession session)
{
var showStatus = await IsDotComOrEnterpriseRepository(repository);
if (!showStatus)
try
{
var showStatus = await IsDotComOrEnterpriseRepository(repository);
if (!showStatus)
{
ShowStatus(null);
return;
}

var viewModel = CreatePullRequestStatusViewModel(session);
var view = ShowStatus(viewModel);
if (view != null)
{
view.Loaded += (s, e) => ShowCallout(view, repository);
}
}
catch (Exception e)
{
ShowStatus(null);
return;
log.Error(e, nameof(RefreshCurrentSession));
}
}

var viewModel = CreatePullRequestStatusViewModel(session);
ShowStatus(viewModel);
void ShowCallout(FrameworkElement view, ILocalRepositoryModel repository)
{
var calloutId = new Guid("63b813cd-9292-4c0f-aa49-ebd888b791f9");
var title = "GitHub repository opened";
var message = repository.CloneUrl;
var isDismissable = true;
var commandSet = new Guid("E234E66E-BA64-4D71-B304-16F0A4C793F5");
var commandId = (uint)0x4010; // View.TfsTeamExplorer
tippingService.Value.RequestCalloutDisplay(calloutId, title, message,
isDismissable, view, commandSet, commandId);
}

async Task<bool> IsDotComOrEnterpriseRepository(ILocalRepositoryModel repository)
Expand Down Expand Up @@ -128,7 +155,7 @@ PullRequestStatusViewModel CreatePullRequestStatusViewModel(IPullRequestSession
return pullRequestStatusViewModel;
}

void ShowStatus(PullRequestStatusViewModel pullRequestStatusViewModel = null)
PullRequestStatusView ShowStatus(PullRequestStatusViewModel pullRequestStatusViewModel = null)
{
var statusBar = FindSccStatusBar(Application.Current.MainWindow);
if (statusBar != null)
Expand All @@ -144,8 +171,11 @@ void ShowStatus(PullRequestStatusViewModel pullRequestStatusViewModel = null)
{
githubStatusBar = new PullRequestStatusView { DataContext = pullRequestStatusViewModel };
statusBar.Items.Insert(0, githubStatusBar);
return githubStatusBar;
}
}

return null;
}

static T Find<T>(StatusBar statusBar)
Expand Down
6 changes: 6 additions & 0 deletions src/GitHub.Services.Vssdk/GitHub.Services.Vssdk.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,10 @@
<ProjectReference Include="..\GitHub.Exports\GitHub.Exports.csproj" />
<ProjectReference Include="..\GitHub.Extensions\GitHub.Extensions.csproj" />
</ItemGroup>

<ItemGroup>
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="WindowsBase" />
</ItemGroup>
</Project>
70 changes: 70 additions & 0 deletions src/GitHub.Services.Vssdk/Services/VsTippingService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using System;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Windows;
using Microsoft;
using IServiceProvider = System.IServiceProvider;

namespace GitHub.Services.Vssdk.Services
{
public class VsTippingService : IVsTippingService
{
// This is the only supported ClientId
readonly Guid ClientId = new Guid("D5D3B674-05BB-4942-B8EC-C3D13B5BD6EE");

readonly IServiceProvider serviceProvider;

public VsTippingService(IServiceProvider serviceProvider)
{
this.serviceProvider = serviceProvider;
}

public void RequestCalloutDisplay(Guid calloutId, string title, string message,
bool isPermanentlyDismissible, FrameworkElement targetElement,
Guid vsCommandGroupId, uint vsCommandId)
{
var screenPoint = targetElement.PointToScreen(new Point(targetElement.ActualWidth / 2, 0));
var point = new Microsoft.VisualStudio.OLE.Interop.POINT { x = (int)screenPoint.X, y = (int)screenPoint.Y };
RequestCalloutDisplay(ClientId, calloutId, title, message, isPermanentlyDismissible,
point, vsCommandGroupId, vsCommandId);
}

// Available on Visual Studio 2017
void RequestCalloutDisplay(Guid clientId, Guid calloutId, string title, string message,
bool isPermanentlyDismissible, FrameworkElement targetElement,
Guid vsCommandGroupId, uint vsCommandId, object commandOption = null)
{
var tippingService = serviceProvider.GetService(typeof(SVsTippingService));
Assumes.Present(tippingService);
var currentMethod = MethodBase.GetCurrentMethod();
var parameterTypes = currentMethod.GetParameters().Select(p => p.ParameterType).ToArray();
var method = tippingService.GetType().GetMethod(currentMethod.Name, parameterTypes);
var arguments = new object[] { clientId, calloutId, title, message, isPermanentlyDismissible, targetElement,
vsCommandGroupId, vsCommandId, commandOption };
method.Invoke(tippingService, arguments);
}

// Available on Visual Studio 2015
void RequestCalloutDisplay(Guid clientId, Guid calloutId, string title, string message, bool isPermanentlyDismissible,
Microsoft.VisualStudio.OLE.Interop.POINT anchor, Guid vsCommandGroupId, uint vsCommandId)
{
var tippingService = serviceProvider.GetService(typeof(SVsTippingService));
Assumes.Present(tippingService);
var currentMethod = MethodBase.GetCurrentMethod();
var parameterTypes = currentMethod.GetParameters().Select(p => p.ParameterType).ToArray();
var method = tippingService.GetType().GetMethod(currentMethod.Name, parameterTypes);
var arguments = new object[] { clientId, calloutId, title, message, isPermanentlyDismissible, anchor,
vsCommandGroupId, vsCommandId };
method.Invoke(tippingService, arguments);
}
}

[Guid("DCCC6A2B-F300-4DA1-92E1-8BF4A5BCA795")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[TypeIdentifier]
[ComImport]
public interface SVsTippingService
{
}
}
10 changes: 10 additions & 0 deletions src/GitHub.VisualStudio/GitHubPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using GitHub.VisualStudio.Helpers;
using GitHub.VisualStudio.Commands;
using GitHub.Services.Vssdk.Commands;
using GitHub.Services.Vssdk.Services;
using GitHub.ViewModels.GitHubPane;
using GitHub.VisualStudio.Settings;
using GitHub.VisualStudio.UI;
Expand Down Expand Up @@ -150,6 +151,9 @@ public ServiceProviderExports([Import(typeof(SVsServiceProvider))] IServiceProvi
[ExportForVisualStudioProcess]
public IPackageSettings PackageSettings => GetService<IPackageSettings>();

[ExportForVisualStudioProcess]
public IVsTippingService TippingService => GetService<IVsTippingService>();

T GetService<T>() => (T)serviceProvider.GetService(typeof(T));
}

Expand All @@ -161,6 +165,7 @@ public ServiceProviderExports([Import(typeof(SVsServiceProvider))] IServiceProvi
[ProvideService(typeof(IUsageService), IsAsyncQueryable = true)]
[ProvideService(typeof(IVSGitExt), IsAsyncQueryable = true)]
[ProvideService(typeof(IGitHubToolWindowManager))]
[ProvideService(typeof(IVsTippingService))]
[Guid(ServiceProviderPackageId)]
public sealed class ServiceProviderPackage : AsyncPackage, IServiceProviderPackage, IGitHubToolWindowManager
{
Expand All @@ -178,6 +183,7 @@ protected override async Task InitializeAsync(CancellationToken cancellationToke
AddService(typeof(ILoginManager), CreateService, true);
AddService(typeof(IGitHubToolWindowManager), CreateService, true);
AddService(typeof(IPackageSettings), CreateService, true);
AddService(typeof(IVsTippingService), CreateService, true);
}

#if DEBUG
Expand Down Expand Up @@ -311,6 +317,10 @@ async Task<object> CreateService(IAsyncServiceContainer container, CancellationT
var sp = new ServiceProvider(Services.Dte as Microsoft.VisualStudio.OLE.Interop.IServiceProvider);
return new PackageSettings(sp);
}
else if (serviceType == typeof(IVsTippingService))
{
return new VsTippingService(this);
}
// go the mef route
else
{
Expand Down