This repository was archived by the owner on Jun 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Show current PR on status bar and allow navigation to PR details MVP #1102
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
069e682
Add command to show the current PR
jcansdale c9d38df
Add PullRequestStatusView to SccStatusBar
jcansdale e6f55fd
Add a simple ViewModel for PullRequestStatusView
jcansdale 8b6cfa2
Wire up property change events
jcansdale 91dcb3d
Make status invisible when not on PR branch
jcansdale a93a467
Open details view when PR status is clicked on
jcansdale 6d8c441
Add hack to ensure that PR status appears
jcansdale 5f63606
Restore missing using System.Globalization
jcansdale 6f9efbd
Find status bar part on main window
jcansdale c5f7cf5
Show PR status after solution has loaded
jcansdale 6362790
Fix duplicate using
jcansdale 11b675a
Move PullRequestStatus initialization to own package
jcansdale c6ee258
Only create PR status view when session changes
jcansdale 6bb88ba
Merge branch 'master' into ui/pr-context
jcansdale a3585d4
Merge branch 'master' into ui/pr-context
jcansdale 4f0da47
Use Serilog and fix CA error
jcansdale 4b5296c
Merge branch 'master' into ui/pr-context
jcansdale c185629
Merge branch 'master' into ui/pr-context
jcansdale File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); | ||
| } | ||
| } | ||
| } |
7 changes: 7 additions & 0 deletions
7
src/GitHub.InlineReviews/Services/IPullRequestStatusManager.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
149
src/GitHub.InlineReviews/Services/PullRequestStatusManager.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
47
src/GitHub.InlineReviews/ViewModels/PullRequestStatusViewModel.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> | ||
| </Grid> | ||
| </UserControl> | ||
13 changes: 13 additions & 0 deletions
13
src/GitHub.InlineReviews/Views/PullRequestStatusView.xaml.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); | ||
| } | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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. ;-)