偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

Visual Studio 2010既簡(jiǎn)單又絢麗的新功能

開發(fā) 后端
在微軟Visual Studio 2010的發(fā)布會(huì)上,我們看到了很多關(guān)于VS2010的新特點(diǎn)和功能,文章將介紹幾個(gè)簡(jiǎn)單但很絢麗的功能。

Visual Studio 2010正式版剛剛發(fā)布不久,但通過微軟在發(fā)布會(huì)上的演示,我們就已經(jīng)看到了VS2010嶄新的用戶體驗(yàn)。在這些新功能中,微軟也為我們?cè)黾恿撕芏鄳?yīng)用的擴(kuò)展。

1、文件的代碼行數(shù)
2、文件的字符數(shù)
3、命名空間的個(gè)數(shù)
4、字段個(gè)數(shù)
5、接口個(gè)數(shù)
6、類的個(gè)數(shù)
7、函數(shù)個(gè)數(shù)
8、屬性個(gè)數(shù)
9、注釋的數(shù)量
10、統(tǒng)計(jì)文件的大?。˙ytes, KB, MB等)。

Visual Studio 2010擴(kuò)展信息

當(dāng)您鍵入您的代碼,你會(huì)看到信息窗口中的數(shù)據(jù)會(huì)即時(shí)更新,這個(gè)信息窗口,是利用可擴(kuò)展面板。你可以把它看成兩個(gè)部分,每一個(gè)部分都可以根據(jù)您的需要展開和折疊。這樣,當(dāng)你不需要它時(shí),你將它可以折疊起來,需要的時(shí)候,將它展開。下面演示如何展開/折疊這個(gè)控件。

VS2010信息窗口

這個(gè)控件有三個(gè)特殊的狀態(tài)。***個(gè)狀態(tài)是一個(gè)很小的擴(kuò)展按鈕。如上圖的***部分。只需點(diǎn)擊它,就會(huì)打開控件右側(cè)的面板,這個(gè)面板顯示文件的基本數(shù)據(jù),如上圖的第二部分。這個(gè)控件還有一個(gè)可擴(kuò)展面板,如果點(diǎn)擊擴(kuò)展,就會(huì)看到下面的面板,其中顯示其他的統(tǒng)計(jì)數(shù)據(jù),如上圖的第三部分。

實(shí)現(xiàn)篇:

1、 Microsoft Visual Studio 2010
2、 Visual Studio 2010 SDK

你安裝Visual Studio SDK之后,你的Visual Studio 2010中會(huì)多出下面這些模板:

Visual Studio 2010模版

這篇文章中,我們使用模板Editor ViewPort Adornment實(shí)現(xiàn)這個(gè)擴(kuò)展,此模板將為你的代碼編輯器的帶來一個(gè)裝飾品。

其實(shí)這個(gè)擴(kuò)展包一個(gè)WPF用戶控件,我把它放進(jìn)VS的視窗中就成了信息框。它還含有兩個(gè)類,一個(gè)類用來解析代碼,獲取代碼的相關(guān)信息;另一個(gè)類用來處理自定義編輯器的事件和當(dāng)頁以及加載的時(shí)候?qū)PF控件添加到頁面中。

***步:創(chuàng)建一個(gè)Viewport Adornment項(xiàng)目

我們從Extensibility中選擇Viewport Adornment模板創(chuàng)建一個(gè)項(xiàng)目。這將生成一個(gè)SourceManifest文件和兩個(gè)類文件。一個(gè)是Adornment類本身,另外一個(gè)是AdornmentFactory類。

第二步:添加一個(gè)WPF用戶控件

