Greetings,
"Open Corresponding .h or .cpp" gets confused when there are files with the same name in the solution, even though the files are in different projects. This manifests itself in either the opening of the wrong file (from another project) or displaying a popup menu of files to choose from.
In the mean time, I whipped up a primitive replacement using macros--it only looks for corresponding files in the same folder. I've not tested it extensively, but it appears to work fine so far:
'' Attempts to open the given file, and returns a boolean indicating success or failure
'' Never throws.
Function OpenFile(ByVal filePath As String)
Try
DTE.ItemOperations.OpenFile(filePath)
Return True
Catch ex As Exception
Return False
End Try
End Function
'' Opens the corresponding header/source file
'' Current file | Target file(s)
'' X.hpp | X.cpp
'' X.h | X.c, else X.cpp
'' X.cpp | X.hpp, else X.h
'' X.c | X.h
Public Sub SwitchHeaderToOrFromSource()
If DTE.ActiveDocument Is Nothing Then Exit Sub
Dim fileInfo As FileInfo = New FileInfo(DTE.ActiveDocument.FullName)
Dim extensionMap As New Dictionary(Of String, String())
extensionMap.Add(".hpp", New String() {".cpp"})
extensionMap.Add(".h", New String() {".c", ".cpp"})
extensionMap.Add(".cpp", New String() {".hpp", ".h"})
extensionMap.Add(".c", New String() {".h"})
Dim currentExt As String = LCase(fileInfo.Extension)
If extensionMap.ContainsKey(currentExt) = False Then Exit Sub
Dim extensions As String() = extensionMap(currentExt)
Dim baseName = Path.GetFileNameWithoutExtension(fileInfo.FullName)
For Each ext As String In extensions
'MsgBox("Trying: " + baseName + ext)
If OpenFile(baseName + ext) = True Then Exit Sub
Next
MsgBox("Could not find any corresponding h/c/hpp/cpp files to open")
End Sub