Using custom plugins in Visual Studio.NET Maxing Your Productivity (3) Custom Add-Ins Help You Maximize The Productivity of Visu

zhaozj2021-02-16  46

How is the plugin work?

InsertDate code given to you in the previous section is quite simple, and the automatic completion of the function is incapable.

I will start with the object browser (Object Browser) because he can learn the object very easy to learn the object so he is a very good assistant. You can click Right click on the object you want to view and then select Go to Definition to view the members of the class. Final Results See Figure 4, you can view the prototype of any member in the member listed, or select a member to press F1 to help.

Figure 4 Object Browser

The ApplicationObject object describes the plug-in host (Host) application, in this example, host (Host) application is Visual Studio .NET IDE. ApplicationObject is implemented in the OnConnection method. Find "DTE" in the online help, even declare the "_dte" type of variables in the code automatically generated. You will see many interesting members at the application level.

One member is an ActiveDocument property (which describes the documentation of the current focus. This document is the document you want to perform insertdate. A very useful rule is that a very useful rule is that the document that is focused on whether the form is focusing regardless of whether the form has focus.

ActiveDocument.Selection property returns a description of the object selected in the document. Because it is an ordinary object in C #, I have enforce the type to convert into TextSelectioni. ActiveDocument is an ordinary class because Document (Translator: Document class similar to VC ) is not necessary based on text, it is better than a form design Document (translator: people who have learned VC may be more familiar with the inheritance relationship of the Document class Unfamiliar people can see books about this. As the final result Selection attribute is also a normal class, here I enforce type to convert it into the TEXTSELECTION type that we actually operate in your code.

TextSelection describes a view of a file (view), and the action of this file and tools in the tools are available in the settings of the settings. He provides a lot of properties and methods you might think about to modify files, and he can affect the view (view), currently selected content, insertion. If you have recorded a macro, you can see using the TextSelection object to capture the content.

INSERTDATE simple setup TEXT attribute value is the current date. Like TEXT, all the actions can set the same type of value. This means that all obtained content must be replaced. If you don't choose content, you will replace it at the location of the cursor, but you have to pay attention to the current state is insert or override mode.

Another method is to use the INSERT function, which allows you to control the location of the text and describe an action that cannot be done. Use this method to replace the Text property to specify the code of the insertion content as follows:

(TextSelection) ApplicationObject.ActiveDocument.selection .insert (

DateTime.now.toString ("YYYY-MM-DD"),

(int) envdte.vsinsertflags.vsinsertflagscollapseetoee);

This vsinsertflags pointed out what the text has been inserted. The documentation of VsInsertFlags is ignored in the online gang group, so I contain this part in Figure 5. Now you should understand how the plugin works, let us make a keyboard bonding and add a menu for this 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 beginning

TextSerection, and the

Resulting TextSerection

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.

转载请注明原文地址:https://www.9cbs.com/read-28323.html

New Post(0)