右鍵單擊項(xiàng)目,選擇添加一個(gè)新的WPF用戶控件。為了簡(jiǎn)單起見,我使用了一個(gè)用戶控件。這個(gè)用戶控件實(shí)際上包含一個(gè)Expander控件,設(shè)置它的ExpandDirection = Left,它里面又包含了一些TextBlock控件和另外一個(gè)Expander ,設(shè)置里面的這個(gè)Expander的ExpandDirection = Down??聪旅娴拇a(我刪除不必要的元素,使其更簡(jiǎn)單):

  1. <Expander ExpandDirection="Left" Style="{DynamicResource ExpanderStyle1}"   
  2. x:Name="expMain" > 
  3. <StackPanel> 
  4. <TextBlock x:Name="txtNoLines"   
  5. Text="No of Lines : {0}"   
  6. Margin="25 25 25 0"   
  7. FontSize="12"   
  8. FontFamily="Verdana"   
  9. FontWeight="Bold"   
  10. Foreground="Yellow"></TextBlock> 
  11. <TextBlock x:Name="txtNoCharacters"   
  12. Text="No of Characters : {0}"   
  13. Margin="25 5 25 15"   
  14. FontSize="12"   
  15. FontFamily="Verdana"   
  16. FontWeight="Bold"   
  17. Foreground="Yellow"></TextBlock> 
  18. <Expander x:Name="expCodeInfo" ExpandDirection="Down"   
  19. Header="Code Information"> 
  20. <StackPanel> 
  21. <TextBlock x:Name="txtClassInfo"   
  22. Margin="25 25 25 0"   
  23. FontSize="12"   
  24. FontFamily="Verdana"   
  25. FontWeight="Bold"   
  26. Foreground="LightYellow"/> 
  27. <Line 
  28. Margin="0,4" 
  29. SnapsToDevicePixels="True" 
  30. Stroke="Gold" 
  31. Stretch="Fill" 
  32. X1="0" X2="1"   
  33. /> 
  34. <TextBlock x:Name="txtFileSize" 
  35. Margin="25 5 25 15"   
  36. FontSize="12"   
  37. FontFamily="Verdana"   
  38. FontWeight="Bold"   
  39. Foreground="AliceBlue"/> 
  40. </StackPanel> 
  41. </Expander> 
  42. </StackPanel> 
  43. </Expander> 

