Visual Studio 2008 Extensibility Development (vii): manipulating a text editor

Source: Internet
Author: User

Objective

In scalability Development (vi), I introduced the basic operations for Solution Explorer. However, for our developers, most of the time to face the editor.

VS2008 's editor is already quite powerful, and if we can use shortcut keys skillfully, the process of writing code is quite comfortable, as the successful programmer says:

"Always use the keyboard rather than the mouse when programming"

But the problem is that VS is for all the developer groups, it only provides the most versatile functionality, and if there is some additional need for the VS editor, we'll have to do it ourselves, and this article will explain how to extend the text editor.

Editor-related interfaces in AOM

As before, here is a brief introduction to the relevant interfaces, types in AOM.

1) Documents

By default, vs renders open documents in tabbed documents. The collection of these documents is documents in AOM, which implements the IEnumerable interface. Through this interface, we can get the currently open document, its important properties and methods are:

Count: Number of open documents;

Add (): Adds a new document to the collection;

CloseAll (): Closes all documents, its parameter is the vsSaveChanges enumeration, may provide the behavior option when closes, like prompts the user to save;

Item (): Gets a document from the collection based on the index;

Open (): Opens a document;

SaveAll (): Saves all documents.

The meaning of these members is quite simple and straightforward. We can loop through all open documents to get information about all the documents, and for a single document, it corresponds to the document interface.

2) Document

Represents a document opened for editing in vs. It has more members, here are only a few more important:

Fullname/path/name: The full name, directory, and filename of the document;

Language: The language type of the document, such as CSharp;

ProjectItem: Gets the ProjectItem object associated with the document;

Selection: Selected content in the document;

Type: Types of documents;

Activate (): Moves focus to the document;

Close (): Closes the document;

Redo ()/undo (): Perform redo/undo operation;

Save (): Saves the document.

For more information about the document members, please refer to here. The selection attribute is very useful, because most of the time we have to select a part of the document, and then do the appropriate action. In addition, in multiple documents that are open, only one is active, and you can use the Dte.activedocument property to quickly get the document.

After you get a reference to the document, you can consider how to edit it next. We need to know 5 interfaces: TextSelection, TextPoint, EditPoint, VirtualPoint, TextDocument. I'm sure you'll be handy when you're working with the editor when you know these interfaces.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.