@@ -12,18 +12,17 @@ namespace SamirBoulema.TGit.Helpers
12
12
public static class FileHelper
13
13
{
14
14
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" ) ;
18
17
19
18
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" ) ;
23
21
24
22
public static string GetMSysGit ( )
25
23
{
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" ) ;
27
26
return Path . Combine ( regPath , "git.exe" ) ;
28
27
}
29
28
@@ -146,8 +145,35 @@ public static string GetExactPathName(string pathName)
146
145
return di . Name . ToUpper ( ) ;
147
146
}
148
147
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>
149
153
public static async Task < string > GetActiveDocumentFilePath ( )
150
154
{
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
+
151
177
var documentView = await VS . Documents . GetActiveDocumentViewAsync ( ) ;
152
178
return documentView ? . FilePath ;
153
179
}
0 commit comments