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
[Feature] Show current PR on status bar #1396
Merged
Merged
Changes from all commits
Commits
Show all changes
87 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 1209998
Merge pull request #1102 from github/ui/pr-context
jcansdale e2d753c
Add usage metrics for ShowCurrentPullRequest
jcansdale f4b3115
Start a button
donokuda 8e26aad
Use visual studio color keys
donokuda 7e1bcc0
Set up some triggers
donokuda 89ce001
Transparent background by default
donokuda 09c58f3
/shrug
donokuda 68895cd
Set the hover state correctly
donokuda 562bac5
Merge branch 'master' into feature/show-current-pr
jcansdale 4ef8387
Merge branch 'master' into feature/show-current-pr
jcansdale 5a2227e
Merge branch 'fixes/1408-change-branch-event-squashed' into feature/s…
jcansdale 942953d
Merge pull request #1402 from github/ui/show-current-pr-polish
jcansdale eb941af
Merge branch 'feature/show-current-pr' of https://github.com/github/V…
jcansdale fa120f0
Merge branch 'fixes/1408-change-branch-event-squashed' into feature/s…
jcansdale a6fa2a0
Merge branch 'fixes/1408-change-branch-event-squashed' into feature/s…
jcansdale efd89ce
Merge branch 'fixes/1408-change-branch-event-squashed' into feature/s…
jcansdale bbd8bd1
Merge branch 'fixes/1408-change-branch-event-squashed' into feature/s…
jcansdale 0ea3eff
Change to using IGitHubServiceProvider
jcansdale f76d113
Merge branch 'fixes/1408-change-branch-event-squashed' into feature/s…
jcansdale 5ea1f0f
Merge branch 'fixes/1408-change-branch-event-squashed' into feature/s…
jcansdale ee6d5a8
Merge branch 'fixes/1408-change-branch-event-squashed' into feature/s…
jcansdale 6cb2bcc
Merge branch 'master' into feature/show-current-pr
jcansdale 975816e
Merge branch 'master' into feature/show-current-pr
jcansdale 5206bd1
Merge branch 'fixes/1440-clear-PR-session' into feature/show-current-pr
jcansdale ad0f8cf
Merge branch 'master' into feature/show-current-pr
jcansdale 41e9187
Merge branch 'master' into feature/show-current-pr
jcansdale 3b54143
Merge branch 'master' into feature/show-current-pr
jcansdale 4503596
Make PR status visible when GitSccProvider is loaded
jcansdale eb3ec74
Merge branch 'master' into feature/show-current-pr
grokys 04e5422
Rename PullRequestStatusManager to PullRequestStatusBarManager
jcansdale 4ce0d65
Show PR number as well as title on tooltip
jcansdale e9f0c17
Convert PullRequestStatusPackage to an AsyncPackage
jcansdale c6750b9
Rename PullRequestStatusPackage to ..StatusBarPackage
jcansdale dc81286
Lazily initialize when we're on a GitHub repo
jcansdale 20879e7
Pass MainWindow to PullRequestStatusBarManager.Initialize
jcansdale 0039538
Add some xmldoc comments
jcansdale f356907
Add fix for hanging InitializeAsync
jcansdale 323f330
Ensure consistent task ordering using ContinueWith
jcansdale 5200e72
Rename InitializeTask to PendingTasks
jcansdale 97eaced
Remove redundant initialized flag
jcansdale 1ea222a
Lazy load VSGitExt on Main thread
jcansdale 68d098a
Do initialization asynchronously on Main thread
jcansdale dcd806f
Add comment about using from background thread
jcansdale 2a3cef5
Factor out GetServiceAsync
jcansdale 66fbbaa
Load VS services asynchronously
jcansdale 16aabcd
Make grammarful English
jcansdale 1205790
Remove dependency on IComponentModel
jcansdale 2df68b1
Merge branch 'master' into feature/show-current-pr
jcansdale ebbc6a6
Let PR # appear on status bar before solution has loaded
jcansdale cf2bc71
Merge branch 'fixes/1493-using-ContinueWith' into feature/show-curren…
jcansdale f23fd24
Expose IVSGitExt as async VS service
jcansdale 921f8c5
Add generic GetServiceAsync to IGitHubServiceProvider
jcansdale ace5498
Use DTE.Version to choose IVSGitExt implementaiton
jcansdale 738b046
Add some comments
jcansdale f3865b1
Use a delegate for GetServiceAsync
jcansdale cc6a112
Move VSGitExtPart into VSGitExtDispatcher
jcansdale e517687
Move CreateVSGitExt into VSGitExtFactory
jcansdale b98cc52
Merge VSGitExtDispatcher into VSGitExtFactory
jcansdale 719e624
Move all construction logic into VSGitExtFactory.Create
jcansdale af9f364
Add comments to factory method
jcansdale fc06da7
Use ApplicationInfo.GetHostVersionInfo not DTE.Version
jcansdale ee9ab4a
Simplify the VSGitExt service
jcansdale 0eadf70
Merge pull request #1513 from github/refactor/simplify-VSGitExt
jcansdale 32d2805
Merge pull request #1510 from github/refactor/convert-VSGitExt-to-ser…
jcansdale 338860d
Merge branch 'master' into feature/show-current-pr
jcansdale c13c597
Merge branch 'master' into feature/show-current-pr
jcansdale d72ff9b
Use IAsyncServiceProvider rather than delegate
jcansdale 78f9d71
Give alias to ..Shell.Framework rather than ..Shell.Immutable.14
jcansdale 05e74b0
Merge branch 'master' into feature/show-current-pr
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
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,29 @@ | ||
| using System; | ||
| using System.Threading; | ||
| using System.Runtime.InteropServices; | ||
| using GitHub.Services; | ||
| using GitHub.VisualStudio; | ||
| using GitHub.InlineReviews.Services; | ||
| using Microsoft.VisualStudio.Shell; | ||
| using Task = System.Threading.Tasks.Task; | ||
|
|
||
| namespace GitHub.InlineReviews | ||
| { | ||
| [Guid(Guids.PullRequestStatusPackageId)] | ||
| [PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)] | ||
| [ProvideAutoLoad(Guids.GitSccProviderId, PackageAutoLoadFlags.BackgroundLoad)] | ||
| public class PullRequestStatusBarPackage : AsyncPackage | ||
| { | ||
| /// <summary> | ||
| /// Initialize the PR status UI on Visual Studio's status bar. | ||
| /// </summary> | ||
| protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress<ServiceProgressData> progress) | ||
| { | ||
| var usageTracker = (IUsageTracker)await GetServiceAsync(typeof(IUsageTracker)); | ||
| var serviceProvider = (IGitHubServiceProvider)await GetServiceAsync(typeof(IGitHubServiceProvider)); | ||
| var gitExt = (IVSGitExt)await GetServiceAsync(typeof(IVSGitExt)); | ||
|
|
||
| new PullRequestStatusBarManager(gitExt, usageTracker, serviceProvider); | ||
| } | ||
| } | ||
| } |
169 changes: 169 additions & 0 deletions
169
src/GitHub.InlineReviews/Services/PullRequestStatusBarManager.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,169 @@ | ||
| 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 GitHub.Models; | ||
| using GitHub.Logging; | ||
| using GitHub.Extensions; | ||
| using Serilog; | ||
|
|
||
| namespace GitHub.InlineReviews.Services | ||
| { | ||
| public class PullRequestStatusBarManager | ||
| { | ||
| static readonly ILogger log = LogManager.ForContext<PullRequestStatusBarManager>(); | ||
| const string StatusBarPartName = "PART_SccStatusBarHost"; | ||
|
|
||
| readonly IVSGitExt gitExt; | ||
| readonly IUsageTracker usageTracker; | ||
| readonly IGitHubServiceProvider serviceProvider; | ||
|
|
||
| IPullRequestSessionManager pullRequestSessionManager; | ||
|
|
||
| [ImportingConstructor] | ||
| public PullRequestStatusBarManager(IVSGitExt gitExt, IUsageTracker usageTracker, IGitHubServiceProvider serviceProvider) | ||
| { | ||
| this.gitExt = gitExt; | ||
| this.usageTracker = usageTracker; | ||
| this.serviceProvider = serviceProvider; | ||
|
|
||
| OnActiveRepositoriesChanged(); | ||
| gitExt.ActiveRepositoriesChanged += OnActiveRepositoriesChanged; | ||
| } | ||
|
|
||
| void OnActiveRepositoriesChanged() | ||
| { | ||
| if (gitExt.ActiveRepositories.Count > 0) | ||
| { | ||
| gitExt.ActiveRepositoriesChanged -= OnActiveRepositoriesChanged; | ||
| Application.Current.Dispatcher.Invoke(() => StartShowingStatus()); | ||
| } | ||
| } | ||
|
|
||
| void StartShowingStatus() | ||
| { | ||
| try | ||
| { | ||
| // Create just in time on Main thread. | ||
| pullRequestSessionManager = serviceProvider.GetService<IPullRequestSessionManager>(); | ||
|
|
||
| RefreshCurrentSession(); | ||
| pullRequestSessionManager.PropertyChanged += PullRequestSessionManager_PropertyChanged; | ||
| } | ||
| catch (Exception e) | ||
| { | ||
| log.Error(e, "Error initializing"); | ||
| } | ||
| } | ||
|
|
||
| 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(pullRequest) : null; | ||
| ShowStatus(viewModel); | ||
| } | ||
|
|
||
| PullRequestStatusViewModel CreatePullRequestStatusViewModel(IPullRequestModel pullRequest) | ||
| { | ||
| var dte = serviceProvider.TryGetService<EnvDTE.DTE>(); | ||
| var command = new RaisePullRequestCommand(dte, usageTracker); | ||
| var pullRequestStatusViewModel = new PullRequestStatusViewModel(command); | ||
| pullRequestStatusViewModel.Number = pullRequest.Number; | ||
| pullRequestStatusViewModel.Title = pullRequest.Title; | ||
| return pullRequestStatusViewModel; | ||
| } | ||
|
|
||
| void ShowStatus(PullRequestStatusViewModel pullRequestStatusViewModel = null) | ||
| { | ||
| var statusBar = FindSccStatusBar(Application.Current.MainWindow); | ||
| 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(Window mainWindow) | ||
| { | ||
| var contentControl = mainWindow?.Template?.FindName(StatusBarPartName, mainWindow) as ContentControl; | ||
| return contentControl?.Content as StatusBar; | ||
| } | ||
|
|
||
| class RaisePullRequestCommand : ICommand | ||
| { | ||
| readonly string guid = Guids.guidGitHubCmdSetString; | ||
| readonly int id = PkgCmdIDList.showCurrentPullRequestCommand; | ||
|
|
||
| readonly EnvDTE.DTE dte; | ||
| readonly IUsageTracker usageTracker; | ||
|
|
||
| internal RaisePullRequestCommand(EnvDTE.DTE dte, IUsageTracker usageTracker) | ||
| { | ||
| this.dte = dte; | ||
| this.usageTracker = usageTracker; | ||
| } | ||
|
|
||
| public bool CanExecute(object parameter) => true; | ||
|
|
||
| public void Execute(object parameter) | ||
| { | ||
| try | ||
| { | ||
| 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); | ||
| } | ||
|
|
||
| usageTracker.IncrementCounter(x => x.NumberOfShowCurrentPullRequest).Forget(); | ||
| } | ||
|
|
||
| public event EventHandler CanExecuteChanged | ||
| { | ||
| add { } | ||
| remove { } | ||
| } | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
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.
This might be called twice!
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.
This will be fixed in #1512.