mardi 13 mars 2007

ToggleCSharpNavigationBar update

While ToggleCSharpNavigationBar is great when having performance as a goal, it wasn't completely doing stuff I wanted so I updated it.

So now, it deactivate the navigation bar in .CS, .HTML & .ASPX

Sub ToggleCSharpNavigationBar()

'for DBG purposes
'If (InputBox("File", "", DTE.ActiveDocument.Name & DTE.ActiveDocument.Kind)) = "" Then Return

Dim objShowNavigationBar As EnvDTE.Property

Dim setProp As Boolean 'whether props have been set

setProp = True

Dim kindDoc As String

kindDoc = DTE.ActiveDocument.Kind

Dim fileName As String

fileName = DTE.ActiveDocument.Name.ToLower()

Select Case kindDoc

Case "{8E7B96A8-E33D-11D0-A6D5-00C04FB67F6A}" 'This kind is for "text" files VB, CS, XML...

If fileName.EndsWith(".cs") Then
objShowNavigationBar = DTE.Properties("TextEditor", "CSharp").Item("ShowNavigationBar")
Else
setProp = False
End If

Case "{57312C73-6202-49E9-B1E1-40EA1A6DC1F6}" 'ASPX

objShowNavigationBar = DTE.Properties("TextEditor", "HTML").Item("ShowNavigationBar")

Case "{C76D83F8-A489-11D0-8195-00A0C91BBEE3}" 'HTML

objShowNavigationBar = DTE.Properties("TextEditor", "HTML").Item("ShowNavigationBar")

Case Else

setProp = False

End Select

If (setProp) Then objShowNavigationBar.Value = Not objShowNavigationBar.Value

End Sub

3 commentaires:

Unknown a dit…

I Know that this post is very Old, but a very usefull one.
I'm testing your code in Visual Studio 2008 and it seems that if you Hide the Navigation Bar, when you want to Show it again it doesn't Show. If you close the file and reopen the navigation bar is there.

Let me explain it better:

1. Start with the NavBar Closed
2. Toogle to ShowIt (fine)
3. Toogle to HideIt (fine)
4. Toogle again to ShowIt (wrong)

but if you before step 4 close and reopen the file it works, it works with other files to, but not if you toogle several times on the same open file in the editor.

Are you experimenting something similar, I think maybe it's a bug because code seems to be fine.

Thanks,
Ernesto

JMG a dit…

I guess this is a bug in VS2008 because I'm using VS2005 and everything's fine.

Working with .CS, .ASPX and .HTML files.

Maybe you can post this on support.microsoft.com because I don't have VS2008.

JM.

Unknown a dit…

Thank you very much for your attention!

You're right, I've tested to with VS2005 and works perfectly, so I'll check with MS support and I let you know when I have a solution so if you go for vs2008 someday you will not lose this excellent tip

Ernesto