コード例 #1
0
        /// <summary>
        /// 折叠全部
        /// </summary>
        public void CollapseAll()
        {
            List <UIHierarchyItem> itemNodes = this.GetProjectNodes();

            if (itemNodes != null && itemNodes.Count > 0)
            {
                for (int i = 0; i < itemNodes.Count; i++)
                {
                    Project proj = itemNodes[i].Object as Project;
                    //项目为非顶级项目
                    if (proj == null)
                    {
                        ProjectItem projItem = itemNodes[i].Object as ProjectItem;
                        if (projItem != null && itemNodes[i].UIHierarchyItems.Expanded)
                        {
                            itemNodes[i].Select(vsUISelectionType.vsUISelectionTypeSelect);
                            _rootNode.DoDefaultAction();
                        }
                    }
                    else
                    {
                        //项目为顶级项目
                        itemNodes[i].UIHierarchyItems.Expanded = false;
                    }
                }
            }
            //折叠顶级项目
            string           solutionName = _app.Solution.Properties.Item("Name").Value.ToString();
            UIHierarchyItems items        = _rootNode.GetItem(solutionName).UIHierarchyItems;

            foreach (UIHierarchyItem topItem in items)
            {
                topItem.UIHierarchyItems.Expanded = false;
            }
        }
コード例 #2
0
        public static void Collapse(this UIHierarchyItem item, UIHierarchy solutionExplorer, IEnumerable <string> exlusionList = null)
        {
            foreach (UIHierarchyItem innerItem in item.UIHierarchyItems)
            {
                if (innerItem.UIHierarchyItems.Count > 0)
                {
                    // Recursive call
                    Collapse(innerItem, solutionExplorer);

                    // skip project folders
                    if (exlusionList != null && exlusionList.Any(e => e == innerItem.Name))
                    {
                        continue;
                    }

                    // Collapse
                    if (innerItem.UIHierarchyItems.Expanded)
                    {
                        innerItem.UIHierarchyItems.Expanded = false;
                        if (innerItem.UIHierarchyItems.Expanded)
                        {
                            innerItem.Select(vsUISelectionType.vsUISelectionTypeSelect);
                            solutionExplorer.DoDefaultAction();
                        }
                    }
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// 展开全部
        /// </summary>
        public static void ExpandAll()
        {
            _dte      = SolutionCommon.Dte as DTE2;
            _rootNode = _dte.ToolWindows.SolutionExplorer;
            //加载所有的项目
            LoadAllProjectNodes();

            List <UIHierarchyItem> itemNodes = GetProjectNodes();

            if (itemNodes != null && itemNodes.Count > 0)
            {
                for (int i = 0; i < itemNodes.Count; i++)
                {
                    Project proj = itemNodes[i].Object as Project;
                    //项目为非顶级项目
                    if (proj == null)
                    {
                        ProjectItem projItem = itemNodes[i].Object as ProjectItem;
                        if (projItem != null && itemNodes[i].UIHierarchyItems.Expanded == false)
                        {
                            itemNodes[i].Select(vsUISelectionType.vsUISelectionTypeSelect);
                            _rootNode.DoDefaultAction();
                        }
                    }
                    else
                    {
                        //项目为顶级项目
                        itemNodes[i].UIHierarchyItems.Expanded = true;
                    }
                }
            }
        }
コード例 #4
0
        private void ExpandCollapseNodes(UIHierarchyItem node, bool expanded, UIHierarchy tree)
        {
            foreach (UIHierarchyItem subNode in node.UIHierarchyItems)
            {
                ExpandCollapseNodes(subNode, expanded, tree);
            }

            if (node.Object is SolutionFolder)
            {
                node.UIHierarchyItems.Expanded = true;
            }
            else if (node.Object is Solution)
            {
                node.UIHierarchyItems.Expanded = true;
            }
            else if (node.Object is Project)
            {
                if (((Project)node.Object).Object is SolutionFolder)
                {
                    //are there projects in the solution folder
                    SolutionFolder f        = ((Project)node.Object).Object as SolutionFolder;
                    bool           expandit = false;
                    foreach (ProjectItem pi in f.Parent.ProjectItems)
                    {
                        if (pi.Object is Project)
                        {
                            //solutionfolder contains a child project, dont close
                            expandit = true;
                        }
                    }
                    node.UIHierarchyItems.Expanded = expandit;
                }
                else
                {
                    node.UIHierarchyItems.Expanded = false;
                }
            }
            else
            {
                node.UIHierarchyItems.Expanded = false;
                //bug in VS
                //if still expanded
                if (node.UIHierarchyItems.Expanded == true)
                {
                    node.Select(vsUISelectionType.vsUISelectionTypeSelect);
                    tree.DoDefaultAction();
                }
            }
        }
コード例 #5
0
        internal UIHierarchyItem FindHierarchyItem(UIHierarchyItems items, object item)
        {
            //
            // Enumerating children recursive would work, but it may be slow on large solution.
            // This tries to be smarter and faster
            //

            Stack s = new Stack();

            CreateItemsStack(s, item);

            UIHierarchyItem last = null;

            while (s.Count != 0)
            {
                if (!items.Expanded)
                {
                    items.Expanded = true;
                }
                if (!items.Expanded)
                {
                    //bug: expand dont always work...
                    UIHierarchyItem parent = ((UIHierarchyItem)items.Parent);
                    parent.Select(vsUISelectionType.vsUISelectionTypeSelect);

                    UIHierarchy tree = items.DTE.Windows.Item(EnvDTE.Constants.vsWindowKindSolutionExplorer).Object as UIHierarchy;
                    tree.DoDefaultAction();
                    //_DTE.ToolWindows.SolutionExplorer.DoDefaultAction();
                }

                object o = s.Pop();

                last = null;
                foreach (UIHierarchyItem child in items)
                {
                    if (child.Object == o)
                    {
                        last  = child;
                        items = child.UIHierarchyItems;
                        break;
                    }
                }
            }

            return(last);
        }
コード例 #6
0
        private void ExpandItems(UIHierarchyItems items)
        {
            if (!items.Expanded)
            {
                items.Expanded = true;
            }
            if (!items.Expanded)
            {
                //bug: expand dont always work...
                UIHierarchyItem parent = ((UIHierarchyItem)items.Parent);
                parent.Select(vsUISelectionType.vsUISelectionTypeSelect);

                UIHierarchy tree = items.DTE.Windows.Item(EnvDTE.Constants.vsWindowKindSolutionExplorer).Object as UIHierarchy;
                tree.DoDefaultAction();
                //_DTE.ToolWindows.SolutionExplorer.DoDefaultAction();
            }
        }
コード例 #7
0
 /// <summary>
 /// The Collapse.
 /// </summary>
 /// <param name="item">The item<see cref="UIHierarchyItem"/>.</param>
 /// <param name="solutionExplorer">The solutionExplorer<see cref="UIHierarchy"/>.</param>
 public void Collapse(UIHierarchyItem item, ref UIHierarchy solutionExplorer)
 {
     foreach (UIHierarchyItem innerItem in item.UIHierarchyItems)
     {
         if (innerItem.UIHierarchyItems.Count > 0)
         {
             Collapse(innerItem, ref solutionExplorer);
             if (innerItem.UIHierarchyItems.Expanded)
             {
                 innerItem.UIHierarchyItems.Expanded = false;
                 if (innerItem.UIHierarchyItems.Expanded)
                 {
                     innerItem.Select(vsUISelectionType.vsUISelectionTypeSelect);
                     solutionExplorer.DoDefaultAction();
                 }
             }
         }
     }
 }
コード例 #8
0
        /// <summary>
        /// 折叠全部项目
        /// </summary>
        /// <param name="sln">解决方案COM</param>
        public static void CollapseAllProject(this Solution sln)
        {
            UIHierarchy rootNode = (sln.DTE as DTE2).ToolWindows.SolutionExplorer;

            List <UIHierarchyItem> itemNodes = GetProjectNodes(sln);

            if (itemNodes != null && itemNodes.Count > 0)
            {
                for (int i = 0; i < itemNodes.Count; i++)
                {
                    Project proj = itemNodes[i].Object as Project;
                    //项目为非顶级项目
                    if (proj == null)
                    {
                        ProjectItem projItem = itemNodes[i].Object as ProjectItem;
                        if (projItem != null && itemNodes[i].UIHierarchyItems.Expanded)
                        {
                            itemNodes[i].Select(vsUISelectionType.vsUISelectionTypeSelect);
                            rootNode.DoDefaultAction();
                        }
                    }
                    else
                    {
                        //项目为顶级项目
                        itemNodes[i].UIHierarchyItems.Expanded = false;
                    }
                }
            }
            //折叠顶级项目
            string           solutionName = sln.Properties.Item("Name").Value.ToString();
            UIHierarchyItems items        = rootNode.GetItem(solutionName).UIHierarchyItems;

            foreach (UIHierarchyItem topItem in items)
            {
                topItem.UIHierarchyItems.Expanded = false;
            }
        }
コード例 #9
0
        public static void CollapseFilter(UIHierarchyItem item, UIHierarchy hierarchy)
        {
            UIHierarchyItems subItems = item.UIHierarchyItems;
            if (subItems != null)
            {
                foreach (UIHierarchyItem innerItem in subItems)
                {
                    if (innerItem.UIHierarchyItems.Count > 0)
                    {
                        CollapseFilter(innerItem, hierarchy);

                        if (innerItem.UIHierarchyItems.Expanded)
                        {
                            innerItem.UIHierarchyItems.Expanded = false;
                            if (innerItem.UIHierarchyItems.Expanded == true)
                            {
                                innerItem.Select(vsUISelectionType.vsUISelectionTypeSelect);
                                hierarchy.DoDefaultAction();
                            }
                        }
                    }
                }
            }
            if (item.UIHierarchyItems.Expanded)
            {
                item.UIHierarchyItems.Expanded = false;
                if (item.UIHierarchyItems.Expanded == true)
                {
                    item.Select(vsUISelectionType.vsUISelectionTypeSelect);
                    hierarchy.DoDefaultAction();
                }
            }
        }
        private void ExpandCollapseNodes(UIHierarchyItem node, bool expanded, UIHierarchy tree)
        {
            foreach(UIHierarchyItem subNode in node.UIHierarchyItems)
              {
            ExpandCollapseNodes(subNode, expanded, tree);
              }

              if (node.Object is SolutionFolder)
              {
            node.UIHierarchyItems.Expanded = true;
              }
              else if (node.Object is Solution)
              {
            node.UIHierarchyItems.Expanded = true;
              }
              else if (node.Object is Project)
              {
            if (((Project)node.Object).Object is SolutionFolder)
            {
              //are there projects in the solution folder
              SolutionFolder f = ((Project)node.Object).Object as SolutionFolder;
              bool expandit = false;
              foreach (ProjectItem pi in f.Parent.ProjectItems)
              {
                if (pi.Object is Project)
                {
                  //solutionfolder contains a child project, dont close
                  expandit = true;
                }
              }
              node.UIHierarchyItems.Expanded = expandit;
            }
            else
            {
              node.UIHierarchyItems.Expanded = false;
            }
              }
              else
              {
            node.UIHierarchyItems.Expanded = false;
            //bug in VS
            //if still expanded
            if (node.UIHierarchyItems.Expanded == true)
            {
              node.Select(vsUISelectionType.vsUISelectionTypeSelect);
              tree.DoDefaultAction();
            }
              }
        }
コード例 #11
0
ファイル: Helper.cs プロジェクト: nostlie/Sandbox
        private static void Collapse(UIHierarchyItem item, ref UIHierarchy solutionExplorer)
        {
            foreach (UIHierarchyItem innerItem in item.UIHierarchyItems)
            {
                if (innerItem.UIHierarchyItems.Count > 0)
                {

                    // Re-cursive call
                    Collapse(innerItem, ref solutionExplorer);

                    // Collapse
                    if (innerItem.UIHierarchyItems.Expanded)
                    {
                        innerItem.UIHierarchyItems.Expanded = false;
                        if (innerItem.UIHierarchyItems.Expanded == true)
                        {
                            // Bug in VS 2005
                            innerItem.Select(vsUISelectionType.vsUISelectionTypeSelect);
                            solutionExplorer.DoDefaultAction();
                        }

                    }
                }

            }
        }