Ejemplo n.º 1
0
        internal void SetActiveSession(SessionNode node)
        {
            uint oldItem = _activeSession;

            if (oldItem != VSConstants.VSITEMID_NIL)
            {
                _window.ExpandItem(this, _activeSession, EXPANDFLAGS.EXPF_UnBoldItem);
            }

            _activeSession = node.ItemId;

            _window.ExpandItem(this, _activeSession, EXPANDFLAGS.EXPF_BoldItem);
        }
        public override int OnAfterOpenProject(IVsHierarchy hierarchy, int added)
        {
            // If this is our project, notify it that it has been opened.
            if (hierarchy.GetProject() != null)
            {
                var oaProject = hierarchy.GetProject() as OAProject;
                if (oaProject != null && oaProject.Project is ProjectNode)
                {
                    ((ProjectNode)oaProject.Project).OnAfterProjectOpen();
                }
            }

            // If this is a new project and our project. We use here that it is only our project that will implemnet the "internal"  IBuildDependencyOnProjectContainer.
            if (added != 0 && hierarchy is IBuildDependencyUpdate)
            {
                IVsUIHierarchy uiHierarchy = hierarchy as IVsUIHierarchy;
                Debug.Assert(uiHierarchy != null, "The ProjectNode should implement IVsUIHierarchy");
                if (uiHierarchy == null)
                {
                    return(VSConstants.E_FAIL);
                }
                // Expand and select project node
                IVsUIHierarchyWindow uiWindow = UIHierarchyUtilities.GetUIHierarchyWindow(this.ServiceProvider, HierarchyNode.SolutionExplorer);
                if (uiWindow != null)
                {
                    __VSHIERARCHYITEMSTATE state;
                    uint stateAsInt;
                    if (uiWindow.GetItemState(uiHierarchy, VSConstants.VSITEMID_ROOT, (uint)__VSHIERARCHYITEMSTATE.HIS_Expanded, out stateAsInt) == VSConstants.S_OK)
                    {
                        state = (__VSHIERARCHYITEMSTATE)stateAsInt;
                        if (state != __VSHIERARCHYITEMSTATE.HIS_Expanded)
                        {
                            int hr;
                            hr = uiWindow.ExpandItem(uiHierarchy, VSConstants.VSITEMID_ROOT, EXPANDFLAGS.EXPF_ExpandParentsToShowItem);
                            if (ErrorHandler.Failed(hr))
                            {
                                Trace.WriteLine("Failed to expand project node");
                            }
                            hr = uiWindow.ExpandItem(uiHierarchy, VSConstants.VSITEMID_ROOT, EXPANDFLAGS.EXPF_SelectItem);
                            if (ErrorHandler.Failed(hr))
                            {
                                Trace.WriteLine("Failed to select project node");
                            }

                            return(hr);
                        }
                    }
                }
            }
            return(VSConstants.S_OK);
        }
