|
Writing Add-Ins for Visual Studio .NET Authors: Smith L. Published year: 2002 Pages: 37-39/172 |
| < Free Open Study > |
In this chapter, you saw how to set up the debugging environment in the Options dialog box. You learned that there are both positives and negatives in the debugger, and you explored ways to work around some of the negatives . You saw how to step through the debugging of an add-in, observing the results that the add-in is effecting on the client IDE as it progresses through the add-in's code. There is no great mystery to debugging an add-in; it just requires that you coordinate the operation of two instances of .NET. But you learned that enhancements have been made to facilitate this process.
Finally, you explored .NET's structured error handling and enhanced your add-in to automatically add error handling to a selected procedure.
In Chapter 5, you will move up a level in complexity, as you learn how to manipulate code in code windows . Chapter 5 is one of the most useful chapters in the book because you will probably build more features to do code manipulation than any other single type of functionality.
| < Free Open Study > |
| < Free Open Study > |
"What matters most in life is not so much how much time we have, but what we do with the time we are given".
-- Author UnknownThus far in working with code in the IDE's Text Editor windows, I've made very few references to the extensibility object of Visual Studio .NET. I've done this for two reasons. First, I wanted to get quickly and simply into building some usable functionality in an add-in. Second, I wanted to demonstrate the use of some common methods that you can reuse most of the time for retrieving code from a code window, performing some operation on the code, and subsequently putting it back into the code window without having to constantly be concerned with the complex syntax of the extensibility object. I suspect that the library routines I've provided for retrieval and replacement of code in a window will work for you 90 percent of the time you want to work on code.
In this chapter, I concentrate on the text-handling objects in the extensibility model. There will obviously be times when you will need to do something to or with code windows that goes beyond simply retrieving and putting back code. Therefore, you must explore some of the extensive details of the text-handling objects. In this chapter, I introduce you to the Documents collection and the Document object as a lead-in to learning how to control the Visual Studio .NET Code Editor.
| Tip |
I don't want to jump ahead into the subject of macros (which is reserved for Chapter 8). However, if you're already familiar with the use of macros in Visual Studio .NET, you can take the code from the short example snippets in the next few topics, enclose it with Sub/End Sub, and actually execute these examples in the Macros IDE. Because I'm illustrating code snippets in the context of an add-in, if you choose to execute the code in the Macro Explorer, substitute DTE for oVB wherever you find it in the code samples. |
| < Free Open Study > |
| < Free Open Study > |
The Documents collection contains all of the Document objects in the IDE. Each object represents an open document. You can reference all of the open documents by looping through the Documents collection. Executing the code sample in Listing 5-1 in an add-in closes all open documents that have been previously saved.
| Note |
When DTE is the parent object in sample code, and I am discussing code within an add-in, I will always use the application object and substitute the variable name oVB for DTE.You will remember from Chapter 3 that I used oVB as ashort name for the application object. DTE will be used as the real object when I discuss code examples in Chapter 8. |
Listing 5-1: Closing Saved Documents
|
|
' Close all saved documents. Dim i As Integer With oVB Try For i = 1 To .Documents.Count If .Documents.Item(i).Saved Then .Documents.Item(i).Close() End If Next I Catch ' Ignore any error we raise attempting to close End Try End With
|
|
| < Free Open Study > |
|
Writing Add-Ins for Visual Studio .NET Authors: Smith L. Published year: 2002 Pages: 37-39/172 |