Obsessive-compulsive benefits-my first vs plugin, on the using sort!

Source: Internet
Author: User

Let's take a look at vs comes with the Using grooming feature:

The length is different, look to let the life be bored! What kind of sorting is this? It's getting messy, okay?

There is no one, from short to long-the pyramid to move the sort of plan?

So all kinds of Baidu:

"VS. Plugin using Sort"

"VS to using by short to long sort"

"Isn't there a plugin for using sort??? ”

......

People look at my search for the key words to know how the search results, so, had to do their own hands, clothed.

First look at the effect:

Just do it, let's do it. Open vs, create a new project ... Wait, there seems to be something missing.

"As rookie, do not know how to start ah, how to write vs plugin Ah?" ”

This question is good to ask, so, Baidu:

"How do I write vs plugins?" "(not to Baidu advertising, but Chinese search Baidu is actually more useful ...) )

Through a variety of search articles, we know that we need to install VisualStudio SDK stuff.

Next create a project, which, figure:

After the project is created, a page appears:

What exactly does that mean?

I don't know, but probably just let us add a new item with the following template:

So, what are all these templates?

Yes, I think we all know, in fact, I do not know.

So, we found this article: How to extend the Visual Studio editor

Then, according to our needs, choose "Custom Command".

"No, that article did not introduce the custom Command, landlord How do you know how to choose this?" ”

Hey, young people is a problem, I will tell you I have to try it out according to the article? I will only tell you, is this:

Back to the chase.

VS automatically created three files:

1, Xxx.cs

2, XxxPackage.cs

3, XXXPACKAGE.VSCT

"What do all these three files do?" ”

Young people have so many problems, they won't open the file to see?

I do not explain more specifically, anyway, our code is written in the "Menuitemcallback" in the right.

"I don't think you can explain it?" ”

I rub, "code difficult not to dismantle" (write code already so difficult, some things don't expose) ok!

1  Private voidMenuitemcallback (Objectsender, EventArgs e)2         {3             varDTE = This. Serviceprovider.getservice (typeof(DTE)) asDTE;//Get the service, this stuff ... It can be understood as a service object of vs. 4             varSelection = DTE. Activedocument.selection asTextSelection;//selected parts of the current document5             if(Selection = =NULL)6                 return;7             varText = Selection. Text.split (New string[] {"\ r \ n"}, Stringsplitoptions.removeemptyentries);//split it up.8 9             //var lines = text. (L = l.length);//in this way, some words are more short, such as LIIIII and wwww which long? Ten  One             varBMP =NewBitmap ( -, -); A             varg = Graphics.fromimage (BMP);//use GDI to calculate the length of the string -             varFont = This. GetFont ();//gets the VS set font, font size -             vartemp =Newlist<Dynamic>(); the             foreach(varLineinchtext) -             { -                 varSize = g.measurestring (line, font);//Calculating string Lengths -Temp. ADD (New{Text = line, Width =size. Width}); +             } - font. Dispose (); + g.dispose (); A bmp. Dispose (); at  -             varSB =NewStringBuilder (); -             foreach(varLineinchTemp. (t = t.width))//Sort -             { - sb. Appendline (line. Text); -             } in  -Selection. Insert (sb.) ToString (), (int) vsinsertflags.vsinsertflagscollapsetoend);//re-writing the document to  +         } -  the PrivateFont getfont () *         { $             //it should have been through vs object to get the font, but searched for half a day, really can't find which API to callPanax Notoginseng             //but with my ingenuity, I immediately thought of the way -             varsetting = Environment.getfolderpath (Environment.SpecialFolder.MyDocuments) +"\\Visual Studio 2015\\settings\\currentsettings.vssettings"; the             varXML =NewXmlDocument (); + XML. Load (setting); A             foreach(XmlNode IteminchXml. getElementsByTagName ("Category")) the             { +                 if(item. attributes["FontName"] !=NULL&& item. attributes["FontSize"] !=NULL) -                 { $                     return NewFont (item. attributes["FontName"]. Value,float. Parse (item. attributes["FontSize"]. Value)); $                 } -             } -             return NewFont ("New song Body", -); the}
View Code

After writing the code, F5 a bit:

Also true TM good, you see this code, how comfortable, such as pyramid-like piling, write code is an art Ah!

Let's move on to the. vsct file, and we found an article:

Keyboard shortcut menu for bindings

Let's change the text of the menu button:

Add a shortcut key again:

Done!

So far, we have completed a "pyramid sort, artistically" our Code of super-Awesome vs plugin!

>> Click I download <<

Obsessive-compulsive benefits-my first vs plugin, on the using sort!

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.