1212using Microsoft . VisualStudio . Shell . Interop ;
1313using System . Collections . Generic ;
1414using GitHub . Models ;
15+ using System . Windows . Input ;
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,14 +141,39 @@ 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 }
@@ -158,6 +185,13 @@ public void ShowMessage(string message)
158185 manager . ShowNotification ( message , NotificationType . Information , NotificationFlags . None , null , default ( Guid ) ) ;
159186 }
160187
188+ public void ShowMessage ( string message , ICommand command )
189+ {
190+ var manager = serviceProvider . TryGetService < ITeamExplorer > ( ) as ITeamExplorerNotificationManager ;
191+ if ( manager != null )
192+ manager . ShowNotification ( message , NotificationType . Information , NotificationFlags . None , command , default ( Guid ) ) ;
193+ }
194+
161195 public void ShowWarning ( string message )
162196 {
163197 var manager = serviceProvider . TryGetService < ITeamExplorer > ( ) as ITeamExplorerNotificationManager ;
0 commit comments