Ejemplo n.º 3
0
        internal void SetActiveSession(SessionNode node)
        {
            int oldItem = _activeSession;

            if (oldItem != -1)
            {
                _window.ExpandItem(this, (uint)_activeSession, EXPANDFLAGS.EXPF_UnBoldItem);
            }

            _activeSession = _sessions.IndexOf(node);
            Debug.Assert(_activeSession != -1);

            _window.ExpandItem(this, (uint)_activeSession, EXPANDFLAGS.EXPF_BoldItem);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Sets the expanded state of the folder.
        /// </summary>
        /// <param name="expanded">Flag that indicates the expanded state of the folder.
        /// This should be 'true' for expanded and 'false' for collapsed state.</param>
        protected void SetExpanded(bool expanded)
        {
            IsExpanded = expanded;
            SetProperty((int)__VSHPROPID.VSHPROPID_Expanded, expanded);

            // If we are in automation mode then skip the ui part
            if (Utilities.IsInAutomationFunction(ProjectMgr.Site))
            {
                return;
            }

            IVsUIHierarchyWindow uiWindow = UIHierarchyUtilities.GetUIHierarchyWindow(ProjectMgr.Site, SolutionExplorer);
            int result = uiWindow.ExpandItem(ProjectMgr, ID, expanded ? EXPANDFLAGS.EXPF_ExpandFolder : EXPANDFLAGS.EXPF_CollapseFolder);

            ErrorHandler.ThrowOnFailure(result);

            // then post the expand command to the shell. Folder verification and creation will
            // happen in the setlabel code...
            IVsUIShell shell = (IVsUIShell)ProjectMgr.GetService(typeof(IVsUIShell));

            object dummy    = null;
            Guid   cmdGroup = VsMenus.guidStandardCommandSet97;

            result = shell.PostExecCommand(ref cmdGroup, (uint)(expanded ? VsCommands.Expand : VsCommands.Collapse), 0, ref dummy);
            ErrorHandler.ThrowOnFailure(result);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Expands the view of Solution Explorer to show project items.
        /// </summary>
        public virtual void ExpandView()
        {
            if (this.node == null || this.node.ProjectMgr == null || this.node.ProjectMgr.IsClosed || this.node.ProjectMgr.Site == null)
            {
                throw new InvalidOperationException();
            }

            UIThread.DoOnUIThread(delegate() {
                IVsExtensibility3 extensibility = this.Node.ProjectMgr.Site.GetService(typeof(IVsExtensibility)) as IVsExtensibility3;

                if (extensibility == null)
                {
                    throw new InvalidOperationException();
                }

                extensibility.EnterAutomationFunction();

                try
                {
                    IVsUIHierarchyWindow uiHierarchy = UIHierarchyUtilities.GetUIHierarchyWindow(this.node.ProjectMgr.Site, HierarchyNode.SolutionExplorer);
                    if (uiHierarchy == null)
                    {
                        throw new InvalidOperationException();
                    }

                    uiHierarchy.ExpandItem(node.ProjectMgr.InteropSafeIVsUIHierarchy, this.node.ID, EXPANDFLAGS.EXPF_ExpandFolder);
                }
                finally
                {
                    extensibility.ExitAutomationFunction();
                }
            });
        }
Ejemplo n.º 6
0
        private void RenameFolder(string newName)
        {
            // Do the rename (note that we only do the physical rename if the leaf name changed)
            string newPath = Path.Combine(this.Parent.VirtualNodeName, newName);

            if (String.Compare(Path.GetFileName(VirtualNodeName), newName, StringComparison.Ordinal) != 0)
            {
                this.RenameDirectory(Path.Combine(this.ProjectMgr.ProjectFolder, newPath));
            }
            this.VirtualNodeName = newPath;

            this.ItemNode.Rename(VirtualNodeName);

            // Let all children know of the new path
            for (HierarchyNode child = this.FirstChild; child != null; child = child.NextSibling)
            {
                if (!(child is FolderNode))
                {
                    child.SetEditLabel(child.Caption);
                }
                else
                {
                    FolderNode childFolderNode = (FolderNode)child;
                    childFolderNode.RenameFolder(childFolderNode.Caption);
                }
            }

            // Some of the previous operation may have changed the selection so set it back to us
            IVsUIHierarchyWindow uiWindow = UIHierarchyUtilities.GetUIHierarchyWindow(this.ProjectMgr.Site, SolutionExplorer);

            ErrorHandler.ThrowOnFailure(uiWindow.ExpandItem(this.ProjectMgr, this.ID, EXPANDFLAGS.EXPF_SelectItem));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Renames the file node for a case only change.
        /// </summary>
        /// <param name="newFileName">The new file name.</param>
        private void RenameCaseOnlyChange(string newFileName)
        {
            //Update the include for this item.
            string include = this.ItemNode.Item.UnevaluatedInclude;

            if (String.Compare(include, newFileName, StringComparison.OrdinalIgnoreCase) == 0)
            {
                this.ItemNode.Item.Xml.Include = newFileName;
            }
            else
            {
                string includeDir = Path.GetDirectoryName(include);
                this.ItemNode.Item.Xml.Include = Path.Combine(includeDir, newFileName);
            }
            this.ItemNode.RefreshProperties();

            this.ReDraw(UIHierarchyElement.Caption);
            this.RenameChildNodes(this);

            // Refresh the property browser.
            IVsUIShell shell = this.ProjectMgr.Site.GetService(typeof(SVsUIShell)) as IVsUIShell;

            Debug.Assert(shell != null, "Could not get the ui shell from the project");
            if (shell == null)
            {
                throw new InvalidOperationException();
            }

            shell.RefreshPropertyBrowser(0);

            //Select the new node in the hierarchy
            IVsUIHierarchyWindow uiWindow = UIHierarchyUtilities.GetUIHierarchyWindow(this.ProjectMgr.Site, SolutionExplorer);

            uiWindow.ExpandItem(this.ProjectMgr.InteropSafeIVsUIHierarchy, this.ID, EXPANDFLAGS.EXPF_SelectItem);
        }
        public override int OnAfterOpenProject(IVsHierarchy hierarchy, int added)
        {
            // If this is a new project and our project. We use here that it is only our project that will implement the "internal"  IBuildDependencyOnProjectContainer.
            ThreadHelper.ThrowIfNotOnUIThread();

            if (added != 0 && hierarchy is IBuildDependencyUpdate)
            {
                IVsUIHierarchy uiHierarchy = hierarchy as IVsUIHierarchy;
                Debug.Assert(uiHierarchy != null, "The ProjectNode should implement IVsUIHierarchy");
                if (uiHierarchy == null)
                {
                    return(VSConstants.E_FAIL);
                }
                // Expand and select project node
                IServiceProvider provider = (IServiceProvider)this.ServiceProvider;


                IVsUIHierarchyWindow uiWindow = UIHierarchyUtilities.GetUIHierarchyWindow(provider, HierarchyNode.SolutionExplorer);
                if (uiWindow != null)
                {
                    __VSHIERARCHYITEMSTATE state;
                    uint stateAsInt;
                    if (uiWindow.GetItemState(uiHierarchy, VSConstants.VSITEMID_ROOT, (uint)__VSHIERARCHYITEMSTATE.HIS_Expanded, out stateAsInt) == VSConstants.S_OK)
                    {
                        state = (__VSHIERARCHYITEMSTATE)stateAsInt;
                        if (state != __VSHIERARCHYITEMSTATE.HIS_Expanded)
                        {
                            int hr;
                            hr = uiWindow.ExpandItem(uiHierarchy, VSConstants.VSITEMID_ROOT, EXPANDFLAGS.EXPF_ExpandParentsToShowItem);
                            if (ErrorHandler.Failed(hr))
                            {
                                XSettings.LogMessage("Failed to expand project node");
                            }
                            hr = uiWindow.ExpandItem(uiHierarchy, VSConstants.VSITEMID_ROOT, EXPANDFLAGS.EXPF_SelectItem);
                            if (ErrorHandler.Failed(hr))
                            {
                                XSettings.LogMessage("Failed to select project node");
                            }

                            return(hr);
                        }
                    }
                }
            }
            return(VSConstants.S_OK);
        }
Ejemplo n.º 9
0
        /// <summary>
        ///  After a drop or paste, will use the dwEffects
        ///  to determine whether we need to clean up the source nodes or not. If
        ///  justCleanup is set, it only does the cleanup work.
        /// </summary>
        internal void CleanupSelectionDataObject(bool dropped, bool cut, bool moved, bool justCleanup)
        {
            if (this.ItemsDraggedOrCutOrCopied == null || this.ItemsDraggedOrCutOrCopied.Count == 0)
            {
                return;
            }

            try
            {
                IVsUIHierarchyWindow w = UIHierarchyUtilities.GetUIHierarchyWindow(this.site, HierarchyNode.SolutionExplorer);
                foreach (HierarchyNode node in this.ItemsDraggedOrCutOrCopied)
                {
                    if ((moved && (cut || dropped) && !justCleanup))
                    {
                        // do not close it if the doc is dirty or we do not own it
                        bool isDirty, isOpen, isOpenedByUs;
                        uint docCookie;
                        IVsPersistDocData ppIVsPersistDocData;
                        DocumentManager   manager = node.GetDocumentManager();

                        if (manager != null)
                        {
                            manager.GetDocInfo(out isOpen, out isDirty, out isOpenedByUs, out docCookie, out ppIVsPersistDocData);
                            if (isDirty || (isOpen && !isOpenedByUs))
                            {
                                continue;
                            }

                            // close it if opened
                            if (isOpen)
                            {
                                manager.Close(__FRAMECLOSE.FRAMECLOSE_NoSave);
                            }
                        }

                        node.Remove(true);
                    }
                    else if (w != null)
                    {
                        ErrorHandler.ThrowOnFailure(w.ExpandItem((IVsUIHierarchy)this, node.ID, EXPANDFLAGS.EXPF_UnCutHighlightItem));
                    }
                }
            }
            finally
            {
                // Now delete the memory allocated by the packaging of datasources.
                // If we just did a cut, or we are told to cleanup, then we need to free the data object. Otherwise, we leave it
                // alone so that you can continue to paste the data in new locations.
                if (moved || cut || justCleanup)
                {
                    this.ItemsDraggedOrCutOrCopied.Clear();
                    this.CleanAndFlushClipboard();
                }

                this.dataObject   = null;
                this.dropDataType = DropDataType.None;
            }
        }
Ejemplo n.º 10
0
        private static void CollapseVsHierarchyItem(VsHierarchyItem vsHierarchyItem, IVsUIHierarchyWindow vsHierarchyWindow)
        {
            if (vsHierarchyItem == null || vsHierarchyWindow == null)
            {
                return;
            }

            vsHierarchyWindow.ExpandItem(vsHierarchyItem.UIHierarchy(), vsHierarchyItem.VsItemID, EXPANDFLAGS.EXPF_CollapseFolder);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Makes sure the node is visible in the Solution Explorer by expanding all of it's parents.
        /// </summary>
        public void EnsureVisible()
        {
            // Get the Solution Explorer window.
            IVsUIHierarchyWindow solutionExplorer = Package.Instance.Context.SolutionExplorer;

            // Make sure the node is visible by expanding all of its parents.
            EXPANDFLAGS flags = EXPANDFLAGS.EXPF_ExpandParentsToShowItem;

            NativeMethods.ThrowOnFailure(solutionExplorer.ExpandItem(this.Hierarchy, this.HierarchyId, flags));
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Expands the current node.
        /// </summary>
        public void Expand()
        {
            // Get the Solution Explorer window.
            IVsUIHierarchyWindow solutionExplorer = Package.Instance.Context.SolutionExplorer;

            // Expand or collapse the node in the Solution Explorer.
            EXPANDFLAGS flags = EXPANDFLAGS.EXPF_ExpandFolder;

            NativeMethods.ThrowOnFailure(solutionExplorer.ExpandItem(this.Hierarchy, this.HierarchyId, flags));
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Performs the EXPANDFLAGS action on a node with nodeID.
        /// </summary>
        internal static void ManipulateNode(ProjectNode project, uint nodeID, EXPANDFLAGS flag)
        {
            IVsUIHierarchyWindow uiHierarchy = VsShellUtilities.GetUIHierarchyWindow(project.Site, HierarchyNode.SolutionExplorer);

            if (uiHierarchy == null)
            {
                return;
            }

            uiHierarchy.ExpandItem(project, nodeID, flag);
        }
Ejemplo n.º 14
0
        private static void CollapseVsHierarchyItem(VsHierarchyItem vsHierarchyItem, IVsUIHierarchyWindow vsHierarchyWindow)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            if (vsHierarchyItem == null ||
                vsHierarchyWindow == null)
            {
                return;
            }

            vsHierarchyWindow.ExpandItem(AsVsUIHierarchy(vsHierarchyItem), vsHierarchyItem.VsItemID, EXPANDFLAGS.EXPF_CollapseFolder);
        }
Ejemplo n.º 15
0
        private static void CollapseVsHierarchyItem(VsHierarchyItem vsHierarchyItem, IVsUIHierarchyWindow vsHierarchyWindow)
        {
            Debug.Assert(ThreadHelper.CheckAccess());

            if (vsHierarchyItem == null ||
                vsHierarchyWindow == null)
            {
                return;
            }

            vsHierarchyWindow.ExpandItem(vsHierarchyItem.UIHierarchy(), vsHierarchyItem.VsItemID, EXPANDFLAGS.EXPF_CollapseFolder);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Expands the view of Solution Explorer to show project items.
        /// </summary>
        public virtual void ExpandView()
        {
            CheckProjectIsValid();

            using (AutomationScope scope = new AutomationScope(this.Node.ProjectMgr.Site))
            {
                IVsUIHierarchyWindow uiHierarchy = UIHierarchyUtilities.GetUIHierarchyWindow(this.node.ProjectMgr.Site, HierarchyNode.SolutionExplorer);
                Utilities.CheckNotNull(uiHierarchy);

                ErrorHandler.ThrowOnFailure(uiHierarchy.ExpandItem(this.node.ProjectMgr, this.node.ID, EXPANDFLAGS.EXPF_ExpandFolder));
            }
        }
Ejemplo n.º 17
0
        private static async Task CollapseVsHierarchyItemAsync(VsHierarchyItem vsHierarchyItem, IVsUIHierarchyWindow vsHierarchyWindow)
        {
            if (vsHierarchyItem == null ||
                vsHierarchyWindow == null)
            {
                return;
            }

            await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            vsHierarchyWindow.ExpandItem(AsVsUIHierarchy(vsHierarchyItem), vsHierarchyItem.VsItemID, EXPANDFLAGS.EXPF_CollapseFolder);
        }
Ejemplo n.º 18
0
        private void RenameFolder(string newName)
        {
            string newPath     = Path.Combine(this.Parent.VirtualNodeName, newName);
            string newFullPath = Path.Combine(this.ProjectMgr.ProjectFolder, newPath);

            // Only do the physical rename if the leaf name changed
            if (String.Compare(Path.GetFileName(VirtualNodeName), newName, StringComparison.Ordinal) != 0)
            {
                // Verify that no directory/file already exists with the new name on disk.
                // If it does, just subsume that name if our directory is empty.
                if (Directory.Exists(newFullPath) || FSLib.Shim.FileSystem.SafeExists(newFullPath))
                {
                    // We can't delete our old directory as it is not empty
                    if (Directory.EnumerateFileSystemEntries(this.Url).Any())
                    {
                        ShowErrorMessage(SR.FolderCannotBeRenamed, newPath);
                        return;
                    }

                    // Try to delete the old (empty) directory.
                    // Note that we don't want to delete recursively in case a file was added between
                    // when we checked and when we went to delete (potential race condition).
                    Directory.Delete(this.Url, false);
                }
                else
                {
                    this.RenameDirectory(newFullPath);
                }
            }

            this.VirtualNodeName = newPath;

            this.ItemNode.Rename(VirtualNodeName);

            // Let all children know of the new path
            for (HierarchyNode child = this.FirstChild; child != null; child = child.NextSibling)
            {
                if (!(child is FolderNode))
                {
                    child.SetEditLabel(child.Caption);
                }
                else
                {
                    FolderNode childFolderNode = (FolderNode)child;
                    childFolderNode.RenameFolder(childFolderNode.Caption);
                }
            }

            // Some of the previous operation may have changed the selection so set it back to us
            IVsUIHierarchyWindow uiWindow = UIHierarchyUtilities.GetUIHierarchyWindow(this.ProjectMgr.Site, SolutionExplorer);

            ErrorHandler.ThrowOnFailure(uiWindow.ExpandItem(this.ProjectMgr.InteropSafeIVsUIHierarchy, this.ID, EXPANDFLAGS.EXPF_SelectItem));
        }
Ejemplo n.º 19
0
 // --------------------------------------------------------------------------------------------
 /// <summary>
 /// Expands the specified hierarchy item.
 /// </summary>
 /// <param name="window">The hierarchy window hosting the item.</param>
 /// <param name="node">The hierarchy of the node to expand.</param>
 /// <param name="id">The id of the node.</param>
 /// <param name="flags">Flags specifying how to expand the node.</param>
 // --------------------------------------------------------------------------------------------
 private static void ExpandItem(IVsUIHierarchyWindow window, IVsUIHierarchy node, uint id,
                                EXPANDFLAGS flags)
 {
     if (window == null)
     {
         return;
     }
     if (node == null)
     {
         throw new ArgumentNullException("node");
     }
     ErrorHandler.ThrowOnFailure(window.ExpandItem(node, id, flags));
 }
Ejemplo n.º 20
0
        private void CollapseHierarchyItems(IVsUIHierarchyWindow toolWindow, IVsHierarchy hierarchy, uint itemid, bool hierIsSolution
                                            , string[] captions)
        {
            IntPtr ptr;
            uint   num2;
            Guid   gUID = typeof(IVsHierarchy).GUID;

            if ((hierarchy.GetNestedHierarchy(itemid, ref gUID, out ptr, out num2) == 0) && (IntPtr.Zero != ptr))
            {
                IVsHierarchy objectForIUnknown = Marshal.GetObjectForIUnknown(ptr) as IVsHierarchy;
                Marshal.Release(ptr);
                if (objectForIUnknown != null)
                {
                    this.CollapseHierarchyItems(toolWindow, objectForIUnknown, num2, false, captions);
                }
            }
            else
            {
                object obj2;
                if (!hierIsSolution)
                {
                    string canonicalname;
                    object captionobj;
                    hierarchy.GetProperty(itemid, (int)__VSHPROPID.VSHPROPID_Caption, out captionobj);
                    var caption = (string)captionobj;
                    if (captions.Contains(caption))
                    {
                        hierarchy.GetCanonicalName(itemid, out canonicalname);
                        ErrorHandler.ThrowOnFailure(toolWindow.ExpandItem(hierarchy as IVsUIHierarchy, itemid, EXPANDFLAGS.EXPF_CollapseFolder));
                    }
                }
                if (hierarchy.GetProperty(itemid, (int)__VSHPROPID.VSHPROPID_FirstVisibleChild, out obj2) == 0)
                {
                    uint itemId = this.GetItemId(obj2);
                    while (itemId != uint.MaxValue)
                    {
                        this.CollapseHierarchyItems(toolWindow, hierarchy, itemId, false, captions);
                        int hr = hierarchy.GetProperty(itemId, (int)__VSHPROPID.VSHPROPID_NextVisibleSibling, out obj2);
                        if (hr == 0)
                        {
                            itemId = this.GetItemId(obj2);
                        }
                        else
                        {
                            ErrorHandler.ThrowOnFailure(hr);
                            return;
                        }
                    }
                }
            }
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Refreshes the solution explorer tree
        /// </summary>
        /// <param name="nodes">A list of nodes which were originally selected</param>
        /// <remarks>
        /// Refreshing the tree cancels the selection, the nodes list is used to restore the
        /// selection. The items on the list could have been changed/ recreated as a side
        /// effect of the operation, so the list of the nodes is re-mapped
        /// </remarks>
        public void RefreshSolutionExplorer(IEnumerable <ItemNode> nodes)
        {
            projectProxy.RefreshSolutionExplorer();

            bool first = true;
            IVsUIHierarchyWindow explorer = GlobalServices.SolutionExplorer;

            if (explorer != null)
            {
                foreach (var node in itemList.RemapNodes(nodes))
                {
                    if (first)
                    {
                        explorer.ExpandItem(this, node.ItemId, EXPANDFLAGS.EXPF_SelectItem);
                        first = false;
                    }
                    else
                    {
                        explorer.ExpandItem(this, node.ItemId, EXPANDFLAGS.EXPF_AddSelectItem);
                    }
                }
            }
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Called by the shell when a node has been renamed from the GUI
        /// </summary>
        /// <param name="label"></param>
        /// <returns>E_NOTIMPL</returns>
        public override int SetEditLabel(string label)
        {
            HierarchyNode thisParentNode = this.Parent;

            this.ReferencedProjectName = label;
            this.OnInvalidateItems(thisParentNode);

            // select the reference node again
            IVsUIHierarchyWindow uiWindow = UIHierarchyUtilities.GetUIHierarchyWindow(this.ProjectMgr.Site, SolutionExplorer);

            uiWindow.ExpandItem(this.ProjectMgr, this.ID, EXPANDFLAGS.EXPF_SelectItem);

            return(VSConstants.S_OK);
        }
Ejemplo n.º 23
0
 private void CollapseHierarchyItems(IVsUIHierarchyWindow toolWindow, IVsHierarchy hierarchy, uint itemid, bool hierIsSolution
     , string[] captions)
 {
     IntPtr ptr;
     uint num2;
     Guid gUID = typeof(IVsHierarchy).GUID;
     if ((hierarchy.GetNestedHierarchy(itemid, ref gUID, out ptr, out num2) == 0) && (IntPtr.Zero != ptr))
     {
         IVsHierarchy objectForIUnknown = Marshal.GetObjectForIUnknown(ptr) as IVsHierarchy;
         Marshal.Release(ptr);
         if (objectForIUnknown != null)
         {
             this.CollapseHierarchyItems(toolWindow, objectForIUnknown, num2, false, captions);
         }
     }
     else
     {
         object obj2;
         if (!hierIsSolution)
         {
             string canonicalname;
             object captionobj;
             hierarchy.GetProperty(itemid, (int)__VSHPROPID.VSHPROPID_Caption, out captionobj);
             var caption = (string)captionobj;
             if (captions.Contains(caption))
             {
                 hierarchy.GetCanonicalName(itemid, out canonicalname);
                 ErrorHandler.ThrowOnFailure(toolWindow.ExpandItem(hierarchy as IVsUIHierarchy, itemid, EXPANDFLAGS.EXPF_CollapseFolder));
             }
         }
         if (hierarchy.GetProperty(itemid, (int)__VSHPROPID.VSHPROPID_FirstVisibleChild, out obj2) == 0)
         {
             uint itemId = this.GetItemId(obj2);
             while (itemId != uint.MaxValue)
             {
                 this.CollapseHierarchyItems(toolWindow, hierarchy, itemId, false, captions);
                 int hr = hierarchy.GetProperty(itemId, (int)__VSHPROPID.VSHPROPID_NextVisibleSibling, out obj2);
                 if (hr == 0)
                 {
                     itemId = this.GetItemId(obj2);
                 }
                 else
                 {
                     ErrorHandler.ThrowOnFailure(hr);
                     return;
                 }
             }
         }
     }
 }
Ejemplo n.º 24
0
        /// <summary>
        /// Expands the view of Solution Explorer to show project items.
        /// </summary>
        public virtual void ExpandView()
        {
            CheckProjectIsValid();

            ThreadHelper.JoinableTaskFactory.Run(async delegate
            {
                await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
                using (new AutomationScope(this.Node.ProjectMgr.Site))
                {
                    IVsUIHierarchyWindow uiHierarchy = UIHierarchyUtilities.GetUIHierarchyWindow(this.node.ProjectMgr.Site, HierarchyNode.SolutionExplorer);

                    ErrorHandler.ThrowOnFailure(uiHierarchy.ExpandItem(this.node.ProjectMgr, this.node.ID, EXPANDFLAGS.EXPF_ExpandFolder));
                }
            });
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Tells the Solution Explorer to allow the user to start editing the node.
        /// </summary>
        public void StartNodeEdit()
        {
            // Get the Solution Explorer window.
            IVsUIHierarchyWindow solutionExplorer = Package.Instance.Context.SolutionExplorer;

            // Once we have the new name, we'll go into edit label mode on the node. Checks for
            // validity will happen in the SetCaption method.

            // First make sure the node is visible.
            this.EnsureVisible();

            // Select the node in the Solution Explorer.
            this.Select();

            // Edit the node's caption.
            NativeMethods.ThrowOnFailure(solutionExplorer.ExpandItem(this.Hierarchy, this.HierarchyId, EXPANDFLAGS.EXPF_EditItemLabel));
        }
Ejemplo n.º 26
0
        private void RenameFolder(string newName)
        {
            // Do the rename (note that we only do the physical rename if the leaf name changed)
            string newPath = Path.Combine(this.Parent.VirtualNodeName, newName);

            if (String.Compare(Path.GetFileName(VirtualNodeName), newName, StringComparison.Ordinal) != 0)
            {
                this.RenameDirectory(Path.Combine(this.ProjectMgr.ProjectFolder, newPath));
            }
            this.VirtualNodeName = newPath;

            this.ItemNode.Rename(VirtualNodeName);
            ThreadHelper.ThrowIfNotOnUIThread();

            // Let all children know of the new path
            for (HierarchyNode child = this.FirstChild; child != null; child = child.NextSibling)
            {
                FileNode childFileNode = child as FileNode;
                if (childFileNode != null && childFileNode.IsLink)
                {
                    string linkPath = Path.Combine(newPath, child.Caption);
                    childFileNode.RenameFileNode(child.Url, child.Url, linkPath, this.ID);
                }
                else if (!(child is FolderNode))
                {
                    child.SetEditLabel(child.Caption);
                }
                else
                {
                    FolderNode childFolderNode = (FolderNode)child;
                    childFolderNode.RenameFolder(childFolderNode.Caption);
                }
            }

            // Some of the previous operation may have changed the selection so set it back to us
            IVsUIHierarchyWindow uiWindow = UIHierarchyUtilities.GetUIHierarchyWindow(this.ProjectMgr.Site, SolutionExplorer);

            // This happens in the context of renaming a folder.
            // Since we are already in solution explorer, it is extremely unlikely that we get a null return.
            // If we do, the consequences are minimal: the parent node will be selected instead of the
            // renamed node.
            if (uiWindow != null)
            {
                ErrorHandler.ThrowOnFailure(uiWindow.ExpandItem(this.ProjectMgr, this.ID, EXPANDFLAGS.EXPF_SelectItem));
            }
        }
Ejemplo n.º 27
0
        /// <summary>
        /// Expands the view of Solution Explorer to show project items.
        /// </summary>
        public virtual void ExpandView()
        {
            if (this.node == null || this.node.ProjectMgr == null || this.node.ProjectMgr.IsClosed || this.node.ProjectMgr.Site == null)
            {
                throw new InvalidOperationException();
            }

            using (AutomationScope scope = new AutomationScope(this.Node.ProjectMgr.Site))
            {
                IVsUIHierarchyWindow uiHierarchy = UIHierarchyUtilities.GetUIHierarchyWindow(this.node.ProjectMgr.Site, HierarchyNode.SolutionExplorer);
                if (uiHierarchy == null)
                {
                    throw new InvalidOperationException();
                }

                ErrorHandler.ThrowOnFailure(uiHierarchy.ExpandItem(this.node.ProjectMgr, this.node.ID, EXPANDFLAGS.EXPF_ExpandFolder));
            }
        }
Ejemplo n.º 28
0
        /// <summary>
        /// Expands the view of Solution Explorer to show project items.
        /// </summary>
        public virtual void ExpandView()
        {
            CheckProjectIsValid();

            UIThread.DoOnUIThread(delegate()
            {
                using (AutomationScope scope = new AutomationScope(this.Node.ProjectMgr.Site))
                {
                    IVsUIHierarchyWindow uiHierarchy = UIHierarchyUtilities.GetUIHierarchyWindow(this.node.ProjectMgr.Site, HierarchyNode.SolutionExplorer);
                    if (uiHierarchy == null)
                    {
                        throw new InvalidOperationException();
                    }

                    ErrorHandler.ThrowOnFailure(uiHierarchy.ExpandItem(this.node.ProjectMgr, this.node.ID, EXPANDFLAGS.EXPF_ExpandFolder));
                }
            });
        }
Ejemplo n.º 29
0
        protected virtual void RenameFolder(string newName)
        {
            // Do the rename (note that we only do the physical rename if the leaf name changed)
            string newPath = Path.Combine(this.Parent.VirtualNodeName, newName);

            if (!String.Equals(Path.GetFileName(VirtualNodeName), newName, StringComparison.Ordinal))
            {
                this.RenameDirectory(Path.Combine(this.ProjectManager.ProjectFolder, newPath));
            }
            this.VirtualNodeName = newPath;

            this.ItemNode.Rename(VirtualNodeName);

            // Let all children know of the new path
            for (HierarchyNode child = this.FirstChild; child != null; child = child.NextSibling)
            {
                FolderNode node = child as FolderNode;

                if (node == null)
                {
                    child.SetEditLabel(child.Caption);
                }
                else
                {
                    node.RenameFolder(node.Caption);
                }
            }

            // Some of the previous operation may have changed the selection so set it back to us
            IVsUIHierarchyWindow uiWindow = UIHierarchyUtilities.GetUIHierarchyWindow(this.ProjectManager.Site, SolutionExplorer);

            // This happens in the context of renaming a folder.
            // Since we are already in solution explorer, it is extremely unlikely that we get a null return.
            // If we do, the consequences are minimal: the parent node will be selected instead of the
            // renamed node.
            if (uiWindow != null)
            {
                ErrorHandler.ThrowOnFailure(uiWindow.ExpandItem(this.ProjectManager.InteropSafeIVsUIHierarchy, this.Id, EXPANDFLAGS.EXPF_SelectItem));
            }

            ProjectManager.ItemIdMap.UpdateCanonicalName(this);
        }
Ejemplo n.º 30
0
        /// <summary>
        /// Selects all nodes of type T in the project.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="project"></param>
        /// <returns>The id's of the selected nodes.</returns>
        internal static T SelectAnyNodeOfType <T>(ProjectNode project)
            where T : HierarchyNode
        {
            IVsUIHierarchyWindow uiHierarchy = VsShellUtilities.GetUIHierarchyWindow(project.Site, HierarchyNode.SolutionExplorer);

            if (uiHierarchy == null)
            {
                return(null);
            }

            List <T> nodes = GetNodesOfType <T>(project);

            if (nodes.Count > 0)
            {
                uiHierarchy.ExpandItem(project, nodes[0].Id, EXPANDFLAGS.EXPF_SelectItem);
                return(nodes[0]);
            }

            return(null);
        }
Ejemplo n.º 31
0
        /// <summary>
        /// Renames the file node for a case only change.
        /// </summary>
        /// <param name="newFileName">The new file name.</param>
        private void RenameCaseOnlyChange(string newFileName)
        {
            //Update the include for this item.
            string include = this.ItemNode.Item.EvaluatedInclude;

            if (String.Compare(include, newFileName, StringComparison.OrdinalIgnoreCase) == 0)
            {
                this.ItemNode.Item.Xml.Include = newFileName;
            }
            else
            {
                string includeDir = Path.GetDirectoryName(include);
                this.ItemNode.Item.Xml.Include = Path.Combine(includeDir, newFileName);
            }

            this.ItemNode.RefreshProperties();

            this.ReDraw(UIHierarchyElement.Caption);
            this.RenameChildNodes(this);

            // Refresh the property browser.
            IVsUIShell shell = this.ProjectMgr.Site.GetService(typeof(SVsUIShell)) as IVsUIShell;

            Debug.Assert(shell != null, "Could not get the ui shell from the project");
            if (shell == null)
            {
                throw new InvalidOperationException();
            }

            ErrorHandler.ThrowOnFailure(shell.RefreshPropertyBrowser(0));

            //Select the new node in the hierarchy
            IVsUIHierarchyWindow uiWindow = UIHierarchyUtilities.GetUIHierarchyWindow(this.ProjectMgr.Site, SolutionExplorer);

            // This happens in the context of renaming a file by case only (Table.sql -> table.sql)
            // Since we are already in solution explorer, it is extremely unlikely that we get a null return.
            if (uiWindow != null)
            {
                ErrorHandler.ThrowOnFailure(uiWindow.ExpandItem(this.ProjectMgr, this.ID, EXPANDFLAGS.EXPF_SelectItem));
            }
        }
Ejemplo n.º 32
0
 // --------------------------------------------------------------------------------------------
 /// <summary>
 /// Expands the specified hierarchy item.
 /// </summary>
 /// <param name="window">The hierarchy window hosting the item.</param>
 /// <param name="node">The hierarchy of the node to expand.</param>
 /// <param name="id">The id of the node.</param>
 /// <param name="flags">Flags specifying how to expand the node.</param>
 // --------------------------------------------------------------------------------------------
 private static void ExpandItem(IVsUIHierarchyWindow window, IVsUIHierarchy node, uint id, 
     EXPANDFLAGS flags)
 {
     if (window == null) return;
       if (node == null) throw new ArgumentNullException("node");
       ErrorHandler.ThrowOnFailure(window.ExpandItem(node, id, flags));
 }
Ejemplo n.º 33
0
        private static void CollapseVsHierarchyItem(VsHierarchyItem vsHierarchyItem, IVsUIHierarchyWindow vsHierarchyWindow)
        {
            if (vsHierarchyItem == null || vsHierarchyWindow == null)
            {
                return;
            }

            vsHierarchyWindow.ExpandItem(vsHierarchyItem.UIHierarchy(), vsHierarchyItem.VsItemID, EXPANDFLAGS.EXPF_CollapseFolder);
        }