Sunday, October 19, 2008

I’m very excited that Silverlight 2 has been released. I’m too new to Microsoft to claim even the slightest involvement, but it’s wonderful to see the excitement both within Microsoft as outside.
It will be interesting to see what will happen with the (already great) uptake of Silverlight by the market.

As I am spending most of my days knee-deep in Xaml nowadays, I always try to find things that will help me be more productive. It happens quite often that I want to select a complete xaml tag. It’s way too much effort to use the mouse to select it, so I often use the control-m-m shortcut to collapse a tag and then select it. However, a few days ago I took 5 minutes to automate this.

image

When you put your mouse somewhere in the Grid tag, and use my macro, you end up with this:

image

You can even put your mouse in the endtag. I bound it to Control-Q and it has made my life that much better!

The macro is as simple as this:

    Sub SelectXMLTagContents()
        DTE.ActiveDocument.Selection.StartOfLine(VsStartOfLineOptions.VsStartOfLineOptionsFirstColumn)
        DTE.ExecuteCommand("Edit.ToggleOutliningExpansion")
        DTE.ActiveDocument.Selection.StartOfLine(VsStartOfLineOptions.VsStartOfLineOptionsFirstColumn)
        DTE.ActiveDocument.Selection.EndOfLine(True)
        DTE.ExecuteCommand("Edit.ToggleOutliningExpansion")
End Sub

It collapses a tag, jumps to the first column, selects the line and then does an uncollapse.

For those using a tool like Karl’s ‘Xaml Power Toys’, it might also be a worthwile addition to their shortcuts.

Monday, October 20, 2008 1:40:29 AM (Romance Standard Time, UTC+01:00)
RJ,

Fantastic tip. Took two minutes to get up and running. Wow, that is a fast macro too.

Cheers,

Karl
Friday, October 24, 2008 7:04:32 PM (Romance Standard Time, UTC+01:00)
RJ,

I am new to messing around with macros and when I put yours into VS2008, I get an error of "Error HRESULT E_FAIL has been returned from a call to a COM component." When I tried to run it. I opened my macro explorer, opened up Module1 (since it should work right?), and dropped your function into the code so it shows up like this:

Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports System.Diagnostics

Public Module Module1
Sub SelectXMLTagContents()
DTE.ActiveDocument.Selection.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstColumn)
DTE.ExecuteCommand("Edit.ToggleOutliningExpansion")
DTE.ActiveDocument.Selection.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstColumn)
DTE.ActiveDocument.Selection.EndOfLine(True)
DTE.ExecuteCommand("Edit.ToggleOutliningExpansion")
End Sub
End Module

What am I doing wrong? If I remove the code, it is fine.

Thanks,
Rob
Rob Montague
Saturday, October 25, 2008 6:22:45 AM (Romance Standard Time, UTC+01:00)
This is my module:

Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports System.Diagnostics

Public Module Module1


Sub SelectXMLTagContents()
DTE.ActiveDocument.Selection.StartOfLine(VsStartOfLineOptions.VsStartOfLineOptionsFirstColumn)
DTE.ExecuteCommand("Edit.ToggleOutliningExpansion")
DTE.ActiveDocument.Selection.StartOfLine(VsStartOfLineOptions.VsStartOfLineOptionsFirstColumn)
DTE.ActiveDocument.Selection.EndOfLine(True)
DTE.ExecuteCommand("Edit.ToggleOutliningExpansion")
End Sub


End Module

So, comparing that, it is the exact same.
It should really work like this!!

So, you bind this macro to a key and then you put your cursor somewhere in some code block that you want to select and invoke it.
If that is the moment you get a com exception, I would look into the installation of visual studio. Basically VS supplies the DTE (com)objects to mess around with. Maybe there is something wrong there (although I would guess that you would not have been able to start VS at all if that's the case).

Try it on another computer to be sure.
Ruurd
Name
E-mail
Home page

Comment (HTML not allowed)  

Enter the code shown (prevents robots):