@@ -216,65 +216,49 @@ void OnBeforeQueryStatus(object sender, EventArgs e)
216216 Visible = false ;
217217 }
218218
219+ // Set command Text/Visible properties and return true when active
219220 bool TryNavigateFromHistoryFileQueryStatus ( IVsTextView sourceView )
220221 {
221- if ( teamExplorerContext . Value . ActiveRepository ? . LocalPath == null )
222+ if ( teamExplorerContext . Value . ActiveRepository ? . LocalPath is string && // Check there is an active repo
223+ FindObjectishForTFSTempFile ( sourceView ) is string ) // Looks like a history file
222224 {
223- // Only available when there's an active repository
224- return false ;
225+ // Navigate from history file is active
226+ Text = "Open File in Solution" ;
227+ Visible = true ;
228+ return true ;
225229 }
226230
227- var filePath = FindPath ( sourceView ) ;
228- if ( filePath == null )
229- {
230- return false ;
231- }
232-
233- var objectish = gitHubContextService . Value . FindObjectishForTFSTempFile ( filePath ) ;
234- if ( objectish == null )
235- {
236- // Not a temporary Team Explorer blob file
237- return false ;
238- }
239-
240- // Navigate from history file is active
241- Text = "Open File in Solution" ;
242- Visible = true ;
243- return true ;
231+ return false ;
244232 }
245233
234+ // Attempt navigation to historical file
246235 bool TryNavigateFromHistoryFile ( IVsTextView sourceView )
247236 {
248- var repositoryDir = teamExplorerContext . Value . ActiveRepository ? . LocalPath ;
249- if ( repositoryDir == null )
250- {
251- return false ;
252- }
253-
254- var path = FindPath ( sourceView ) ;
255- if ( path == null )
237+ if ( teamExplorerContext . Value . ActiveRepository ? . LocalPath is string repositoryDir &&
238+ FindObjectishForTFSTempFile ( sourceView ) is string objectish )
256239 {
257- return false ;
258- }
259-
260- var objectish = gitHubContextService . Value . FindObjectishForTFSTempFile ( path ) ;
261- if ( objectish == null )
262- {
263- return false ;
264- }
240+ var ( commitSha , blobPath ) = gitHubContextService . Value . ResolveBlobFromHistory ( repositoryDir , objectish ) ;
241+ if ( blobPath is string )
242+ {
243+ var workingFile = Path . Combine ( repositoryDir , blobPath ) ;
244+ VsShellUtilities . OpenDocument ( serviceProvider , workingFile , VSConstants . LOGVIEWID . TextView_guid ,
245+ out IVsUIHierarchy hierarchy , out uint itemID , out IVsWindowFrame windowFrame , out IVsTextView targetView ) ;
265246
266- var ( commitSha , blobPath ) = gitHubContextService . Value . ResolveBlobFromHistory ( repositoryDir , objectish ) ;
267- if ( blobPath == null )
268- {
269- return false ;
247+ pullRequestEditorService . Value . NavigateToEquivalentPosition ( sourceView , targetView ) ;
248+ return true ;
249+ }
270250 }
271251
272- var workingFile = Path . Combine ( repositoryDir , blobPath ) ;
273- VsShellUtilities . OpenDocument ( serviceProvider , workingFile , VSConstants . LOGVIEWID . TextView_guid ,
274- out IVsUIHierarchy hierarchy , out uint itemID , out IVsWindowFrame windowFrame , out IVsTextView targetView ) ;
252+ return false ;
253+ }
275254
276- pullRequestEditorService . Value . NavigateToEquivalentPosition ( sourceView , targetView ) ;
277- return true ;
255+ // Find the blob SHA in a file name if any
256+ string FindObjectishForTFSTempFile ( IVsTextView sourceView )
257+ {
258+ return
259+ FindPath ( sourceView ) is string path &&
260+ gitHubContextService . Value . FindObjectishForTFSTempFile ( path ) is string objectish ?
261+ objectish : null ;
278262 }
279263
280264 // See http://microsoft.public.vstudio.extensibility.narkive.com/agfoD1GO/full-pathname-of-file-shown-in-current-view-of-core-editor#post2
0 commit comments