2

Visual Studio 2012 の新しい「プレビュー タブ」機能用の Visual Studio 2010 プラグインはありますか?

4

1 に答える 1

2

私は自分でそれをやろうとしましたが、VS 拡張機能や EnvDTE API を使用した経験がありません。

Visual Studio 2010 の拡張機能のビルドと公開に従って、新しい Visual Studio 2010 拡張機能を作成しました。

次に、VSPackage Builder デザイナーで [ツール] メニュー項目を追加し、このコードを使用して動作を模倣しました。

私はできません:

  • ファイルが選択されるたびに決定するため、ループを実行する必要があります。
  • 既存のウィンドウでファイルを開きます。
  • ウィンドウを右側に表示するように変更します。

他の誰かが拡張機能の作成に興味を持っている場合に備えて、ここにコードを残します。彼が VS Extensibility についてよりよく知っていることを願っています。

[Guid(GuidList.guidPreviewDocumentTabPkgString)]
public class PreviewDocumentTabPackage : PreviewDocumentTabPackageBase
{
    private DTE dte;
    private Document currentTab;

    protected override void Initialize()
    {
        base.Initialize();

        this.dte = this.GetService(typeof(_DTE)) as DTE;
        if (this.dte == null)
        {
            throw new ArgumentNullException("dte");
        }

        var applicationObject = (DTE2)GetGlobalService(typeof(SDTE));
        var solutionExplorer = applicationObject.ToolWindows.SolutionExplorer;

        System.Threading.Tasks.Task.Factory.StartNew(() =>
        {
            object currentItem = null;
            while (true) // To be improved
            {
                // Get selected items
                var items = solutionExplorer.SelectedItems as Array;

                // Only do logic if there is one file selected, no preview for multiple files.
                if (items != null &&
                    items.Length == 1)
                {
                    var item = items.GetValue(0);
                    if (currentItem == null)
                    {
                        currentItem = item;
                    }
                    else
                    {
                        // Only show preview if the file is "new".
                        if (item != currentItem)
                        {
                            currentItem = item;

                            // Determine if is a c# file.
                            var realItem = (UIHierarchyItem)currentItem;
                            var itemName = realItem.Name;
                            if (itemName.EndsWith(".cs"))
                            {
                                // Get the file
                                var projectItem = (ProjectItem)realItem.Object;
                                var projectItemPath = projectItem.Properties.Item("FullPath")
                                                                    .Value.ToString();

                                // No already opened file.
                                if (currentTab == null)
                                {
                                    // Open the file and get the window.
                                    this.currentTab = this.dte.Documents.Open(projectItemPath);
                                }
                                else
                                {
                                    // Todo: Open the file in the this.currentTab window.
                                }
                            }
                        }
                    }
                }

                // Avoid flooding
                System.Threading.Thread.Sleep(100);
            }
        });
    }
}
于 2013-04-10T12:58:04.683 に答える