@@ -12,18 +12,17 @@ namespace SamirBoulema.TGit.Helpers
1212 public static class FileHelper
1313 {
1414 public static string GetTortoiseGitProc ( )
15- {
16- return ( string ) Registry . GetValue ( @"HKEY_LOCAL_MACHINE\SOFTWARE\TortoiseGit" , "ProcPath" , @"C:\Program Files\TortoiseGit\bin\TortoiseGitProc.exe" ) ;
17- }
15+ => ( string ) Registry . GetValue ( @"HKEY_LOCAL_MACHINE\SOFTWARE\TortoiseGit" ,
16+ "ProcPath" , @"C:\Program Files\TortoiseGit\bin\TortoiseGitProc.exe" ) ;
1817
1918 public static string GetTortoiseGitPlink ( )
20- {
21- return ( string ) Registry . GetValue ( @"HKEY_CURRENT_USER\SOFTWARE\TortoiseGit" , "ProcPath" , @"C:\Program Files\TortoiseGit\bin\TortoiseGitPlink.exe" ) ;
22- }
19+ => ( string ) Registry . GetValue ( @"HKEY_CURRENT_USER\SOFTWARE\TortoiseGit" ,
20+ "ProcPath" , @"C:\Program Files\TortoiseGit\bin\TortoiseGitPlink.exe" ) ;
2321
2422 public static string GetMSysGit ( )
2523 {
26- var regPath = ( string ) Registry . GetValue ( @"HKEY_CURRENT_USER\Software\TortoiseGit" , "MSysGit" , @"C:\Program Files (x86)\Git\bin\git.exe" ) ;
24+ var regPath = ( string ) Registry . GetValue ( @"HKEY_CURRENT_USER\Software\TortoiseGit" ,
25+ "MSysGit" , @"C:\Program Files (x86)\Git\bin\git.exe" ) ;
2726 return Path . Combine ( regPath , "git.exe" ) ;
2827 }
2928
@@ -146,8 +145,35 @@ public static string GetExactPathName(string pathName)
146145 return di . Name . ToUpper ( ) ;
147146 }
148147
148+ /// <summary>
149+ /// Get the path of the file on which to act upon.
150+ /// This can be different depending on where the TGit context menu was used
151+ /// </summary>
152+ /// <returns>File path</returns>
149153 public static async Task < string > GetActiveDocumentFilePath ( )
150154 {
155+ var windowFrame = await VS . Windows . GetCurrentWindowAsync ( ) ;
156+ var solutionExplorerIsActive = windowFrame . Guid == new Guid ( WindowGuids . SolutionExplorer ) ;
157+
158+ // Context menu in the Solution Explorer
159+ if ( solutionExplorerIsActive )
160+ {
161+ var selectedItem = await VS . Solutions . GetActiveItemAsync ( ) ;
162+
163+ if ( selectedItem != null )
164+ {
165+ if ( selectedItem . Type == SolutionItemType . Project ||
166+ selectedItem . Type == SolutionItemType . Solution )
167+ {
168+ return Path . GetDirectoryName ( selectedItem . FullPath ) ;
169+ }
170+ else if ( selectedItem . Type == SolutionItemType . PhysicalFile )
171+ {
172+ return selectedItem . FullPath ;
173+ }
174+ }
175+ }
176+
151177 var documentView = await VS . Documents . GetActiveDocumentViewAsync ( ) ;
152178 return documentView ? . FilePath ;
153179 }
0 commit comments