Oh how lazy I truly is.
Currently I am doing some heavy manipulation of Xml tags. I ended up with a Excel spreadsheet of new Xml tags I wanted to generate and I wanted to build a Xml document to send off to our QA team for review. MAN was I getting sick of typing "<" and then looking at the text in my excel spreadsheet and typing it in, ensuring I get the case sensitivity correct and then typing ">". At least Visual Studio will generate the closing tag for you. But that was getting very annoying. In comes Macros in Visual Studio. So here is what I did.
- Open Macros IDE
- Click Tools
- Macros
- Macros IDE...
- Add Module for your Custom Macros
- Right click the "MyMacros" in the Project Explorer
- Click Add
- Add Module
- Type in whatever name you want to name this module
- Click Add
- Program Functions inside your module.
- Public Module CreateXmlTag
- Sub SurroundWithXmlTag()
- DTE.ActiveDocument.Selection.Text = "<" + DTE.ActiveDocument.Selection.Text + ">"
- End Sub

- I didn't add the second half of the tags since Visual Studio will auto generate the closing tag. You could do many manipulations here. Like adding <b> for HTML, or whatever you want :)
- Save and Close the Macros IDE window
- Then I added the macro to a toolbar for convenience
- Tools
- Customize
- Click New
- Type in name of Toolbar and click Ok. You will then have a toolbar appear
- Click the "Commands" tab
- Select the radio button "Toolbar:" (Mine was GenerateXmlTag)
- Select "Add Command..."
- Under Categories scroll down to "Macros"
- Find your Macro
- Click Add

- Next I wanted to bind it to a keyboard command.
- Select Keyboard...
- I filtered by "Xml"
- Found my Command
- "Used the new shortcut in:" Xml Editor with Alt+J, Alt+K

- Viola!
- I can now copy and past my text from Excel
| OpenDate |
| VoidDate |
|
CloseDate
Highlight and press either my button or my keyboard command and it works like a charm.
<OpenDate></OpenDate> <VoidDate></VoidDate> <CloseDate></CloseDate>
P.S. If you don't like the ugly looking text in your toolbar. Visual Studio has a way to add a button image to a command. I personally used Ryan Molden's tool which made things much easier for me.
http://blogs.msdn.com/b/visualstudio/archive/2010/06/17/command-image-changing-extension.aspx
I hoped you enjoyed my lazy post.
|
69588fc9-3227-4bbe-acce-29902035166c|1|5.0
Xml, VS2010, Macros