private void InspectHierarchyItems(IVsHierarchy hier, uint itemid, int level, List <uint> sharedItemIds)
        {
            string caption = HierarchyUtilities.GetHierarchyProperty <string>(hier, itemid, (int)__VSHPROPID.VSHPROPID_Caption);

            this.Output(string.Format("{0}{1}\n", new string('\t', level), caption));

            bool isSharedItem;

            if (HierarchyUtilities.TryGetHierarchyProperty(hier, itemid, (int)__VSHPROPID7.VSHPROPID_IsSharedItem, out isSharedItem) &&
                isSharedItem)
            {
                sharedItemIds.Add(itemid);
            }

            uint child;

            if (HierarchyUtilities.TryGetHierarchyProperty(hier, itemid, (int)__VSHPROPID.VSHPROPID_FirstChild, Unbox.AsUInt32, out child) &&
                child != (uint)VSConstants.VSITEMID.Nil)
            {
                this.InspectHierarchyItems(hier, child, level + 1, sharedItemIds);

                while (HierarchyUtilities.TryGetHierarchyProperty(hier, child, (int)__VSHPROPID.VSHPROPID_NextSibling, Unbox.AsUInt32, out child) &&
                       child != (uint)VSConstants.VSITEMID.Nil)
                {
                    this.InspectHierarchyItems(hier, child, level + 1, sharedItemIds);
                }
            }
        }
        /// <summary>
        /// This function is the callback used to execute a command when the a menu item is clicked.
        /// See the Initialize method to see how the menu item is associated to this function using
        /// the OleMenuCommandService service and the MenuCommand class.
        /// </summary>
        private void MenuItemCallback(object sender, EventArgs e)
        {
            var    sharedHier    = this.FindSharedProject();
            string sharedCaption = HierarchyUtilities.GetHierarchyProperty <string>(sharedHier, (uint)VSConstants.VSITEMID.Root, (int)__VSHPROPID.VSHPROPID_Caption);

            this.Output(string.Format("Found shared project: {0}\n", sharedCaption));

            var    activePlatformHier = this.GetActiveProjectContext(sharedHier);
            string activeCaption      = HierarchyUtilities.GetHierarchyProperty <string>(activePlatformHier, (uint)VSConstants.VSITEMID.Root, (int)__VSHPROPID.VSHPROPID_Caption);

            this.Output(string.Format("The active platform project: {0}\n", activeCaption));

            this.Output("Platform projects:\n");
            foreach (IVsHierarchy platformHier in this.EnumImportingProjects(sharedHier))
            {
                string platformCaption = HierarchyUtilities.GetHierarchyProperty <string>(platformHier, (uint)VSConstants.VSITEMID.Root, (int)__VSHPROPID.VSHPROPID_Caption);
                this.Output(string.Format(" * {0}\n", platformCaption));
            }

            this.Output("Walk the active platform project:\n");
            var sharedItemIds = new List <uint>();

            this.InspectHierarchyItems(activePlatformHier, (uint)VSConstants.VSITEMID.Root, 1, sharedItemIds);

            var    sharedItemId = sharedItemIds[0];
            string fullPath;

            ErrorHandler.ThrowOnFailure(((IVsProject)activePlatformHier).GetMkDocument(sharedItemId, out fullPath));
            this.Output(string.Format("Shared item full path: {0}\n", fullPath));

            var dte       = (EnvDTE.DTE) this.GetService(typeof(EnvDTE.DTE));
            var dteEvents = (EnvDTE80.Events2)dte.Events;

            dteEvents.ProjectItemsEvents.ItemRenamed += this.OnItemRenamed;
            HierarchyUtilities.TryGetHierarchyProperty(activePlatformHier, sharedItemId, (int)__VSHPROPID7.VSHPROPID_SharedProjectHierarchy, out sharedHier);

            uint itemIdInSharedHier;
            int  found;

            VSDOCUMENTPRIORITY[] priority = new VSDOCUMENTPRIORITY[1];
            if (ErrorHandler.Succeeded(((IVsProject)sharedHier).IsDocumentInProject(fullPath, out found, priority, out itemIdInSharedHier)) &&
                found != 0)
            {
                var newName = DateTime.Now.Ticks.ToString() + Path.GetExtension(fullPath);
                ErrorHandler.ThrowOnFailure(sharedHier.SetProperty(itemIdInSharedHier, (int)__VSHPROPID.VSHPROPID_EditLabel, newName));
                this.Output(string.Format("Renamed {0} to {1}\n", fullPath, newName));
            }

            dteEvents.ProjectItemsEvents.ItemRenamed -= this.OnItemRenamed;
        }
