Use custom Plug-ins in Visual Studio.NET to maximize your productivity (iii)

Source: Internet
Author: User
Tags definition empty insert visual studio
How does the visual| maximize plug-ins work?

The Insertdate code presented to you in the previous chapters is fairly straightforward, and the AutoComplete feature is incredibly difficult to achieve.

I will start with the Object Browser, because he can easily let us learn the object so he is a very good assistant. Browser You can view the members of a class by right-clicking on the object you want to view and then choosing to move to the definition (go To definition). The final results are shown in Figure 4, where you can view the prototypes of any one of the members in the list or select a member to press F1 to access the first help.




Figure 4 Object Browser

The Applicationobject object describes the plug-in host (host) application, in which the host application is the visual Studio. NET IDE. Applicationobject is implemented in the OnConnection method. Find "DTE" in the online help, even a variable applicationobject declared as "_dte" in the code that the wizard automatically generates. At the application level you will see many interesting members of her.

One of the members is the ActiveDocument property, which describes the document for the current focus. This document is the document that you want to do the insertdate operation. A very useful rule in situations where the window focus and document focus are relevant but different is that a document that has the focus of focus will be saved, regardless of whether the form has focused.

The Activedocument.selection property returns an object that describes the current selection in the document. Because in C # It is a normal object, so I he it forces the type to convert to Textselectioni. ActiveDocument is an ordinary class, because document (translator: Similar to the document class in VC + +) is not necessarily based on text, like a form design document (translator: Learn VC + + People may be more familiar with the inheritance of the document class, and people who are unfamiliar can look at books about it. As a result the selection attribute is also an ordinary class, where I force the type to be converted into classes that we actually manipulate in the code textselection type.

TextSelection describes a view of a file, and the actions and tools of the file-the settings in the options are also in use. He offers a lot of the attributes and methods you might think of modifying the file, as well as the views that he can influence, the current selection, and the insertion position. If you've ever recorded a macro, you can see Using the TextSelection object to capture the content.

Insertdate Simple Set the Text property value to be the current date. Like text, all actions can set values of the same type. This means that all the resulting content has to be replaced, and if there is no selection, it will be replaced at the cursor position, but you should be aware that the current state is insert or overwrite mode.

Another approach is to use the Insert function, which allows you to control the placement of text and describe an action that cannot be redo. Use this method to replace the Text property to specify the code for inserting content as follows:

((TextSelection) applicationObject.ActiveDocument.Selection). Insert (

DateTime.Now.ToString ("Yyyy-mm-dd"),

(int) ENVDTE.VSINSERTFLAGS.VSINSERTFLAGSCOLLAPSETOEND);

This vsinsertflags indicates how the text has been inserted in any way. The Vsinsertflags document was omitted from the online Help group, so I included this part in Figure 5.

Now that you understand how plug-ins work, let's simply make a keyboard bonding and add a menu to the command.

Figure 5 Vsinsertflags Value

Vsinsertflagscollapsetoend
The selection ' s current

Contents are deleted before

Performing the insertion, and

The TextSelection is left empty

At the end of the newly

Inserted text.




Vsinsertflagscollapsetostart


The selection ' s current

Contents are deleted before

Performing the insertion, and

The TextSelection is left empty

At the beginning of the newly

Inserted text.




Vsinsertflagscontainnewtext


The selection ' s current

Contents are replaced with the

Inserted text, and the

TextSelection is left containing

The new text.




Vsinsertflagsinsertatstart
The inserted text is placed at

The beginning of the

TextSelection, and the

Resulting textselection

Contains both the new and

Previous text.




Vsinsertflagsinsertatend


The inserted text is placed at

The end of the TextSelection,

and the resulting

TextSelection contains both

The new and previous text.






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.