Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.
Merged
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
1 change: 1 addition & 0 deletions src/GitHub.Exports/Settings/Guids.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public static class Guids
public const string StartPagePackageId = "3b764d23-faf7-486f-94c7-b3accc44a70e";
public const string CodeContainerProviderId = "6CE146CB-EF57-4F2C-A93F-5BA685317660";
public const string InlineReviewsPackageId = "248325BE-4A2D-4111-B122-E7D59BF73A35";
public const string PullRequestStatusPackageId = "5121BEC6-1088-4553-8453-0DDC7C8E2238";
public const string TeamExplorerWelcomeMessage = "C529627F-8AA6-4FDB-82EB-4BFB7DB753C3";
public const string LoginManagerId = "7BA2071A-790A-4F95-BE4A-0EEAA5928AAF";

Expand Down
11 changes: 11 additions & 0 deletions src/GitHub.InlineReviews/GitHub.InlineReviews.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,13 @@
<Compile Include="Glyph\GlyphMargin.cs" />
<Compile Include="Glyph\GlyphMarginVisualManager.cs" />
<Compile Include="Glyph\IGlyphFactory.cs" />
<Compile Include="PullRequestStatusPackage.cs" />
<Compile Include="InlineReviewsPackage.cs" />
<Compile Include="Models\InlineCommentThreadModel.cs" />
<Compile Include="Models\PullRequestSessionLiveFile.cs" />
<Compile Include="Models\PullRequestSessionFile.cs" />
<Compile Include="Services\IPullRequestStatusManager.cs" />
<Compile Include="Services\PullRequestStatusManager.cs" />
<Compile Include="Tags\MouseEnterAndLeaveEventRouter.cs" />
<Compile Include="Peek\InlineCommentPeekableItem.cs" />
<Compile Include="Peek\InlineCommentPeekableItemSource.cs" />
Expand Down Expand Up @@ -124,6 +127,7 @@
<Compile Include="ViewModels\IPullRequestCommentsViewModel.cs" />
<Compile Include="ViewModels\IssueCommentThreadViewModel.cs" />
<Compile Include="ViewModels\PullRequestCommentsViewModel.cs" />
<Compile Include="ViewModels\PullRequestStatusViewModel.cs" />
<Compile Include="Views\DiffCommentThreadView.xaml.cs">
<DependentUpon>DiffCommentThreadView.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -161,6 +165,9 @@
<Compile Include="Views\CommentView.xaml.cs">
<DependentUpon>CommentView.xaml</DependentUpon>
</Compile>
<Compile Include="Views\PullRequestStatusView.xaml.cs">
<DependentUpon>PullRequestStatusView.xaml</DependentUpon>
</Compile>
<Compile Include="VisualStudioExtensions.cs" />
</ItemGroup>
<ItemGroup>
Expand Down Expand Up @@ -447,6 +454,10 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Views\PullRequestStatusView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<ItemGroup>
<Analyzer Include="..\..\packages\SerilogAnalyzer.0.12.0.0\analyzers\dotnet\cs\SerilogAnalyzer.dll" />
Expand Down
2 changes: 1 addition & 1 deletion src/GitHub.InlineReviews/InlineReviewsPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace GitHub.InlineReviews
[Guid(Guids.InlineReviewsPackageId)]
[ProvideAutoLoad(UIContextGuids80.SolutionExists)]
[ProvideMenuResource("Menus.ctmenu", 1)]
[ProvideToolWindow(typeof(PullRequestCommentsPane), DocumentLikeTool=true)]
[ProvideToolWindow(typeof(PullRequestCommentsPane), DocumentLikeTool = true)]
public class InlineReviewsPackage : Package
{
protected override void Initialize()
Expand Down
24 changes: 24 additions & 0 deletions src/GitHub.InlineReviews/PullRequestStatusPackage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Runtime.InteropServices;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
using Microsoft.VisualStudio.ComponentModelHost;
using GitHub.VisualStudio;
using GitHub.InlineReviews.Services;

namespace GitHub.InlineReviews
{
[PackageRegistration(UseManagedResourcesOnly = true)]
[Guid(Guids.PullRequestStatusPackageId)]
[ProvideAutoLoad(UIContextGuids80.SolutionExists)]
public class PullRequestStatusPackage : Package
{
protected override void Initialize()
{
var componentModel = (IComponentModel)GetService(typeof(SComponentModel));
var exportProvider = componentModel.DefaultExportProvider;
var pullRequestStatusManager = exportProvider.GetExportedValue<IPullRequestStatusManager>();
pullRequestStatusManager.Initialize();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace GitHub.InlineReviews.Services
{
public interface IPullRequestStatusManager
{
void Initialize();
}
}
149 changes: 149 additions & 0 deletions src/GitHub.InlineReviews/Services/PullRequestStatusManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
using System;
using System.Windows;
using System.Windows.Input;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.ComponentModel;
using System.ComponentModel.Composition;
using GitHub.InlineReviews.Views;
using GitHub.InlineReviews.ViewModels;
using GitHub.Services;
using GitHub.VisualStudio;
using Microsoft.VisualStudio.Shell;
using GitHub.Models;
using GitHub.Logging;
using Serilog;

namespace GitHub.InlineReviews.Services
{
[Export(typeof(IPullRequestStatusManager))]
public class PullRequestStatusManager : IPullRequestStatusManager
{
static readonly ILogger log = LogManager.ForContext<PullRequestStatusManager>();
const string StatusBarPartName = "PART_SccStatusBarHost";

readonly SVsServiceProvider serviceProvider;
readonly Window mainWindow;
readonly IPullRequestSessionManager pullRequestSessionManager;

[ImportingConstructor]
public PullRequestStatusManager(SVsServiceProvider serviceProvider, IPullRequestSessionManager pullRequestSessionManager)
: this()
{
this.serviceProvider = serviceProvider;
this.pullRequestSessionManager = pullRequestSessionManager;
}

public PullRequestStatusManager()
{
mainWindow = Application.Current.MainWindow;
}

public void Initialize()
{
RefreshCurrentSession();
pullRequestSessionManager.PropertyChanged += PullRequestSessionManager_PropertyChanged;
}

void PullRequestSessionManager_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(PullRequestSessionManager.CurrentSession))
{
RefreshCurrentSession();
}
}

void RefreshCurrentSession()
{
var pullRequest = pullRequestSessionManager.CurrentSession?.PullRequest;
var viewModel = pullRequest != null ? CreatePullRequestStatusViewModel(serviceProvider, pullRequest) : null;
ShowStatus(viewModel);
}

static PullRequestStatusViewModel CreatePullRequestStatusViewModel(IServiceProvider serviceProvider, IPullRequestModel pullRequest)
{
var command = new RaiseVsCommand(serviceProvider, Guids.guidGitHubCmdSetString, PkgCmdIDList.showCurrentPullRequestCommand);
var pullRequestStatusViewModel = new PullRequestStatusViewModel(command);
pullRequestStatusViewModel.Number = pullRequest.Number;
pullRequestStatusViewModel.Title = pullRequest.Title;
return pullRequestStatusViewModel;
}

void ShowStatus(PullRequestStatusViewModel pullRequestStatusViewModel = null)
{
var statusBar = FindSccStatusBar();
if (statusBar != null)
{
var githubStatusBar = Find<PullRequestStatusView>(statusBar);
if (githubStatusBar != null)
{
// Replace to ensure status shows up.
statusBar.Items.Remove(githubStatusBar);
}

if (pullRequestStatusViewModel != null)
{
githubStatusBar = new PullRequestStatusView { DataContext = pullRequestStatusViewModel };
statusBar.Items.Insert(0, githubStatusBar);
}
}
}

static T Find<T>(StatusBar statusBar)
{
foreach (var item in statusBar.Items)
{
if (item is T)
{
return (T)item;
}
}

return default(T);
}

StatusBar FindSccStatusBar()
{
var contentControl = mainWindow?.Template?.FindName(StatusBarPartName, mainWindow) as ContentControl;
return contentControl?.Content as StatusBar;
}

class RaiseVsCommand : ICommand
{
readonly IServiceProvider serviceProvider;
readonly string guid;
readonly int id;

internal RaiseVsCommand(IServiceProvider serviceProvider, string guid, int id)
{
this.serviceProvider = serviceProvider;
this.guid = guid;
this.id = id;
}

public bool CanExecute(object parameter) => true;

public void Execute(object parameter)
{
try
{
var dte = serviceProvider.GetService(typeof(EnvDTE.DTE)) as EnvDTE.DTE;
object customIn = null;
object customOut = null;
dte.Commands.Raise(guid, id, ref customIn, ref customOut);
}
catch (Exception e)
{
log.Error(e, "Couldn't raise {Guid}:{ID}", guid, id);
System.Diagnostics.Trace.WriteLine(e);
}
}

public event EventHandler CanExecuteChanged
{
add { }
remove { }
}
}
}
}
47 changes: 47 additions & 0 deletions src/GitHub.InlineReviews/ViewModels/PullRequestStatusViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System;
using System.Windows.Input;
using System.ComponentModel;

namespace GitHub.InlineReviews.ViewModels
{
public class PullRequestStatusViewModel : INotifyPropertyChanged
{
int? number;
string title;

public PullRequestStatusViewModel(ICommand showCurrentPullRequestCommand)
{
ShowCurrentPullRequestCommand = showCurrentPullRequestCommand;
}

public int? Number
{
get { return number; }
set
{
if (number != value)
{
number = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Number)));
}
}
}

public string Title
{
get { return title; }
set
{
if (title != value)
{
title = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Title)));
}
}
}

public ICommand ShowCurrentPullRequestCommand { get; }

public event PropertyChangedEventHandler PropertyChanged;
}
}
18 changes: 18 additions & 0 deletions src/GitHub.InlineReviews/Views/PullRequestStatusView.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<UserControl x:Class="GitHub.InlineReviews.Views.PullRequestStatusView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:GitHub.InlineReviews.Views"
mc:Ignorable="d"
d:DesignHeight="20" d:DesignWidth="60">

<Grid Visibility="{Binding Number, TargetNullValue=Collapsed}">
<Button Command="{Binding ShowCurrentPullRequestCommand}">
<TextBlock>PR #<Run Text="{Binding Number}" /></TextBlock>
</Button>
<Grid.ToolTip>
<TextBlock Text="{Binding Title}" />
</Grid.ToolTip>
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@donokuda here's the UI, if you can call it that. ;-)

</Grid>
</UserControl>
13 changes: 13 additions & 0 deletions src/GitHub.InlineReviews/Views/PullRequestStatusView.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Windows.Controls;

namespace GitHub.InlineReviews.Views
{
public partial class PullRequestStatusView : UserControl
{
public PullRequestStatusView()
{
InitializeComponent();
}
}
}