Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
 All Forums
 Visual Assist
 Feature Requests
 Open Corresponding H or CPP Bug

You must be registered to post a reply.
Click here to register.

Screensize:
UserName:
Password:
Format: BoldItalicizeUnderlineStrikethrough Align leftCenterAlign right Insert horizontal ruleUpload and insert imageInsert hyperlinkInsert email addressInsert codeInsert quoted textInsert listInsert Emoji
   
Message:

Forum code is on.
Html is off.

 
Check to subscribe to this topic.
   

T O P I C    R E V I E W
MHaggag Posted - Jun 10 2007 : 11:20:10 AM
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
4   L A T E S T    R E P L I E S    (Newest First)
Old as dirt Posted - Oct 22 2007 : 3:43:42 PM
I liked the old icon for alt-o better than the new one. The new one look mighty generic and I missed it. The only way to tell what it is for is to look at the tip when you hover over it. I never used the alt-o shortcut before and so I thought that you had removed the feature so I was searching to see if anybody else complained about it.
feline Posted - Jun 11 2007 : 06:15:56 AM
quote:
Originally posted by MHaggag

"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.


In addition to sl@sh's comments VA is actually designed to handle this situation, and normally it does.

However if all of the files are in pairs, but not all of the files have been added to the solution then VA will think that the files are not really paired up, and it will show the alt-o menu. This could be why you are seeing this unexpected behaviour.

Having said that, thank you for posting the macro, it should provide a useful start point for people who want / need custom "alt-o" behaviour, e.g. jumping between "odd" file extensions.
sl@sh Posted - Jun 11 2007 : 03:28:57 AM
It's been discussed why VA opens up a list of possible files to switch to for some cases. The point of this behaviour is to catch all possible solutions to the user's request and if there's more than one, let the user decide where to go.

Your macro can be really helpful for those projects that indeed store headers along with the implementation files within the same folder, but in my 15+ years of software engeneering that kind of project file structure was the exception rather than the rule! In spite of the IDE's standard behaviour, storing headers this way is not as common as you might imagine. Hence I like VA's current behaviour. (It also has the nice side-effect that it helps you catch unintentional double function declarations)

For the above reasons I think this is indeed the right forum to post - the current behaviour is not a bug after all.
MHaggag Posted - Jun 10 2007 : 11:21:18 AM
Err..wrong forum. I intended to post this in the general release forum.

© 2023 Whole Tomato Software, LLC Go To Top Of Page
Snitz Forums 2000