借鉴@Karstens的答案,我修改了在文件之间切换的子程序,使其能够在.cpp和.h文件以及View和View Model文件之间进行切换。
如果您想要做同样的事情,请按照他链接中的说明,但使用这个子程序:
'=====================================================================
' If the currently open document is a CPP or an H file, attempts to
' switch between the CPP and the H file.
'
' If the currently open document is a View.xml or an ViewModel.cs file, attempts to
' switch between the View and the ViewModel file.
'=====================================================================
Sub SwitchBetweenAssociatedFiles()
Dim currentDocument As String
Dim targetDocument As String
currentDocument = ActiveDocument.FullName
If currentDocument.EndsWith(".cpp", StringComparison.InvariantCultureIgnoreCase) Then
targetDocument = Left(currentDocument, Len(currentDocument) - 3) + "h"
ElseIf currentDocument.EndsWith(".h", StringComparison.InvariantCultureIgnoreCase) Then
targetDocument = Left(currentDocument, Len(currentDocument) - 1) + "cpp"
ElseIf currentDocument.EndsWith("View.xaml", StringComparison.InvariantCultureIgnoreCase) Then
targetDocument = currentDocument.Replace("\Views\", "\ViewModels\")
targetDocument = targetDocument.Replace("\View\", "\ViewModel\")
targetDocument = targetDocument.Replace("View.xaml", "ViewModel.cs")
ElseIf currentDocument.EndsWith("ViewModel.cs", StringComparison.InvariantCultureIgnoreCase) Then
targetDocument = currentDocument.Replace("\ViewModels\", "\Views\")
targetDocument = targetDocument.Replace("\ViewModel\", "\View\")
targetDocument = targetDocument.Replace("ViewModel.cs", "View.xaml")
End If
If System.IO.File.Exists(targetDocument) Then
OpenDocument(targetDocument)
End If
End Sub
我将它分配给了Alt + §,这在我的配置中是空闲的。方便与Alt + Tab并用。^_^