11using System ;
22using System . ComponentModel . Composition ;
3+ using System . ComponentModel . Design ;
34using System . Linq ;
45using System . Reactive ;
56using System . Reactive . Linq ;
1516using GitHub . Models ;
1617using GitHub . Primitives ;
1718using GitHub . Services ;
19+ using GitHub . Services . Vssdk . Commands ;
1820using GitHub . VisualStudio ;
1921using ReactiveUI ;
2022using Serilog ;
@@ -36,8 +38,6 @@ public sealed class GitHubPaneViewModel : ViewModelBase, IGitHubPaneViewModel, I
3638 readonly ISimpleApiClientFactory apiClientFactory ;
3739 readonly IConnectionManager connectionManager ;
3840 readonly ITeamExplorerContext teamExplorerContext ;
39- readonly IVisualStudioBrowser browser ;
40- readonly IUsageTracker usageTracker ;
4141 readonly INavigationViewModel navigator ;
4242 readonly ILoggedOutViewModel loggedOut ;
4343 readonly INotAGitHubRepositoryViewModel notAGitHubRepository ;
@@ -49,6 +49,7 @@ public sealed class GitHubPaneViewModel : ViewModelBase, IGitHubPaneViewModel, I
4949 readonly ReactiveCommand < Unit > refresh ;
5050 readonly ReactiveCommand < Unit > showPullRequests ;
5151 readonly ReactiveCommand < object > openInBrowser ;
52+ readonly ReactiveCommand < object > help ;
5253 Task initializeTask ;
5354 IViewModel content ;
5455 ILocalRepositoryModel localRepository ;
@@ -82,8 +83,6 @@ public GitHubPaneViewModel(
8283 this . apiClientFactory = apiClientFactory ;
8384 this . connectionManager = connectionManager ;
8485 this . teamExplorerContext = teamExplorerContext ;
85- this . browser = browser ;
86- this . usageTracker = usageTracker ;
8786 this . navigator = navigator ;
8887 this . loggedOut = loggedOut ;
8988 this . notAGitHubRepository = notAGitHubRepository ;
@@ -147,6 +146,13 @@ public GitHubPaneViewModel(
147146 if ( url != null ) browser . OpenUrl ( url ) ;
148147 } ) ;
149148
149+ help = ReactiveCommand . Create ( ) ;
150+ help . Subscribe ( _ =>
151+ {
152+ browser . OpenUrl ( new Uri ( GitHubUrls . Documentation ) ) ;
153+ usageTracker . IncrementCounter ( x => x . NumberOfGitHubPaneHelpClicks ) . Forget ( ) ;
154+ } ) ;
155+
150156 navigator . WhenAnyObservable ( x => x . Content . NavigationRequested )
151157 . Subscribe ( x => NavigateTo ( x ) . Forget ( ) ) ;
152158
@@ -280,47 +286,27 @@ async Task CreateInitializeTask(IServiceProvider paneServiceProvider)
280286 {
281287 await UpdateContent ( teamExplorerContext . ActiveRepository ) ;
282288 teamExplorerContext . WhenAnyValue ( x => x . ActiveRepository )
283- . Skip ( 1 )
284- . ObserveOn ( RxApp . MainThreadScheduler )
285- . Subscribe ( x => UpdateContent ( x ) . Forget ( ) ) ;
289+ . Skip ( 1 )
290+ . ObserveOn ( RxApp . MainThreadScheduler )
291+ . Subscribe ( x => UpdateContent ( x ) . Forget ( ) ) ;
286292
287293 connectionManager . Connections . CollectionChanged += ( _ , __ ) => UpdateContent ( LocalRepository ) . Forget ( ) ;
288294
289- BindNavigatorCommand ( paneServiceProvider , PkgCmdIDList . pullRequestCommand , showPullRequests ) ;
290- BindNavigatorCommand ( paneServiceProvider , PkgCmdIDList . backCommand , navigator . NavigateBack ) ;
291- BindNavigatorCommand ( paneServiceProvider , PkgCmdIDList . forwardCommand , navigator . NavigateForward ) ;
292- BindNavigatorCommand ( paneServiceProvider , PkgCmdIDList . refreshCommand , refresh ) ;
293- BindNavigatorCommand ( paneServiceProvider , PkgCmdIDList . githubCommand , openInBrowser ) ;
294-
295- paneServiceProvider . AddCommandHandler ( Guids . guidGitHubToolbarCmdSet , PkgCmdIDList . helpCommand ,
296- ( _ , __ ) =>
297- {
298- browser . OpenUrl ( new Uri ( GitHubUrls . Documentation ) ) ;
299- usageTracker . IncrementCounter ( x => x . NumberOfGitHubPaneHelpClicks ) . Forget ( ) ;
300- } ) ;
295+ var menuService = ( IMenuCommandService ) paneServiceProvider . GetService ( typeof ( IMenuCommandService ) ) ;
296+ BindNavigatorCommand ( menuService , PkgCmdIDList . pullRequestCommand , showPullRequests ) ;
297+ BindNavigatorCommand ( menuService , PkgCmdIDList . backCommand , navigator . NavigateBack ) ;
298+ BindNavigatorCommand ( menuService , PkgCmdIDList . forwardCommand , navigator . NavigateForward ) ;
299+ BindNavigatorCommand ( menuService , PkgCmdIDList . refreshCommand , refresh ) ;
300+ BindNavigatorCommand ( menuService , PkgCmdIDList . githubCommand , openInBrowser ) ;
301+ BindNavigatorCommand ( menuService , PkgCmdIDList . helpCommand , help ) ;
301302 }
302303
303- OleMenuCommand BindNavigatorCommand < T > ( IServiceProvider paneServiceProvider , int commandId , ReactiveCommand < T > command )
304+ OleMenuCommand BindNavigatorCommand < T > ( IMenuCommandService menu , int commandId , ReactiveCommand < T > command )
304305 {
305- Guard . ArgumentNotNull ( paneServiceProvider , nameof ( paneServiceProvider ) ) ;
306+ Guard . ArgumentNotNull ( menu , nameof ( menu ) ) ;
306307 Guard . ArgumentNotNull ( command , nameof ( command ) ) ;
307308
308- Func < bool > canExecute = ( ) => Content == navigator && command . CanExecute ( null ) ;
309-
310- var result = paneServiceProvider . AddCommandHandler (
311- Guids . guidGitHubToolbarCmdSet ,
312- commandId ,
313- canExecute ,
314- ( ) => command . Execute ( null ) ,
315- true ) ;
316-
317- Observable . CombineLatest (
318- this . WhenAnyValue ( x => x . Content ) ,
319- command . CanExecuteObservable ,
320- ( c , e ) => c == navigator && e )
321- . Subscribe ( x => result . Enabled = x ) ;
322-
323- return result ;
309+ return menu . BindCommand ( new CommandID ( Guids . guidGitHubToolbarCmdSet , commandId ) , command ) ;
324310 }
325311
326312 async Task NavigateTo < TViewModel > ( Func < TViewModel , Task > initialize , Func < TViewModel , bool > match = null )
0 commit comments