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