1- using Microsoft . TeamFoundation . Git . Controls . Extensibility ;
2- using System ;
1+ using System ;
2+ using System . Collections . Generic ;
33using System . ComponentModel . Composition ;
44using System . Globalization ;
55using System . Linq ;
6+ using System . Windows . Input ;
67using GitHub . Extensions ;
7- using Microsoft . Win32 ;
8- using Microsoft . VisualStudio . TeamFoundation . Git . Extensibility ;
8+ using GitHub . Models ;
99using GitHub . VisualStudio ;
1010using Microsoft . TeamFoundation . Controls ;
11+ using Microsoft . TeamFoundation . Git . Controls . Extensibility ;
1112using Microsoft . VisualStudio ;
1213using Microsoft . VisualStudio . Shell . Interop ;
13- using System . Collections . Generic ;
14- using GitHub . Models ;
14+ using Microsoft . VisualStudio . TeamFoundation . Git . Extensibility ;
15+ using Microsoft . Win32 ;
1516
1617namespace GitHub . Services
1718{
@@ -25,6 +26,7 @@ public interface IVSServices
2526 string SetDefaultProjectPath ( string path ) ;
2627
2728 void ShowMessage ( string message ) ;
29+ void ShowMessage ( string message , ICommand command ) ;
2830 void ShowWarning ( string message ) ;
2931 void ShowError ( string message ) ;
3032 void ClearNotifications ( ) ;
@@ -139,49 +141,76 @@ static string PokeTheRegistryForLocalClonePath()
139141 }
140142 }
141143
142- const string PathsKey = @"Software\Microsoft\VisualStudio\14.0\NewProjectDialog\MRUSettingsLocalProjectLocationEntries" ;
144+ const string NewProjectDialogKeyPath = @"Software\Microsoft\VisualStudio\14.0\NewProjectDialog" ;
145+ const string MRUKeyPath = "MRUSettingsLocalProjectLocationEntries" ;
143146 public string SetDefaultProjectPath ( string path )
144147 {
145148 string old ;
146- using ( var key = Registry . CurrentUser . OpenSubKey ( PathsKey , true ) )
149+ using ( var newProjectKey = Registry . CurrentUser . OpenSubKey ( NewProjectDialogKeyPath , true ) )
147150 {
148- old = ( string ) key ? . GetValue ( "Value0" , string . Empty , RegistryValueOptions . DoNotExpandEnvironmentNames ) ;
149- key ? . SetValue ( "Value0" , path , RegistryValueKind . String ) ;
151+ using ( var mruKey = newProjectKey ? . OpenSubKey ( MRUKeyPath , true ) )
152+ {
153+ if ( mruKey == null )
154+ return String . Empty ;
155+
156+ // is this already the default path? bail
157+ old = ( string ) mruKey . GetValue ( "Value0" , string . Empty , RegistryValueOptions . DoNotExpandEnvironmentNames ) ;
158+ if ( String . Equals ( path . TrimEnd ( '\\ ' ) , old . TrimEnd ( '\\ ' ) , StringComparison . CurrentCultureIgnoreCase ) )
159+ return old ;
160+
161+ // grab the existing list of recent paths, throwing away the last one
162+ var numEntries = ( int ) mruKey . GetValue ( "MaximumEntries" , 5 ) ;
163+ var entries = new List < string > ( numEntries ) ;
164+ for ( int i = 0 ; i < numEntries - 1 ; i ++ )
165+ {
166+ var val = ( string ) mruKey . GetValue ( "Value" + i , String . Empty , RegistryValueOptions . DoNotExpandEnvironmentNames ) ;
167+ if ( ! String . IsNullOrEmpty ( val ) )
168+ entries . Add ( val ) ;
169+ }
170+
171+ newProjectKey . SetValue ( "LastUsedNewProjectPath" , path ) ;
172+ mruKey . SetValue ( "Value0" , path ) ;
173+ // bump list of recent paths one entry down
174+ for ( int i = 0 ; i < entries . Count ; i ++ )
175+ mruKey . SetValue ( "Value" + ( i + 1 ) , entries [ i ] ) ;
176+ }
150177 }
151178 return old ;
152179 }
153180
154181 public void ShowMessage ( string message )
155182 {
156183 var manager = serviceProvider . TryGetService < ITeamExplorer > ( ) as ITeamExplorerNotificationManager ;
157- if ( manager != null )
158- manager . ShowNotification ( message , NotificationType . Information , NotificationFlags . None , null , default ( Guid ) ) ;
184+ manager ? . ShowNotification ( message , NotificationType . Information , NotificationFlags . None , null , default ( Guid ) ) ;
185+ }
186+
187+ public void ShowMessage ( string message , ICommand command )
188+ {
189+ var manager = serviceProvider . TryGetService < ITeamExplorer > ( ) as ITeamExplorerNotificationManager ;
190+ manager ? . ShowNotification ( message , NotificationType . Information , NotificationFlags . None , command , default ( Guid ) ) ;
159191 }
160192
161193 public void ShowWarning ( string message )
162194 {
163195 var manager = serviceProvider . TryGetService < ITeamExplorer > ( ) as ITeamExplorerNotificationManager ;
164- if ( manager != null )
165- manager . ShowNotification ( message , NotificationType . Warning , NotificationFlags . None , null , default ( Guid ) ) ;
196+ manager ? . ShowNotification ( message , NotificationType . Warning , NotificationFlags . None , null , default ( Guid ) ) ;
166197 }
167198
168199 public void ShowError ( string message )
169200 {
170201 var manager = serviceProvider . TryGetService < ITeamExplorer > ( ) as ITeamExplorerNotificationManager ;
171- if ( manager != null )
172- manager . ShowNotification ( message , NotificationType . Error , NotificationFlags . None , null , default ( Guid ) ) ;
202+ manager ? . ShowNotification ( message , NotificationType . Error , NotificationFlags . None , null , default ( Guid ) ) ;
173203 }
174204
175205 public void ClearNotifications ( )
176206 {
177207 var manager = serviceProvider . TryGetService < ITeamExplorer > ( ) as ITeamExplorerNotificationManager ;
178- if ( manager != null )
179- manager . ClearNotifications ( ) ;
180- }
208+ manager ? . ClearNotifications ( ) ;
209+ }
181210
182211 public void ActivityLogMessage ( string message )
183212 {
184- var log = VisualStudio . Services . GetActivityLog ( serviceProvider ) ;
213+ var log = serviceProvider . GetActivityLog ( ) ;
185214 if ( log != null )
186215 {
187216 if ( ! ErrorHandler . Succeeded ( log . LogEntry ( ( UInt32 ) __ACTIVITYLOG_ENTRYTYPE . ALE_INFORMATION ,
@@ -192,7 +221,7 @@ public void ActivityLogMessage(string message)
192221
193222 public void ActivityLogError ( string message )
194223 {
195- var log = VisualStudio . Services . GetActivityLog ( serviceProvider ) ;
224+ var log = serviceProvider . GetActivityLog ( ) ;
196225 if ( log != null )
197226 {
198227
@@ -204,7 +233,7 @@ public void ActivityLogError(string message)
204233
205234 public void ActivityLogWarning ( string message )
206235 {
207- var log = VisualStudio . Services . GetActivityLog ( serviceProvider ) ;
236+ var log = serviceProvider . GetActivityLog ( ) ;
208237 if ( log != null )
209238 {
210239 if ( ! ErrorHandler . Succeeded ( log . LogEntry ( ( UInt32 ) __ACTIVITYLOG_ENTRYTYPE . ALE_WARNING ,
0 commit comments