|
1 | 1 | using System; |
2 | 2 | using System.ComponentModel.Composition; |
| 3 | +using System.ComponentModel.Design; |
3 | 4 | using System.Linq; |
4 | 5 | using System.Reactive; |
5 | 6 | using System.Reactive.Linq; |
|
14 | 15 | using GitHub.Models; |
15 | 16 | using GitHub.Primitives; |
16 | 17 | using GitHub.Services; |
| 18 | +using GitHub.Services.Vssdk.Commands; |
17 | 19 | using GitHub.VisualStudio; |
18 | 20 | using ReactiveUI; |
19 | 21 | using OleMenuCommand = Microsoft.VisualStudio.Shell.OleMenuCommand; |
@@ -43,6 +45,8 @@ public sealed class GitHubPaneViewModel : ViewModelBase, IGitHubPaneViewModel, I |
43 | 45 | readonly ObservableAsPropertyHelper<ContentOverride> contentOverride; |
44 | 46 | readonly ObservableAsPropertyHelper<bool> isSearchEnabled; |
45 | 47 | readonly ObservableAsPropertyHelper<string> title; |
| 48 | + readonly ReactiveCommand<object> navigateBack; |
| 49 | + readonly ReactiveCommand<object> navigateForward; |
46 | 50 | readonly ReactiveCommand<Unit> refresh; |
47 | 51 | readonly ReactiveCommand<Unit> showPullRequests; |
48 | 52 | readonly ReactiveCommand<object> openInBrowser; |
@@ -125,6 +129,14 @@ public GitHubPaneViewModel( |
125 | 129 | .Select(x => x is ISearchablePageViewModel) |
126 | 130 | .ToProperty(this, x => x.IsSearchEnabled); |
127 | 131 |
|
| 132 | + navigateBack = ReactiveCommand.CreateCombined( |
| 133 | + currentPage.Select(x => x != null), |
| 134 | + navigator.NavigateBack); |
| 135 | + |
| 136 | + navigateForward = ReactiveCommand.CreateCombined( |
| 137 | + currentPage.Select(x => x != null), |
| 138 | + navigator.NavigateForward); |
| 139 | + |
128 | 140 | refresh = ReactiveCommand.CreateAsyncTask( |
129 | 141 | currentPage.SelectMany(x => x?.WhenAnyValue( |
130 | 142 | y => y.IsLoading, |
@@ -213,11 +225,12 @@ public async Task InitializeAsync(IServiceProvider paneServiceProvider) |
213 | 225 |
|
214 | 226 | connectionManager.Connections.CollectionChanged += (_, __) => UpdateContent(LocalRepository).Forget(); |
215 | 227 |
|
216 | | - BindNavigatorCommand(paneServiceProvider, PkgCmdIDList.pullRequestCommand, showPullRequests); |
217 | | - BindNavigatorCommand(paneServiceProvider, PkgCmdIDList.backCommand, navigator.NavigateBack); |
218 | | - BindNavigatorCommand(paneServiceProvider, PkgCmdIDList.forwardCommand, navigator.NavigateForward); |
219 | | - BindNavigatorCommand(paneServiceProvider, PkgCmdIDList.refreshCommand, refresh); |
220 | | - BindNavigatorCommand(paneServiceProvider, PkgCmdIDList.githubCommand, openInBrowser); |
| 228 | + var menuService = (IMenuCommandService)paneServiceProvider.GetService(typeof(IMenuCommandService)); |
| 229 | + BindNavigatorCommand(menuService, PkgCmdIDList.pullRequestCommand, showPullRequests); |
| 230 | + BindNavigatorCommand(menuService, PkgCmdIDList.backCommand, navigator.NavigateBack); |
| 231 | + BindNavigatorCommand(menuService, PkgCmdIDList.forwardCommand, navigator.NavigateForward); |
| 232 | + BindNavigatorCommand(menuService, PkgCmdIDList.refreshCommand, refresh); |
| 233 | + BindNavigatorCommand(menuService, PkgCmdIDList.githubCommand, openInBrowser); |
221 | 234 |
|
222 | 235 | paneServiceProvider.AddCommandHandler(Guids.guidGitHubToolbarCmdSet, PkgCmdIDList.helpCommand, |
223 | 236 | (_, __) => |
@@ -304,27 +317,12 @@ public Task ShowPullRequest(string owner, string repo, int number) |
304 | 317 | x => x.RemoteRepositoryOwner == owner && x.LocalRepository.Name == repo && x.Number == number); |
305 | 318 | } |
306 | 319 |
|
307 | | - OleMenuCommand BindNavigatorCommand<T>(IServiceProvider paneServiceProvider, int commandId, ReactiveCommand<T> command) |
| 320 | + OleMenuCommand BindNavigatorCommand<T>(IMenuCommandService menu, int commandId, ReactiveCommand<T> command) |
308 | 321 | { |
309 | | - Guard.ArgumentNotNull(paneServiceProvider, nameof(paneServiceProvider)); |
| 322 | + Guard.ArgumentNotNull(menu, nameof(menu)); |
310 | 323 | Guard.ArgumentNotNull(command, nameof(command)); |
311 | 324 |
|
312 | | - Func<bool> canExecute = () => Content == navigator && command.CanExecute(null); |
313 | | - |
314 | | - var result = paneServiceProvider.AddCommandHandler( |
315 | | - Guids.guidGitHubToolbarCmdSet, |
316 | | - commandId, |
317 | | - canExecute, |
318 | | - () => command.Execute(null), |
319 | | - true); |
320 | | - |
321 | | - Observable.CombineLatest( |
322 | | - this.WhenAnyValue(x => x.Content), |
323 | | - command.CanExecuteObservable, |
324 | | - (c, e) => c == navigator && e) |
325 | | - .Subscribe(x => result.Enabled = x); |
326 | | - |
327 | | - return result; |
| 325 | + return menu.BindCommand(new CommandID(Guids.guidGitHubToolbarCmdSet, commandId), command); |
328 | 326 | } |
329 | 327 |
|
330 | 328 | async Task NavigateTo<TViewModel>(Func<TViewModel, Task> initialize, Func<TViewModel, bool> match = null) |
|
0 commit comments