From past one year I have been working on Wii games. I was using CodeWarrior IDE. This IDE was not as good as Visual Studio, I used to hate it. But things changed. As I started using it more and more I got to see some really good features like. Pre-Processing a file by context menu. Class hierarchy diagram & few other features. Ofcourse we can Pre-Process a file in VS as well, but we have to go to project settings tab for that. Also, it Pre-Processes all files in the project. Another features which is "open the partner file". You can open c, cpp or cc file if you are in a header file and vice-verse. This small feature is really handy. So I wrote a MACRO for it.
Steps to add this MACRO to your VS IDE,
- Open VS IDE.
- Press Alt+F11 or go to Tools->Macros->Macros IDE.
- Right click on MyMacros->Add->Add New Item.
- Select Module in the dialog box and name it OpenPartnerFile.
- Paste the following code.
Public Module OpenPartnerFile
' if this file is a .cpp then open up the .h
' or vice versa
Sub OpenPartnerFile()
Dim filename As String
Dim partnerFilename As String
filename = DTE.ActiveDocument.FullName
If (filename.EndsWith(".h")) Then
partnerFilename = filename.Substring(0, filename.Length() - 2) ' + ".cpp"
If System.IO.File.Exists(partnerFilename + ".cpp") Then
partnerFilename += ".cpp"
End If
If System.IO.File.Exists(partnerFilename + ".cc") Then
partnerFilename += ".cc"
End If
If System.IO.File.Exists(partnerFilename + ".c") Then
partnerFilename += ".c"
End If
End If
If (filename.EndsWith(".cpp")) Then
partnerFilename = filename.Substring(0, filename.Length() - 4) + ".h"
End If
If (filename.EndsWith(".cc")) Then
partnerFilename = filename.Substring(0, filename.Length() - 3) + ".h"
End If
If (filename.EndsWith(".c")) Then
partnerFilename = filename.Substring(0, filename.Length() - 2) + ".h"
End If
'MsgBox(partnerFilename)
'See if the file exists & open it
If System.IO.File.Exists(partnerFilename) Then
DTE.ItemOperations.OpenFile(partnerFilename)
End If
End Sub
End Module
You are done with the MACRO now. Save and exit the Macro IDE. Now its the time to execute the macro on a keyboard shortcut. Steps are,
' if this file is a .cpp then open up the .h
' or vice versa
Sub OpenPartnerFile()
Dim filename As String
Dim partnerFilename As String
filename = DTE.ActiveDocument.FullName
If (filename.EndsWith(".h")) Then
partnerFilename = filename.Substring(0, filename.Length() - 2) ' + ".cpp"
If System.IO.File.Exists(
partnerFilename += ".cpp"
End If
If System.IO.File.Exists(
partnerFilename += ".cc"
End If
If System.IO.File.Exists(
partnerFilename += ".c"
End If
End If
If (filename.EndsWith(".cpp")) Then
partnerFilename = filename.Substring(0, filename.Length() - 4) + ".h"
End If
If (filename.EndsWith(".cc")) Then
partnerFilename = filename.Substring(0, filename.Length() - 3) + ".h"
End If
If (filename.EndsWith(".c")) Then
partnerFilename = filename.Substring(0, filename.Length() - 2) + ".h"
End If
'MsgBox(partnerFilename)
'See if the file exists & open it
If System.IO.File.Exists(
DTE.ItemOperations.OpenFile(
End If
End Sub
End Module
You are done with the MACRO now. Save and exit the Macro IDE. Now its the time to execute the macro on a keyboard shortcut. Steps are,
- Tools->Options->Environment->Keyboard.
- Select Visual C++ 6 in the first drop down list.
- In the next input box, type : OpenPartnerFile.
- You will get a Macro in the list box below, Click on it.
- Type a short cut of your choice & click assign. I feel "ctrl+` " more convenient.
No comments:
Post a Comment