2
在Visual Studio 2012中是否有新的“preview tab”功能的Visual Studio 2010插件?是否有Visual Studio 2010文件预览选项卡插件?
在Visual Studio 2012中是否有新的“preview tab”功能的Visual Studio 2010插件?是否有Visual Studio 2010文件预览选项卡插件?
我试图自己做,但我没有做VS扩展也没有使用EnvDTE API expierience。
我按照Building and publishing an extension for 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);
}
});
}
}
我花了几个小时,什么都没发现:/ – JoanComasFdz 2013-04-10 12:35:36