11using System ;
22using System . Windows ;
3+ using System . Windows . Input ;
34using System . Windows . Controls ;
45using System . Windows . Controls . Primitives ;
56using System . ComponentModel . Composition ;
67using System . Reactive . Linq ;
8+ using System . Linq . Expressions ;
79using GitHub . Commands ;
810using GitHub . InlineReviews . Views ;
911using GitHub . InlineReviews . ViewModels ;
1012using GitHub . Services ;
1113using GitHub . Models ;
1214using GitHub . Logging ;
15+ using GitHub . Extensions ;
1316using Serilog ;
1417using ReactiveUI ;
1518
@@ -24,8 +27,9 @@ public class PullRequestStatusBarManager
2427 static readonly ILogger log = LogManager . ForContext < PullRequestStatusBarManager > ( ) ;
2528 const string StatusBarPartName = "PART_SccStatusBarHost" ;
2629
27- readonly IOpenPullRequestsCommand openPullRequestsCommand ;
28- readonly IShowCurrentPullRequestCommand showCurrentPullRequestCommand ;
30+ readonly IUsageTracker usageTracker ;
31+ readonly ICommand openPullRequestsCommand ;
32+ readonly ICommand showCurrentPullRequestCommand ;
2933
3034 // At the moment these must be constructed on the main thread.
3135 // TeamExplorerContext needs to retrieve DTE using GetService.
@@ -36,13 +40,19 @@ public class PullRequestStatusBarManager
3640
3741 [ ImportingConstructor ]
3842 public PullRequestStatusBarManager (
43+ IUsageTracker usageTracker ,
3944 IOpenPullRequestsCommand openPullRequestsCommand ,
4045 IShowCurrentPullRequestCommand showCurrentPullRequestCommand ,
4146 Lazy < IPullRequestSessionManager > pullRequestSessionManager ,
4247 Lazy < ITeamExplorerContext > teamExplorerContext )
4348 {
44- this . openPullRequestsCommand = openPullRequestsCommand ;
45- this . showCurrentPullRequestCommand = showCurrentPullRequestCommand ;
49+ this . usageTracker = usageTracker ;
50+
51+ this . openPullRequestsCommand = new UsageTrackingCommand ( openPullRequestsCommand ,
52+ usageTracker , x => x . NumberOfOpenPullRequests ) ;
53+ this . showCurrentPullRequestCommand = new UsageTrackingCommand ( showCurrentPullRequestCommand ,
54+ usageTracker , x => x . NumberOfShowCurrentPullRequest ) ;
55+
4656 this . pullRequestSessionManager = pullRequestSessionManager ;
4757 this . teamExplorerContext = teamExplorerContext ;
4858 }
@@ -136,5 +146,37 @@ StatusBar FindSccStatusBar(Window mainWindow)
136146 var contentControl = mainWindow ? . Template ? . FindName ( StatusBarPartName , mainWindow ) as ContentControl ;
137147 return contentControl ? . Content as StatusBar ;
138148 }
149+
150+ class UsageTrackingCommand : ICommand
151+ {
152+ readonly ICommand command ;
153+ readonly IUsageTracker usageTracker ;
154+ readonly Expression < Func < UsageModel . MeasuresModel , int > > counter ;
155+
156+ internal UsageTrackingCommand ( ICommand command , IUsageTracker usageTracker ,
157+ Expression < Func < UsageModel . MeasuresModel , int > > counter )
158+ {
159+ this . command = command ;
160+ this . usageTracker = usageTracker ;
161+ this . counter = counter ;
162+ }
163+
164+ public event EventHandler CanExecuteChanged
165+ {
166+ add { command . CanExecuteChanged += value ; }
167+ remove { command . CanExecuteChanged -= value ; }
168+ }
169+
170+ public bool CanExecute ( object parameter )
171+ {
172+ return command . CanExecute ( parameter ) ;
173+ }
174+
175+ public void Execute ( object parameter )
176+ {
177+ command . Execute ( parameter ) ;
178+ usageTracker . IncrementCounter ( counter ) . Forget ( ) ;
179+ }
180+ }
139181 }
140182}
0 commit comments