//  -------------------------------------------------------------------
        /// <summary>
        /// Creates a new submittable physical item.
        /// </summary>
        /// <param name="rootPath">
        /// The root path of the solution that contains this item.
        /// </param>
        /// <param name="project">
        /// The project that contains this item.
        /// </param>
        /// <param name="hierItem">
        /// The hierarchy item that this item represents.
        /// </param>
        public SubmittablePhysicalItem(string rootPath, IVsProject project,
			HierarchyItem hierItem)
        {
            this.rootPath = rootPath;
            this.project = project;
            this.hierarchy = hierItem;
        }
        //  -------------------------------------------------------------------
        /// <summary>
        /// Gets an array of hierarchy items that represent the currently
        /// selected items in the Solution Explorer.
        /// </summary>
        /// <param name="provider">
        /// The DTE object to use as a service provider.
        /// </param>
        /// <returns>
        /// An array of HierarchyItem objects that are currently selected.
        /// </returns>
        public static HierarchyItem[] GetCurrentSelection(
            IServiceProvider provider)
        {
            IVsMonitorSelection vsms = (IVsMonitorSelection)
                                       provider.GetService(typeof(SVsShellMonitorSelection));

            IntPtr             hierPtr;
            uint               itemID;
            IVsMultiItemSelect multiSel;
            IntPtr             selCont;

            vsms.GetCurrentSelection(out hierPtr, out itemID, out multiSel,
                                     out selCont);

            if (hierPtr != IntPtr.Zero)
            {
                // Single selection

                IVsHierarchy hier = IntPtrToInterface <IVsHierarchy>(hierPtr);

                return(new HierarchyItem[] {
                    new HierarchyItem(hier, itemID)
                });
            }
            else if (itemID == VSConstants.VSITEMID_SELECTION)
            {
                // Multiple selection

                uint count;
                int  isSingle;
                multiSel.GetSelectionInfo(out count, out isSingle);

                VSITEMSELECTION[] selection = new VSITEMSELECTION[count];
                multiSel.GetSelectedItems(0, count, selection);

                HierarchyItem[] hierItems = new HierarchyItem[count];
                int             i         = 0;
                foreach (VSITEMSELECTION selectedItem in selection)
                {
                    hierItems[i++] = new HierarchyItem(selectedItem.pHier,
                                                       selectedItem.itemid);
                }

                return(hierItems);
            }
            else
            {
                return(new HierarchyItem[] { });
            }
        }
Example #3
0
        //  -------------------------------------------------------------------
        /// <summary>
        /// Returns true if two hierarchy items are the same (that is, they
        /// contain the same hierarchy interface and item ID).
        /// </summary>
        /// <param name="obj">
        /// The object to compare to this hierarchy item.
        /// </param>
        /// <returns>
        /// True if the hierarchy items are the same; false if they are not, or
        /// if the given object is not a hierarchy item.
        /// </returns>
        public override bool Equals(object obj)
        {
            HierarchyItem rhs = obj as HierarchyItem;

            if (rhs != null)
            {
                return((hierarchy == rhs.hierarchy) &&
                       (itemID == rhs.itemID));
            }
            else
            {
                return(false);
            }
        }
        //  -------------------------------------------------------------------
        /// <summary>
        /// Searches the current selection to determine if the given hierarchy
        /// item is contained in it.
        /// </summary>
        /// <param name="hierarchyItem">
        /// The hierarchy item to search for.
        /// </param>
        /// <returns>
        /// True if the hierarchy item was found in the selection; otherwise,
        /// false.
        /// </returns>
        private bool FindHierarchyItemInSelection(HierarchyItem hierarchyItem)
        {
            foreach (ISubmittableItem item in selection)
            {
                SubmittableProject sp = item as SubmittableProject;

                if (sp != null)
                {
                    if (sp.HierarchyItem.Equals(hierarchyItem))
                    {
                        return true;
                    }
                }
            }

            return false;
        }
        //  -------------------------------------------------------------------
        /// <summary>
        /// Adds the specified hierarchy item as a new child node of the given
        /// node.
        /// </summary>
        /// <param name="item">
        /// The hierarchy item to be added.
        /// </param>
        /// <param name="parent">
        /// The node to add this hierarchy item as a child of.
        /// </param>
        private void AddHierarchyItemToNode(HierarchyItem item,
			TreeNode parent)
        {
            TreeNode node = new TreeNode(item["Name"].ToString());
            node.Tag = item;

            treeImages.Images.Add(item.Icon);

            node.ImageIndex = node.SelectedImageIndex =
                treeImages.Images.Count - 1;

            if (parent.Checked || FindHierarchyItemInSelection(item))
                node.Checked = true;

            parent.Nodes.Add(node);

            // Perhaps recursively handle nested projects here?
        }