The projects in my office are set up like so:
MyProject
MyFiles
Include
MyFile.h
MyFile.cpp
Which I think is not too uncommon. Alt-S doesn't find the header tho, and won't flip to it (it can flip from header to cpp tho).
The fix is to change SwitchToRelated() to be like so:
public static void SwitchToRelated(EnvDTE.Document document)
{
...
// Then, look in project folder and use the first match
foreach (string ext_new in list)
{
name_new = Path.ChangeExtension(name, ext_new);
foreach (ProjectItem projectItem in prj.ProjectItems)
{
if (FindInPrjRecurse(projectItem, name_new))
return;
}
}
}
and add:
public static bool FindInPrjRecurse(ProjectItem projectItem, string name)
{
if (projectItem.Name == name)
{
// Use the first file with equal name
projectItem.Open(Constants.vsViewKindCode);
return true;
}
foreach (ProjectItem subProjectItem in projectItem.ProjectItems)
{
if (FindInPrjRecurse(subProjectItem, name))
return true;
}
return false;
}