<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      VS2010 Extension實踐(1)

      最近VS2010 Extension在Visual Studio Blog(http://blogs.msdn.com/visualstudio/)上提得很頻繁,于是也想翻來文檔研究研究,結果居然找了半天,居然沒有一丁點完整介紹這一塊的,于是,只好自己找著VS IDE上的模板提供的內容和Visual Studio Blog上的講解,一邊Reflector參演,一邊涂鴉一些代碼,準備實彈演練一下,但是覺得這個模板建出來的Extension也太簡單了,剛好看到AxTool(http://www.axtools.com/products-vs2010-extensions.php)有一個代碼編輯器擴展,也是VS Extension的,于是就照著這個,自己一步一步做一下。

      首先,要想建立VS Extension工程,你需要安裝VS2010 SDK,目前是Beta2版本,你可以到這里可以下載:http://go.microsoft.com/fwlink/?LinkID=165597),這里我是通過Editor Text Adornment模板創建的工程,嗯,我就不詳細寫如何通過模板創建自己Extension工程了,如果你不熟悉這里,可以參考Quan To的這篇帖子——Building and publishing an extension for Visual Studio 2010。

      建好工程以后,會自動生成TextViewCreationListener,這里實現了IWpfTextViewCreationListener接口,并通過MEF導出IWpfTextViewCreationListener對象:

       

       

      [TextViewRole("DOCUMENT")]
      [Export(typeof(IWpfTextViewCreationListener))]
      [ContentType("text")]
      internal sealed class PETextViewCreationListener : IWpfTextViewCreationListener    
      {
              void IWpfTextViewCreationListener.TextViewCreated(IWpfTextView textView)
              {
                  //...
              }
      }

       

      這樣VS就會在合適的時候調用IWpfTextViewCreationListener.TextViewCreated方法來通知文字編輯的狀態改變。

      為了實現浮動一個自己的工具欄,這里還需要導出一個AdornmentLayerDefinition,并通過Order Attribute來定制這個Adornment層的顯示位置和次序:

       

              [Name("QuickToolbarAdornmentLayer")]
              [Order(After = "Text")]
              [Export(typeof(AdornmentLayerDefinition))]
              public AdornmentLayerDefinition QuickToolbarLayerDefinition
              {
                  get;
                  set;
              }

       

      這里的Name Attribute很重要,以后的代碼中要獲取我們的AdornmentLayer就得靠它了:

       

      this._adornmentLayer = this._textView.GetAdornmentLayer("QuickToolbarAdornmentLayer");

       

      扯得遠了,回到IWpfTextViewCreationListener.TextViewCreated,通過這里,可以得到一個IWpfTextView,

      這是所有操作的目標和展現,另外,還需要掛他的Closed、LayoutChanged、MouseHovered、SelectionChanged等事件,以響應用戶行為。

      由于我們要通過工具欄操作代碼,所以需要通過MEF導入IEditorOperationsFactoryService:

       

              [Import]
              internal IEditorOperationsFactoryService EditorOperationsFactoryService
              {
                  get;
                  set;
              }

       

      這樣就可以在IWpfTextViewCreationListener.TextViewCreated中通過IEditorOperationsFactoryService.GetEditorOperations(ITextView)來獲得IEditorOperations,有了它,就可以方便快捷的編輯代碼了。

      接下來要實現工具欄的界面,這個就不多說了,建一個UserControl,里面放上ToolBar就搞定了。那么何時何地顯示這個ToolBar呢?這就要依賴IWpfTextView的SelectionChanged事件了,上面提到會掛這個事件就是為這里用的。

       

       1                 private void MayBeAdornmentShowCondition()
       2                 {
       3                     if (!this._textView.Selection.IsEmpty)
       4                     {
       5                         SnapshotPoint startPos = this._textView.Selection.Start.Position;
       6                         SnapshotPoint endPos = this._textView.Selection.End.Position;
       7                         IWpfTextViewLine textViewLineContainingBufferPosition = this._textView.GetTextViewLineContainingBufferPosition(startPos);
       8                         TextBounds characterBounds = textViewLineContainingBufferPosition.GetCharacterBounds(startPos);
       9                         TextBounds bounds2 = this._textView.GetTextViewLineContainingBufferPosition(endPos).GetCharacterBounds(endPos);
      10                         if (this._fromMouseHover)
      11                         {
      12                             this._mustHaveAdornmentDisplayed = true;
      13                         }
      14                         else
      15                         {
      16                             PELeftButtonMouseProcessor property = null;
      17                             try
      18                             {
      19                                 property = this._textView.Properties.GetProperty<PELeftButtonMouseProcessor>(typeof(PELeftButtonMouseProcessor));
      20                             }
      21                             catch
      22                             {
      23                             }
      24                             this._mustHaveAdornmentDisplayed = (property != null)
      25                                 && (property.IsLeftButtonDown
      26                                 || ((DateTime.Now - property.LastLeftButtonDownTime).TotalMilliseconds < 400.0));
      27                         }
      28                         if (this._mustHaveAdornmentDisplayed)
      29                         {
      30                             TextBounds selectionBounds = !this._textView.Selection.IsReversed ? bounds2 : characterBounds;
      31                             int offset = 7;
      32                             double top = selectionBounds.Top + (!this._textView.Selection.IsReversed ? (offset + textViewLineContainingBufferPosition.Height) : (-offset - this._adornmentUI.ActualHeight));
      33                             if (top < 0.0)
      34                             {
      35                                 top = 0.0;
      36                             }
      37                             double left = characterBounds.Left + ((bounds2.Left - characterBounds.Left) / 2.0);
      38                             if ((left + this._adornmentUI.ActualWidth) > this._textView.ViewportWidth)
      39                             {
      40                                 left = this._textView.ViewportWidth - this._adornmentUI.ActualWidth;
      41                             }
      42                             Canvas.SetTop(this._adornmentUI, top);
      43                             Canvas.SetLeft(this._adornmentUI, left);
      44                             long chars = 0L;
      45                             try
      46                             {
      47                                 chars = this._textView.Selection.SelectedSpans[0].Span.Length;
      48                             }
      49                             catch
      50                             {
      51                             }
      52                             this._adornmentUI.SetStatus(chars);
      53                             this.RenderSelectionPopup();
      54                         }
      55                     }
      56                     else
      57                     {
      58                         this._mustHaveAdornmentDisplayed = false;
      59                         this._adornmentLayer.RemoveAdornmentsByTag(this._adornmentTag);
      60                     }
      61                 }
      62 
      63                 private void RenderSelectionPopup()
      64                 {
      65                     if (this._mustHaveAdornmentDisplayed)
      66                     {
      67                         IAdornmentLayerElement element = null;
      68                         try
      69                         {
      70                             element = this._adornmentLayer.Elements.First<IAdornmentLayerElement>(
      71                                 (IAdornmentLayerElement ile) => ile.Tag.ToString() == this._adornmentTag);
      72                         }
      73                         catch (InvalidOperationException)
      74                         {
      75                         }
      76                         if (element == null)
      77                         {
      78                             this._adornmentLayer.AddAdornment(this._textView.Selection.SelectedSpans[0], this._adornmentTag, this._adornmentUI);
      79                         }
      80                         this._timer.Stop();
      81                         this._timer.Start();
      82                     }
      83                 }
      84 
      85                 private void selection_SelectionChanged(object sender, EventArgs e)
      86                 {
      87                     this._fromMouseHover = false;
      88                     this.MayBeAdornmentShowCondition();
      89                 }

       

       

      然后要注意的是IWpfTextView的Closed事件處理要記得取消所有掛這個事件等等收尾工作。

      接下來編譯工程,打包VSIX就完成了,目前實現的主要Feature:

      1、當在代碼編輯器中選擇一段文字,并將鼠標移到文字區域時,QuickToolbar會以半透明的方式“浮”文字的旁邊。

      2、當鼠標移到QuickToolbar區域,QuickToolbar會變成不透明,其上的按鈕會響應鼠標動作。

      3、目前支持的操作有:

      • 剪切(Cut)
      • 復制(Copy)
      • 粘貼(Paste)
      • 刪除(Delete)
      • 減小縮進(Decrease Indent)
      • 增加縮進(Increase Indent)
      • 注釋代碼(Comment)
      • 取消注釋(Uncomment)
      • 等等

      VSIX和源代碼下載以及安裝方法在GCDN論壇: [VS2010擴展]浮動工具欄(http://gcdn.grapecity.com/showtopic-345.html)

      posted @ 2010-08-31 19:57  葡萄城技術團隊  閱讀(3025)  評論(4)    收藏  舉報
      主站蜘蛛池模板: 国产无套白浆一区二区| 国产95在线 | 亚洲| 国产精品成人午夜久久| 99国产精品白浆无码流出| 18禁无遮挡啪啪无码网站破解版| 艳妇臀荡乳欲伦69调教视频| 中文字幕av一区二区| 大地资源免费视频观看| 无码天堂va亚洲va在线va| 久久精品久久黄色片看看| 婷婷久久香蕉五月综合加勒比 | 爆乳日韩尤物无码一区| 波多野无码中文字幕av专区| 日韩国产精品无码一区二区三区| 91亚洲国产成人久久蜜臀| 亚洲日韩久热中文字幕| 国产偷人爽久久久久久老妇app| 在线成人国产天堂精品av| 亚洲色一色噜一噜噜噜| 忻州市| 欧美喷潮最猛视频| 老熟妇乱子交视频一区| 国产卡一卡二卡三免费入口| 丰满少妇特黄一区二区三区| 少妇真人直播免费视频| 国产精品高清国产三级囯产AV| 在线a人片免费观看| 国产成人免费观看在线视频| 国产桃色在线成免费视频| 国产精品成人亚洲一区二区| 久久精品人妻无码一区二区三区| 亚洲中文字幕乱码一区| 日韩中文字幕高清有码| 又爽又黄又无遮挡的视频| 国产成人高清亚洲综合| 亚洲 自拍 另类 欧美 综合| 亚洲中文久久久精品无码| 水蜜桃视频在线观看免费18| 欧洲精品久久久AV无码电影| 亚洲av午夜成人片| 日韩一区二区三区在线观院|