成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

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

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

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

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

Visual Studio 2010擴(kuò)展信息

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

VS2010信息窗口

這個(gè)控件有三個(gè)特殊的狀態(tài)。***個(gè)狀態(tài)是一個(gè)很小的擴(kuò)展按鈕。如上圖的***部分。只需點(diǎn)擊它,就會(huì)打開(kāi)控件右側(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ò)展,此模板將為你的代碼編輯器的帶來(lái)一個(gè)裝飾品。

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

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

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

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

右鍵單擊項(xiàng)目,選擇添加一個(gè)新的WPF用戶(hù)控件。為了簡(jiǎn)單起見(jiàn),我使用了一個(gè)用戶(hù)控件。這個(gè)用戶(hù)控件實(shí)際上包含一個(gè)Expander控件,設(shè)置它的ExpandDirection = Left,它里面又包含了一些TextBlock控件和另外一個(gè)Expander ,設(shè)置里面的這個(gè)Expander的ExpandDirection = Down。看下面的代碼(我刪除不必要的元素,使其更簡(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è)用來(lái)顯示基本的統(tǒng)計(jì)信息和另外一個(gè)顯示擴(kuò)展的統(tǒng)計(jì)信息。我還使用StackPanel來(lái)固定TextBlocks布局。現(xiàn)在,如果你看一下后臺(tái)代碼,發(fā)現(xiàn)它也一樣簡(jiǎn)單。其實(shí)我已經(jīng)創(chuàng)建了一個(gè)CodeInfoTracker類(lèi),用它來(lái)為我們分析源代碼文件。我只是為我們的用戶(hù)控件添加了一個(gè)構(gòu)造函數(shù),使用戶(hù)控件更具擴(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)體放置在我們的自定義類(lèi)中,它有幾個(gè)int屬性用來(lái)保存分析源文件獲取的所有信息。 info.PerFormCalculate(); 給出分析的結(jié)果。這里使用的所有獲取的信息來(lái)更新了UIElements。 #p#

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

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

我可以從WPFTextView.TextSnapshot.GetText()獲得到了源代碼。在我調(diào)用的這個(gè)分析的時(shí)候,我只需要檢測(cè)的代碼是什么語(yǔ)言寫(xiě)的。開(kāi)始我想自己來(lái)實(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è)屬性告訴我是使用了哪種語(yǔ)言。之后我創(chuàng)建了一個(gè)新的方法PerFormCalculate,用它來(lái)解析源代碼,它返回一個(gè)Calculation結(jié)構(gòu)對(duì)象。

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

回到這個(gè)擴(kuò)展,我創(chuàng)建一個(gè)Adornment(InfoBoxAdornmentFactory)的Factory類(lèi)。這個(gè)類(lèi)繼承IWpfTextViewCreationListener,用來(lái)監(jiān)聽(tīng)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è)類(lèi)上使用了很多Attributes,像ContentType,它定義了我們只處理文本格式的編輯器;還有TextViewRole,它定義了將被這個(gè)類(lèi)處理的textview的類(lèi)型。在這個(gè)類(lèi)中,我創(chuàng)建了一個(gè)AdornmentLayerDefination對(duì)象。可能你想知道我們沒(méi)有使用它,無(wú)什么還需要定義它呢,它只是用來(lái)配置屬性的。Order屬性指定,當(dāng),InfoBox在層被選之后監(jiān)聽(tīng),Name是編輯擴(kuò)展的名字。

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

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

因此,通過(guò)這一事件,當(dāng)我們編輯的文檔時(shí),我們可以很容易地得到回調(diào)。當(dāng)瀏覽器編輯器的大小改變時(shí),我還通過(guò)處理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來(lái)獲取的Layer對(duì)象,發(fā)生在ViewportHeightChanged和ViewportWidthChanged ViewPortSizeChage事件。當(dāng)一個(gè)布局改變時(shí),我就能更新這個(gè)用戶(hù)的控件。至此,我們成功地建立我們的擴(kuò)展。你可以使用F5運(yùn)行它,它會(huì)打開(kāi)一個(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. 解密中國(guó)研發(fā)團(tuán)隊(duì)如何開(kāi)發(fā)VS2010新特性
  3. Visual Studio 2010化繁為簡(jiǎn) 令項(xiàng)目管理更輕松
  4. Visual Studio 2010 Lab Management功能
  5. Visual Studio 2010將再度擁抱UML

 

責(zé)任編輯:王曉東 來(lái)源: 博客園
相關(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)

主站蜘蛛池模板: av网站免费看| 国产高清视频 | 欧美精品一二三区 | 一级片免费在线观看 | 天天av网| 国产日韩欧美精品一区二区三区 | 在线播放国产一区二区三区 | 中文字幕高清免费日韩视频在线 | 国产高清在线精品 | 亚洲精品9999 | 国产污视频在线 | 久久国产综合 | 亚洲国产欧美国产综合一区 | 久久久久久久国产 | 特a毛片 | 日本不卡一二三 | 国产激情在线 | 香蕉久久久 | 国产精品久久二区 | 亚洲欧美在线观看视频 | 亚洲欧美日韩精品久久亚洲区 | 亚洲人成人一区二区在线观看 | 人人干人人干人人干 | 久久91精品国产一区二区三区 | 亚洲一区二区精品视频 | 成人精品久久 | 国产高清视频 | 久久久久久一区 | 97视频精品 | 日本精品视频在线观看 | 亚洲精品在线播放 | 国产精品国产三级国产播12软件 | 在线视频一区二区三区 | 日本色高清 | 日韩欧美三级电影 | 女人夜夜春 | 亚洲精品视频导航 | 免费在线一区二区三区 | 另类视频区 | 精品一区二区三区免费毛片 | 日韩在线不卡视频 |