Exemplo n.º 3
0
    private static HierarchyNode CreateNode(IVsHierarchy hierarchy, Guid identifier, IVsImageService2 imageService, IVsHierarchyItemManager hierarchyItemManager)
    {
        ThreadHelper.ThrowIfNotOnUIThread();

        ImageMoniker collapsedIcon;
        ImageMoniker expandedIcon;
        string       name;
        bool         isFolder;


        name = HierarchyUtilities.GetHierarchyProperty <string>(
            hierarchy,
            VSConstants.VSITEMID_ROOT,
            (int)__VSHPROPID.VSHPROPID_Name
            );

        isFolder = HierarchyUtilities.IsSolutionFolder(
            hierarchyItemManager.GetHierarchyItem(hierarchy, VSConstants.VSITEMID_ROOT).HierarchyIdentity
            );

        collapsedIcon = imageService.GetImageMonikerForHierarchyItem(
            hierarchy,
            VSConstants.VSITEMID_ROOT,
            (int)__VSHIERARCHYIMAGEASPECT.HIA_Icon
            );

        expandedIcon = imageService.GetImageMonikerForHierarchyItem(
            hierarchy,
            VSConstants.VSITEMID_ROOT,
            (int)__VSHIERARCHYIMAGEASPECT.HIA_OpenFolderIcon
            );

        // Sometimes the icons can be blank.
        // In those cases, use some default icons.
        if (collapsedIcon.Id == 0 && collapsedIcon.Guid == default)
        {
            collapsedIcon = isFolder ? KnownMonikers.FolderClosed : KnownMonikers.DocumentCollection;
        }

        if (expandedIcon.Id == 0 && expandedIcon.Guid == default)
        {
            expandedIcon = isFolder ? KnownMonikers.FolderOpened : KnownMonikers.DocumentCollection;
        }

        return(new HierarchyNode(identifier, name, collapsedIcon, expandedIcon)
        {
            IsLoaded = !HierarchyUtilities.IsStubHierarchy(hierarchy),
            IsFolder = isFolder
        });
    }
Exemplo n.º 4
0
        private bool TryGetManager(out IVsReferenceManagerUser manager)
        {
            _project.GetItemInfo(out IVsHierarchy hierarchy, out uint itemId, out _);

            IVsReferenceManagerUser?value = HierarchyUtilities.GetHierarchyProperty <IVsReferenceManagerUser?>(
                hierarchy,
                itemId,
                (int)__VSHPROPID5.VSHPROPID_ReferenceManagerUser
                );

            if (value is not null)
            {
                manager = value;
                return(true);
            }

            manager = null !;
            return(false);
        }
Exemplo n.º 5
0
    private static Guid GetParentIdentifier(IVsSolution solution, IVsHierarchy hierarchy)
    {
        IVsHierarchy?parentHierarchy;


        ThreadHelper.ThrowIfNotOnUIThread();

        parentHierarchy = HierarchyUtilities.GetHierarchyProperty <IVsHierarchy?>(
            hierarchy,
            VSConstants.VSITEMID_ROOT,
            (int)__VSHPROPID.VSHPROPID_ParentHierarchy
            );

        if (parentHierarchy is not null)
        {
            if (TryGetIdentifier(solution, parentHierarchy, out Guid parentIdentifier))
            {
                return(parentIdentifier);
            }
        }

        return(default);