你可以看到,代碼很簡(jiǎn)單,兩個(gè)Expanders,一個(gè)用來顯示基本的統(tǒng)計(jì)信息和另外一個(gè)顯示擴(kuò)展的統(tǒng)計(jì)信息。我還使用StackPanel來固定TextBlocks布局。現(xiàn)在,如果你看一下后臺(tái)代碼,發(fā)現(xiàn)它也一樣簡(jiǎn)單。其實(shí)我已經(jīng)創(chuàng)建了一個(gè)CodeInfoTracker類,用它來為我們分析源代碼文件。我只是為我們的用戶控件添加了一個(gè)構(gòu)造函數(shù),使用戶控件更具擴(kuò)展性而已。

  1. private CodeInfoTracker _cinfo;  
  2. private CodeInfoTracker.Calculators _calculator;  
  3. public ucInfoBox(CodeInfoTracker cinfo)  
  4. : this()  
  5.  {  
  6. this._cinfo = cinfo;  
  7. }  
  8. public void UpdateInfo(CodeInfoTracker info)  
  9. {  
  10. _calculator = info.PerFormCalculate();  
  11. this.txtNoLines.Text = string.Format("No of Lines : {0}",   
  12. _calculator.no_of_lines);  
  13. this.txtNoCharacters.Text = string.Format("No of Characters : {0}",   
  14. _calculator.no_of_characters);  
  15. this.txtFileSize.Text = string.Format("Total File Size : {0}",   
  16. _calculator.totalfilesize);  
  17.  
  18. StringBuilder builder = new StringBuilder();  
  19. if (this._calculator.interfaces != 0)  
  20. builder.AppendFormat("Interfaces : {0}\n\r",   
  21. this._calculator.interfaces);  
  22. if (this._calculator.namespaces != 0)  
  23. builder.AppendFormat("NameSpaces : {0}\n\r",   
  24. this._calculator.namespaces);  
  25. if (this._calculator.classes != 0)  
  26. builder.AppendFormat("Classes : {0}\n\r",   
  27. this._calculator.classes);  
  28. if (this._calculator.methods != 0)  
  29. builder.AppendFormat("Methods : {0}\n\r", this._calculator.methods);  
  30. if (this._calculator.properties != 0)  
  31. builder.AppendFormat("Properties : {0}\n\r",   
  32. this._calculator.properties);  
  33. if (this._calculator.fields != 0)  
  34. builder.AppendFormat("Fields : {0}\n\r", this._calculator.fields);  
  35. if (this._calculator.comments != 0)  
  36. builder.AppendFormat("Comments : {0}\n\r", this._calculator.comments);  
  37. if (builder.Length > 0)  
  38. {  
  39. this.txtClassInfo.Visibility = System.Windows.Visibility.Visible;  
  40. this.txtClassInfo.Text = builder.ToString();  
  41. }  
  42. else  
  43. {  
  44. this.txtClassInfo.Text = "";  
  45. this.txtClassInfo.Visibility = System.Windows.Visibility.Hidden;  
  46. }  

使用了一個(gè)結(jié)構(gòu)體Calculators ,這個(gè)結(jié)構(gòu)體放置在我們的自定義類中,它有幾個(gè)int屬性用來保存分析源文件獲取的所有信息。 info.PerFormCalculate(); 給出分析的結(jié)果。這里使用的所有獲取的信息來更新了UIElements。 #p#

第三步:創(chuàng)建獲取源文件信息的類

雖然代碼存在一些復(fù)雜性,但是這個(gè)類其實(shí)很簡(jiǎn)單。我很感謝CS Parser [^],它幫助我自動(dòng)地解析源代碼。這個(gè)類需要一個(gè)IWpfTextView對(duì)象,它代表著Visual Studio 2010文本編輯器。實(shí)際上WpfTextView實(shí)現(xiàn)了IWpfTextView。在執(zhí)行期間這個(gè)類接受這個(gè)對(duì)象。

我可以從WPFTextView.TextSnapshot.GetText()獲得到了源代碼。在我調(diào)用的這個(gè)分析的時(shí)候,我只需要檢測(cè)的代碼是什么語言寫的。開始我想自己來實(shí)現(xiàn),但是感謝上帝,我在WPFTextView中發(fā)現(xiàn)已經(jīng)存在這個(gè)對(duì)象了。

  1. public enum Language  
  2. {  
  3. CSharp, VisualBasic, Indeterminate  
  4. }  
  5. internal Language DetectLanguage  
  6. {  
  7. get  
  8. {  
  9. string langtype =   
  10. this._view.FormattedLineSource.TextAndAdornmentSequencer.  
  11. SourceBuffer.ContentType.DisplayName;  
  12. if(langtype.Equals("CSHARP",   
  13. StringComparison.InvariantCultureIgnoreCase))  
  14. return Language.CSharp;  
  15. else if(langtype.Equals("BASIC",   
  16. StringComparison.InvariantCultureIgnoreCase))  
  17. return Language.VisualBasic;  
  18. else  
  19. return Language.Indeterminate;  
  20. }  

DetectLanguage妥善地利用WPFTextView對(duì)象的FormattedLineSource.TextAndAdornmentSequencer。SourceBuffer.ContentType.DisplayName,這個(gè)屬性告訴我是使用了哪種語言。之后我創(chuàng)建了一個(gè)新的方法PerFormCalculate,用它來解析源代碼,它返回一個(gè)Calculation結(jié)構(gòu)對(duì)象。

第四步:創(chuàng)建 Adornment Factory 類

回到這個(gè)擴(kuò)展,我創(chuàng)建一個(gè)Adornment(InfoBoxAdornmentFactory)的Factory類。這個(gè)類繼承IWpfTextViewCreationListener,用來監(jiān)聽WPF的編輯和創(chuàng)建事件。

  1. [Export(typeof(IWpfTextViewCreationListener))]  
  2. [ContentType("text")]  
  3. [TextViewRole(PredefinedTextViewRoles.Document)]   
  4. internal sealed class InfoBoxAdornmentFactory : IWpfTextViewCreationListener  
  5. {  
  6. [Export(typeof(AdornmentLayerDefinition))]  
  7. [Name("AlwaysVisibleInfoBox")]  
  8. [Order(After = PredefinedAdornmentLayers.Selection)]  
  9. [TextViewRole(PredefinedTextViewRoles.Interactive)]  
  10. public AdornmentLayerDefinition editorAdornmentLayer = null;  
  11. public void TextViewCreated(IWpfTextView textView)  
  12. {  
  13. new AlwaysVisibleInfoBox(textView);  
  14. }  
  15. }  

這里,你可以看到我在這個(gè)類上使用了很多Attributes,像ContentType,它定義了我們只處理文本格式的編輯器;還有TextViewRole,它定義了將被這個(gè)類處理的textview的類型。在這個(gè)類中,我創(chuàng)建了一個(gè)AdornmentLayerDefination對(duì)象。可能你想知道我們沒有使用它,無什么還需要定義它呢,它只是用來配置屬性的。Order屬性指定,當(dāng),InfoBox在層被選之后監(jiān)聽,Name是編輯擴(kuò)展的名字。

第五步:創(chuàng)建Adornment 類

Adornment類實(shí)際創(chuàng)建了一個(gè)WPF用戶控件對(duì)象,并設(shè)置它的視圖畫布。在內(nèi)部構(gòu)造函數(shù)中,我處理IWpfTextView.LayoutChanged事件,當(dāng)代碼修改或者布局改變的時(shí)候,就觸發(fā)這個(gè)事件。

因此,通過這一事件,當(dāng)我們編輯的文檔時(shí),我們可以很容易地得到回調(diào)。當(dāng)瀏覽器編輯器的大小改變時(shí),我還通過處理WPFTextView.ViewportHeightChanged,WPFTextView.ViewportWidthChanged得到回調(diào),使我們可以重新定位相應(yīng)的UserControl。

  1. public AlwaysVisibleInfoBox(IWpfTextView view)  
  2. {  
  3. _view.LayoutChanged += this.OnLayoutChanged;  
  4. this.GetLayer();  
  5.  }  
  6. private void GetLayer()  
  7. {  
  8.  _adornmentLayer = this._view.GetAdornmentLayer("AlwaysVisibleInfoBox");  
  9. _view.ViewportHeightChanged += delegate { this.onSizeChange(); };  
  10. _view.ViewportWidthChanged += delegate { this.onSizeChange(); };  
  11. }  
  12. private void OnLayoutChanged(object sender, TextViewLayoutChangedEventArgs e)  
  13. {  
  14. this._info = new CodeInfoTracker(_view);  
  15. this.infobox.UpdateInfo(this._info);  
  16. }  
  17. public void onSizeChange()  
  18. {  
  19.  
  20. _adornmentLayer.RemoveAllAdornments();  
  21. Canvas.SetLeft(infobox, _view.ViewportRight - 255);  
  22.  Canvas.SetTop(infobox, _view.ViewportTop + 10);  
  23.  
  24. _adornmentLayer.AddAdornment(AdornmentPositioningBehavior.ViewportRelative,   
  25.  null, null,   
  26. infobox, null);  
  27.  } 

因此,構(gòu)造函數(shù)只是調(diào)用GetLayer來獲取的Layer對(duì)象,發(fā)生在ViewportHeightChanged和ViewportWidthChanged ViewPortSizeChage事件。當(dāng)一個(gè)布局改變時(shí),我就能更新這個(gè)用戶的控件。至此,我們成功地建立我們的擴(kuò)展。你可以使用F5運(yùn)行它,它會(huì)打開一個(gè)Visual Studio 2010的Experimental實(shí)例。

安裝和卸載這個(gè)擴(kuò)展:

安裝和卸載這個(gè)擴(kuò)展是非常容易的。當(dāng)您編譯項(xiàng)目后,它會(huì)產(chǎn)生一個(gè)VSIX文件。您可以只需雙擊這個(gè)文件,它會(huì)自動(dòng)安裝到Visual Studio 2010。

安裝和卸載這個(gè)擴(kuò)展

文章轉(zhuǎn)自海納百川的博客,

原文地址:http://www.cnblogs.com/zhuqil/archive/2010/04/15/Visual-Studio-Extension.html

 

【編輯推薦】

  1. 圖解Visual Studio 2010中的UML建模功能
  2. 解密中國研發(fā)團(tuán)隊(duì)如何開發(fā)VS2010新特性
  3. Visual Studio 2010化繁為簡(jiǎn) 令項(xiàng)目管理更輕松
  4. Visual Studio 2010 Lab Management功能
  5. Visual Studio 2010將再度擁抱UML

 

責(zé)任編輯:王曉東 來源: 博客園
相關(guān)推薦

2010-01-13 09:11:04

Visual Stud

2013-11-13 10:07:26

Visual Stud微軟

2010-02-22 14:00:29

Visual Stud

2013-06-04 17:08:19

Visual Stud

2010-04-08 15:14:59

Visual StudASP.NET 4.

2009-05-19 09:21:50

Visual Stud云計(jì)算并行編程

2009-10-22 14:50:00

Visual Stud

2010-01-15 09:30:22

Visual Stud

2009-12-02 11:22:14

Visual Stud

2009-04-23 14:05:28

Visual Stud歷史調(diào)試功能

2010-04-12 08:43:45

Visual Stud

2009-12-02 09:43:38

Visual Stud

2012-04-25 11:04:13

Visual Stud

2009-10-22 09:47:33

Visual Stud

2009-12-02 10:44:30

Visual Stud

2010-04-15 08:40:00

UML建模Visual Stud

2009-10-19 09:48:24

Visual Stud

2009-03-10 10:21:05

災(zāi)難恢復(fù)Restart Manvs

2009-08-21 13:29:20

Visual Stud

2009-11-19 10:55:33

Visual Stud
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)