Visual Studio 2012中是否有新的“preview tab”功能的Visual Studio 2010插件?
答案 0 :(得分:2)
我自己尝试过这样做,但我在进行VS扩展或使用EnvDTE API方面没有任何好处。
我已按照Building and publishing an extension for Visual Studio 2010创建了一个新的Visual Studio 2010扩展程序。
然后我在VSPackage Builder设计器中添加了一个Tools菜单项,并使用此代码尝试模仿该行为。
我无法:
我将代码保留在此处,以防其他人对创建扩展程序感兴趣。希望他对VS可扩展性有更好的了解。
[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);
}
});
}
}