none
Any way to customize appearance of file items in Solution Explorer? RRS feed

  • Question

  • I want to mark somehow one file in a custom project - similar to how startup project name appears in bold font in Solution Explorer.

    I know I can provide an icon via item template, but that's not what I want. I want to highlight or bold dynamically one startup file in a project.

    Any ideas please?

    Friday, August 31, 2007 5:38 PM

Answers

  • Hi Oleg,

     

    From a VS Package, this is actually pretty simple. I added the following to the PythonFileNode::ExecuteCommandOnNode method in the IronPython sample. This bolds the project item when you run the "set as main" command in IronPython. This does not need to be done from the project system however. This could be run from any VSPackage:

     

    IVsUIHierarchyWindow2 windows = VsShellUtilities.GetUIHierarchyWindow(this.ProjectMgr.Site as IServiceProvider, new Guid(ToolWindowGuids80.SolutionExplorer)) as IVsUIHierarchyWindow2;

    windows.SetItemAttribute(this.ProjectMgr as IVsUIHierarchy, this.ID, (uint)__VSHIERITEMATTRIBUTE.VSHIERITEMATTRIBUTE_Bold, true);

     

    The first line gets the IVsUIHierarchyWindow for the solution explorer tool window. The second line calls SetItemAttribute and passes in the hierarchy/project, the ID of the item, and sets the bold attribute to true.

     

    Hopefully that solves your issue! Let me know if you still can't get it to work.

     

    Thanks,

    Aaron

    Saturday, September 1, 2007 5:17 AM
    Moderator

All replies

  • Hi Oleg,

     

    From a VS Package, this is actually pretty simple. I added the following to the PythonFileNode::ExecuteCommandOnNode method in the IronPython sample. This bolds the project item when you run the "set as main" command in IronPython. This does not need to be done from the project system however. This could be run from any VSPackage:

     

    IVsUIHierarchyWindow2 windows = VsShellUtilities.GetUIHierarchyWindow(this.ProjectMgr.Site as IServiceProvider, new Guid(ToolWindowGuids80.SolutionExplorer)) as IVsUIHierarchyWindow2;

    windows.SetItemAttribute(this.ProjectMgr as IVsUIHierarchy, this.ID, (uint)__VSHIERITEMATTRIBUTE.VSHIERITEMATTRIBUTE_Bold, true);

     

    The first line gets the IVsUIHierarchyWindow for the solution explorer tool window. The second line calls SetItemAttribute and passes in the hierarchy/project, the ID of the item, and sets the bold attribute to true.

     

    Hopefully that solves your issue! Let me know if you still can't get it to work.

     

    Thanks,

    Aaron

    Saturday, September 1, 2007 5:17 AM
    Moderator
  • Thanks, Aaron, it works. But I only managed to get it working in a command. Where do you think is the right place to call these lines at project loading so my startup file will always be bolded?

    I tried calling it in IVsSolutionEvents.OnAfterOpenProject or OnAfterOpenSolution with no luck, I get "An item with the same key has already been added." error

    in latter case and "Value does not fall within the expected range." in former case.

    I probably need some event when solution explorer is loaded anf ready. Any idea please?

     

    Sunday, September 2, 2007 9:47 PM
  • Aaron,
    I have the same question as Oleg - where do I set the ItemAttribute when I am loading a project?
    I am implementing a custom project type, so would I rather do it in Load(), CreateFileNode()...?
    Currently I am setting ItemAttribute in the method Load() of ProjectNode, but the changes aren't visible in the SolutionExplorer. Do I have to call anything like Update(), Refresh() on the SolutionExplorer as well?

    And which uint value do I have to set if I want to set a bold Item as non-bold again??

    Thanks for your help,

    Claudia

    Thursday, March 6, 2008 1:11 PM
  • Hi Oleg, Claudia,

    I have solved the similar problem in Neutron with indicating the main file - with different icon. That is my code (look at blue part):

    Code Snippet

            [Browsable(false)]
            public override int ImageIndex
            {
                get
                {
                    if (!File.Exists(Url))
                    {
                        return (int)ProjectNode.ImageName.MissingFile;
                    }
                    if (IsNonMemberItem)
                    {
                        return (int)ProjectNode.ImageName.ExcludedFile;
                    }
                    if (FileName.EndsWith(NeutronConstants.AsFileExtension))
                    {
                        string mainClass = ProjectMgr.GetProjectProperty(Property.MainClass.ToString());
                        if (mainClass == FileName)
                        {
                            return (int)ImageNameEx.MainClass;
                        }
                        return (int)ImageNameEx.File;
                    }
                    return base.ImageIndex;
                }
            }

     

     

    I store the information about what file is the main in the project properties.

    Hope that helps,

    Thursday, March 6, 2008 4:24 PM
    Moderator
  • Thanks Dmitry,
    that would be a nice solution as well.
    I've also found the method I was looking for in order to update the Icon.
    Code Snippet

    HierarchyNode.Redraw(UIHierarchyElement.Icon)



    Claudia


    Friday, March 7, 2008 8:54 AM