예제 #1
0
        private bool IsSolutionExplorerEmpty()
        {
            bool flag = true;
            IVsUIHierarchyWindow explorerToolWindow = this.GetSolutionExplorerToolWindow();

            if (explorerToolWindow != null)
            {
                uint pitemid              = uint.MaxValue;
                IVsMultiItemSelect ppMIS  = (IVsMultiItemSelect)null;
                IntPtr             ppHier = IntPtr.Zero;
                try
                {
                    Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(explorerToolWindow.GetCurrentSelection(out ppHier, out pitemid, out ppMIS));
                    flag = (int)pitemid != -3 && !(ppHier != IntPtr.Zero);
                }
                finally
                {
                    if (ppHier != IntPtr.Zero)
                    {
                        Marshal.Release(ppHier);
                    }
                }
                if (flag)
                {
                    flag = this.GetNumberOfProjectUnderTheSolution() <= 0;
                }
            }
            return(flag);
        }
예제 #2
0
        public IEnumerable <IVsHierarchyItem> GetSelection()
        {
            return(asyncManager.Run(async() => {
                await asyncManager.SwitchToMainThread();

                var selHier = IntPtr.Zero;
                uint selId;
                IVsMultiItemSelect selMulti;

                try {
                    ErrorHandler.ThrowOnFailure(hierarchyWindow.GetCurrentSelection(out selHier, out selId, out selMulti));

                    // There may be no selection at all.
                    if (selMulti == null && selHier == IntPtr.Zero)
                    {
                        return Enumerable.Empty <IVsHierarchyItem> ();
                    }

                    // This is a single item selection.
                    if (selMulti == null)
                    {
                        return new[] { hierarchyManager.GetHierarchyItem(
                                           (IVsHierarchy)Marshal.GetTypedObjectForIUnknown(selHier, typeof(IVsHierarchy)), selId) };
                    }

                    // This is a multiple item selection.

                    uint selCount;
                    int singleHier;
                    ErrorHandler.ThrowOnFailure(selMulti.GetSelectionInfo(out selCount, out singleHier));

                    var selection = new VSITEMSELECTION[selCount];
                    ErrorHandler.ThrowOnFailure(selMulti.GetSelectedItems(0, selCount, selection));

                    return selection.Where(sel => sel.pHier != null)
                    .Select(sel => hierarchyManager.GetHierarchyItem(sel.pHier, sel.itemid))
                    .ToArray();
                } finally {
                    if (selHier != IntPtr.Zero)
                    {
                        Marshal.Release(selHier);
                    }
                }
            }));
        }
예제 #3
0
        public IHierarchyNode GetSelectedProject()
        {
            IVsUIHierarchyWindow uiWindow = VsShellUtilities.GetUIHierarchyWindow(provider, new Guid(ToolWindowGuids.SolutionExplorer));
            IntPtr             pHier;
            uint               pItemId;
            IVsMultiItemSelect itemSelection;
            int hr = uiWindow.GetCurrentSelection(out pHier, out pItemId, out itemSelection);

            if (hr != VSConstants.S_OK)
            {
                throw new HierarchyNodeException(Resources.HierarchyNodeFactory_ErrorNoToolWindow);
            }

            IVsHierarchy selectedHier = Marshal.GetObjectForIUnknown(pHier) as IVsHierarchy;

            Debug.Assert(selectedHier != null);

            HierarchyNode node = new HierarchyNode(solution, selectedHier);

            return(node);
        }
예제 #4
0
        private VSITEMSELECTION[] GetSelectedNodes(IVsUIHierarchyWindow toolWindow)
        {
            ErrorUtilities.VerifyThrowArgumentNull((object)toolWindow, "toolWindow");
            uint   pitemid = uint.MaxValue;
            IntPtr ppHier  = IntPtr.Zero;

            VSITEMSELECTION[] vsitemselectionArray = (VSITEMSELECTION[])null;
            try
            {
                IVsMultiItemSelect ppMIS;
                int currentSelection = toolWindow.GetCurrentSelection(out ppHier, out pitemid, out ppMIS);
                Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(currentSelection);
                if (currentSelection == 0)
                {
                    if ((int)pitemid == -3 && ppMIS != null)
                    {
                        uint pcItems;
                        int  pfSingleHierarchy;
                        int  selectionInfo = ppMIS.GetSelectionInfo(out pcItems, out pfSingleHierarchy);
                        Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(selectionInfo);
                        if (pcItems > 0U)
                        {
                            if (selectionInfo == 0)
                            {
                                VSITEMSELECTION[] rgItemSel = new VSITEMSELECTION[pcItems];
                                for (int index = 0; (long)index < (long)pcItems; ++index)
                                {
                                    rgItemSel[index].itemid = uint.MaxValue;
                                    rgItemSel[index].pHier  = (IVsHierarchy)null;
                                }
                                int selectedItems = ppMIS.GetSelectedItems(0U, pcItems, rgItemSel);
                                Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(selectedItems);
                                if (selectedItems == 0)
                                {
                                    vsitemselectionArray = rgItemSel;
                                }
                            }
                        }
                    }
                    else if ((int)pitemid != -3)
                    {
                        if (ppHier != IntPtr.Zero)
                        {
                            IVsHierarchy objectForIunknown = Marshal.GetObjectForIUnknown(ppHier) as IVsHierarchy;
                            vsitemselectionArray = new VSITEMSELECTION[1]
                            {
                                new VSITEMSELECTION()
                                {
                                    itemid = pitemid,
                                    pHier  = objectForIunknown
                                }
                            };
                        }
                    }
                }
            }
            finally
            {
                if (ppHier != IntPtr.Zero)
                {
                    Marshal.Release(ppHier);
                }
            }
            return(vsitemselectionArray ?? new VSITEMSELECTION[0]);
        }