1111using GitHub . Services . Vssdk . Commands ;
1212using EnvDTE ;
1313using Microsoft . VisualStudio ;
14+ using Microsoft . VisualStudio . Shell ;
15+ using Microsoft . VisualStudio . Shell . Interop ;
16+ using Task = System . Threading . Tasks . Task ;
17+ using SVsServiceProvider = Microsoft . VisualStudio . Shell . SVsServiceProvider ;
1418
1519namespace GitHub . VisualStudio . Commands
1620{
@@ -22,6 +26,7 @@ public class OpenFromUrlCommand : VsCommand<string>, IOpenFromUrlCommand
2226 readonly Lazy < IPullRequestEditorService > pullRequestEditorService ;
2327 readonly Lazy < IGitHubToolWindowManager > gitHubToolWindowManager ;
2428 readonly Lazy < DTE > dte ;
29+ readonly IServiceProvider serviceProvider ;
2530
2631 /// <summary>
2732 /// Gets the GUID of the group the command belongs to.
@@ -38,15 +43,16 @@ public OpenFromUrlCommand(
3843 Lazy < GitHubContextService > gitHubContextService ,
3944 Lazy < IRepositoryCloneService > repositoryCloneService ,
4045 Lazy < IPullRequestEditorService > pullRequestEditorService ,
41- [ Import ( typeof ( Microsoft . VisualStudio . Shell . SVsServiceProvider ) ) ] IServiceProvider sp ) :
46+ [ Import ( typeof ( SVsServiceProvider ) ) ] IServiceProvider serviceProvider ) :
4247 base ( CommandSet , CommandId )
4348 {
4449 this . gitHubContextService = gitHubContextService ;
4550 this . repositoryCloneService = repositoryCloneService ;
4651 this . pullRequestEditorService = pullRequestEditorService ;
47- dte = new Lazy < DTE > ( ( ) => ( DTE ) sp . GetService ( typeof ( DTE ) ) ) ;
52+ this . serviceProvider = serviceProvider ;
53+ dte = new Lazy < DTE > ( ( ) => ( DTE ) serviceProvider . GetService ( typeof ( DTE ) ) ) ;
4854 gitHubToolWindowManager = new Lazy < IGitHubToolWindowManager > (
49- ( ) => ( IGitHubToolWindowManager ) sp . GetService ( typeof ( IGitHubToolWindowManager ) ) ) ;
55+ ( ) => ( IGitHubToolWindowManager ) serviceProvider . GetService ( typeof ( IGitHubToolWindowManager ) ) ) ;
5056
5157 // See https://code.msdn.microsoft.com/windowsdesktop/AllowParams-2005-9442298f
5258 ParametersDescription = "u" ; // accept a single url
@@ -91,21 +97,58 @@ public override async Task Execute(string url)
9197
9298 if ( ! Directory . Exists ( repositoryDir ) )
9399 {
94- await repositoryCloneService . Value . CloneRepository ( cloneUrl , repositoryDirName , targetDir ) ;
100+ var result = ShowInfoMessage ( $ "Clone '{ cloneUrl } ' to '{ repositoryDir } '?") ;
101+ switch ( result )
102+ {
103+ case VSConstants . MessageBoxResult . IDYES :
104+ await repositoryCloneService . Value . CloneRepository ( cloneUrl , repositoryDirName , targetDir ) ;
105+ // Open the cloned repository
106+ dte . Value . ExecuteCommand ( "File.OpenFolder" , repositoryDir ) ;
107+ dte . Value . ExecuteCommand ( "View.TfsTeamExplorer" ) ;
108+ break ;
109+ case VSConstants . MessageBoxResult . IDNO :
110+ // Target the current solution
111+ repositoryDir = FindSolutionDirectory ( dte . Value . Solution ) ;
112+ if ( repositoryDir == null )
113+ {
114+ // No current solution to use
115+ return ;
116+ }
117+
118+ break ;
119+ case VSConstants . MessageBoxResult . IDCANCEL :
120+ return ;
121+ }
95122 }
96123
97124 var solutionDir = FindSolutionDirectory ( dte . Value . Solution ) ;
98125 if ( solutionDir == null || ! ContainsDirectory ( repositoryDir , solutionDir ) )
99126 {
100- // Open if current solution isn't in repository directory
101- dte . Value . ExecuteCommand ( "File.OpenFolder" , repositoryDir ) ;
102- dte . Value . ExecuteCommand ( "View.TfsTeamExplorer" ) ;
127+ var result = ShowInfoMessage ( $ "Open repository fiolder at '{ repositoryDir } '?") ;
128+ switch ( result )
129+ {
130+ case VSConstants . MessageBoxResult . IDYES :
131+ // Open if current solution isn't in repository directory
132+ dte . Value . ExecuteCommand ( "File.OpenFolder" , repositoryDir ) ;
133+ dte . Value . ExecuteCommand ( "View.TfsTeamExplorer" ) ;
134+ break ;
135+ case VSConstants . MessageBoxResult . IDNO :
136+ break ;
137+ case VSConstants . MessageBoxResult . IDCANCEL :
138+ return ;
139+ }
103140 }
104141
105142 await TryOpenPullRequest ( gitHubUrl ) ;
106143 TryOpenFile ( gitHubUrl , context , repositoryDir ) ;
107144 }
108145
146+ VSConstants . MessageBoxResult ShowInfoMessage ( string message )
147+ {
148+ return ( VSConstants . MessageBoxResult ) VsShellUtilities . ShowMessageBox ( serviceProvider , message , null ,
149+ OLEMSGICON . OLEMSGICON_QUERY , OLEMSGBUTTON . OLEMSGBUTTON_YESNOCANCEL , OLEMSGDEFBUTTON . OLEMSGDEFBUTTON_FIRST ) ;
150+ }
151+
109152 static bool ContainsDirectory ( string repositoryDir , string solutionDir )
110153 {
111154 if ( solutionDir . Equals ( repositoryDir , StringComparison . OrdinalIgnoreCase ) )
0 commit comments