5

Tôi đang viết phần mở rộng hệ thống dự án cho VS 2017 và mỗi dự án bằng ngôn ngữ của tôi có một tệp là "tệp khởi động". Tôi muốn tập tin đó xuất hiện đậm trong Solution Explorer.Trong hệ thống dự án tùy chỉnh VS 2017, làm thế nào tôi có thể làm cho một mục dự án được in đậm trong Solution Explorer?

Python Tools for VS làm những gì tôi đang tìm kiếm, nhưng tiện ích mở rộng của tôi được xây dựng trên khung hệ thống dự án mới (CPS). Cách CPS để thay đổi diện mạo của các mục Solution Explorer là triển khai IProjectTreePropertiesProvider, nhưng tôi không thấy bất kỳ cách nào để thay đổi kiểu văn bản với nó - chỉ các biểu tượng.

Trả lời

4

Tôi không chắc chắn CPS có bất kỳ nội dung nào được xây dựng cho điều này, nhưng bạn vẫn có thể sử dụng kết hợp giao diện Visual Studio gốc/được quản lý. Đây là ví dụ sử dụng IProjectTreePropertiesProvider:

[Export(typeof(IProjectTreePropertiesProvider))] 
[AppliesTo(MyUnconfiguredProject.UniqueCapability)] 
[Order(1000)] 
internal class ProjectTreePropertiesProvider1 : IProjectTreePropertiesProvider 
{ 
    // we need to import that to do COM calls 
    [Import] 
    protected IProjectThreadingService ThreadingService { get; set; } 

    // we want the "old" IVsHierarchy interface 
    [ImportMany(ExportContractNames.VsTypes.IVsHierarchy)] 
    private OrderPrecedenceImportCollection<IVsHierarchy> IVsHierarchies { get; } 
    private IVsHierarchy VsHierarchy => IVsHierarchies.First().Value; 

    [ImportingConstructor] 
    public ProjectTreePropertiesProvider1(UnconfiguredProject unconfiguredProject) 
    { 
     IVsHierarchies = new OrderPrecedenceImportCollection<IVsHierarchy>(projectCapabilityCheckProvider: unconfiguredProject); 
    } 

    /// <summary> 
    /// Calculates new property values for each node in the project tree. 
    /// </summary> 
    /// <param name="propertyContext">Context information that can be used for the calculation.</param> 
    /// <param name="propertyValues">Values calculated so far for the current node by lower priority tree properties providers.</param> 
    public async void CalculatePropertyValues(IProjectTreeCustomizablePropertyContext propertyContext, IProjectTreeCustomizablePropertyValues propertyValues) 
    { 
     // this is from the standard WindowsScript project type sample 
     if (propertyValues.Flags.Contains(ProjectTreeFlags.Common.ProjectRoot)) 
     { 
      // etc.. 
      propertyValues.Icon = KnownMonikers.JSProjectNode.ToProjectSystemType(); 
      // etc.. 
     } 

     // now, we're doing some COM calls, ensure it happens on UI thread 
     await ThreadingService.SwitchToUIThread(); 

     // get the id of some item (this "Start.js" item is from the standard sample) 
     VsHierarchy.ParseCanonicalName("Start.js", out uint id); 

     // get IVsUIShell from service provider 
     VsHierarchy.GetSite(out Microsoft.VisualStudio.OLE.Interop.IServiceProvider sp); 
     var shell = (IVsUIShell)sp.QueryService<IVsUIShell>(); 

     // get solution explorer's window 
     var SolutionExplorer = new Guid(ToolWindowGuids80.SolutionExplorer); 
     shell.FindToolWindow(0, ref SolutionExplorer, out IVsWindowFrame frame); 

     // get solution explorer's DocView 
     frame.GetProperty((int)__VSFPROPID.VSFPROPID_DocView, out object obj); 
     var window = (IVsUIHierarchyWindow2)obj; 

     // change attribute of the item 
     window.SetItemAttribute((IVsUIHierarchy)VsHierarchy, id, (uint)__VSHIERITEMATTRIBUTE.VSHIERITEMATTRIBUTE_Bold, true); 
    } 
} 
Các vấn đề liên quan