Exemple #1
0
        private static TreeNode FindNode(TreeNodeCollection nodeCollectionToSearch, string nodeText)
        {
            var nodesToSearch = nodeCollectionToSearch.Cast <TreeNode>();
            var foundNode     = nodesToSearch.FirstOrDefault(n => n.Text == nodeText);

            return(foundNode);
        }
Exemple #2
0
        public static void ExportSplitObjects(string savePath, TreeNodeCollection nodes)
        {
            ThreadPool.QueueUserWorkItem(state =>
            {
                var count = nodes.Cast <TreeNode>().Sum(x => x.Nodes.Count);
                int k     = 0;
                Progress.Reset();
                foreach (GameObjectTreeNode node in nodes)
                {
                    //遍历一级子节点
                    foreach (GameObjectTreeNode j in node.Nodes)
                    {
                        //收集所有子节点
                        var gameObjects = new List <GameObject>();
                        CollectNode(j, gameObjects);
                        //跳过一些不需要导出的object
                        if (gameObjects.All(x => x.m_SkinnedMeshRenderer == null && x.m_MeshFilter == null))
                        {
                            Progress.Report(++k, count);
                            continue;
                        }
                        //处理非法文件名
                        var filename = FixFileName(j.Text);
                        //每个文件存放在单独的文件夹
                        var targetPath = $"{savePath}{filename}\\";
                        //重名文件处理
                        for (int i = 1; ; i++)
                        {
                            if (Directory.Exists(targetPath))
                            {
                                targetPath = $"{savePath}{filename} ({i})\\";
                            }
                            else
                            {
                                break;
                            }
                        }
                        Directory.CreateDirectory(targetPath);
                        //导出FBX
                        StatusStripUpdate($"Exporting {filename}.fbx");
                        try
                        {
                            ExportGameObject(j.gameObject, targetPath);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show($"Export GameObject:{j.Text} error\r\n{ex.Message}\r\n{ex.StackTrace}");
                        }

                        Progress.Report(++k, count);
                        StatusStripUpdate($"Finished exporting {filename}.fbx");
                    }
                }
                if (Properties.Settings.Default.openAfterExport)
                {
                    Process.Start(savePath);
                }
                StatusStripUpdate("Finished");
            });
        }
        public static TreeNode AddRootNode(this TreeNodeCollection treeNodeCollection, string value)
        {
            var rootNode = new TreeNode(value);

            treeNodeCollection.Add(new TreeNode(value));
            return(treeNodeCollection.Cast <TreeNode>().Where(x => x.Text == value).FirstOrDefault());
        }
        public void MoveDown()
        {
            var selectedCategory = GetSelectedAchievementCategory();

            var node = tvwAchievementCategories.SelectedNode.Parent;
            TreeNodeCollection nodes = null;

            if (node != null && node.Nodes != null)
            {
                nodes = node.Nodes;
            }
            else
            {
                nodes = tvwAchievementCategories.Nodes;
            }

            var categories = nodes.Cast <AchievementCategoryTreeNode>().Select(x => x.AchievementCategory).ToList();

            var filteredIndex = categories.FindIndex(x => x == selectedCategory);

            if (filteredIndex == categories.Count - 1) // Already bottom element so can't go down
            {
                return;
            }

            dataManager.Swap(categories[filteredIndex], categories[filteredIndex + 1]);

            RefreshTreeView();
        }
Exemple #5
0
 private void RecursiveTreeViewSearch(TreeNodeCollection treeNodes)
 {
     TreeNode[] nodes = treeNodes.Cast <TreeNode>().ToArray();
     foreach (var node in nodes)
     {
         if (whereCondition(node.Tag as TestObjectNurse))
         {
             RecursiveTreeViewSearch(node.Nodes);
             node.ForeColor = Color.Red;
             node.BackColor = Color.Yellow;
         }
         else
         {
             if (node.GetNodeCount(false) == 0)
             {
                 node.Remove();
             }
             else
             {
                 RecursiveTreeViewSearch(node.Nodes);
                 if (node.GetNodeCount(false) == 0)
                 {
                     node.Remove();
                 }
             }
         }
     }
 }
Exemple #6
0
        public Color RefreshTreeViewColors(TreeNodeCollection nodes)
        {
            AlarmColors alarmcolors = new AlarmColors();

            Color defColor = Color.Transparent;

            if (nodes.Count > 0)
            {
                foreach (TreeNode elem in nodes)
                {
                    if (elem.Nodes.Count > 0)
                    {
                        elem.BackColor = RefreshTreeViewColors(elem.Nodes);
                    }
                    //int maxcode = nodes.Cast<TreeNode>().Max(x => alarmcolors.giveAlarmCode(x.BackColor));
                }
                var query = (from el in nodes.Cast <TreeNode>()
                             where alarmcolors.giveAlarmCode(el.BackColor) >= 0
                             select el);
                if (query.Count() > 0)
                {
                    int max = query.Max(x => alarmcolors.giveAlarmCode(x.BackColor));
                    return(alarmcolors.giveColorfromCode(max));
                }
            }
            return(defColor);
        }
        public void Remove()
        {
            var selectedCategory = GetSelectedAchievementCategory();

            if (selectedCategory == null)
            {
                MessageBox.Show("No category selected!" + Environment.NewLine + Environment.NewLine + "Category is not added.", "No category", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            dataManager.Remove(selectedCategory);

            var node = tvwAchievementCategories.SelectedNode.Parent;
            TreeNodeCollection nodes = null;

            if (node != null && node.Nodes != null)
            {
                nodes = node.Nodes;
            }
            else
            {
                nodes = tvwAchievementCategories.Nodes;
            }

            tvwAchievementCategories.SelectedNode.Remove();

            var categories = nodes.Cast <AchievementCategoryTreeNode>().Select(x => x.AchievementCategory).ToList();

            dataManager.UpdateLocations(selectedCategory, categories);

            RefreshTreeView();
        }
Exemple #8
0
        /// <summary>
        /// Function to add a file to the tree.
        /// </summary>
        /// <param name="nodes">Source collection.</param>
        /// <param name="file">File to add.</param>
        /// <returns>The new node.</returns>
        public static TreeNodeFile AddFile(this TreeNodeCollection nodes, GorgonFileSystemFileEntry file)
        {
            if (file == null)
            {
                throw new ArgumentNullException("file");
            }

            // Find check to ensure the node is unique.
            TreeNodeFile result = (from node in nodes.Cast <TreeNode>()
                                   let dirNode = node as TreeNodeFile
                                                 where dirNode != null &&
                                                 string.Equals(node.Name, file.FullPath, StringComparison.OrdinalIgnoreCase)
                                                 select dirNode).FirstOrDefault();

            if (result != null)
            {
                return(result);
            }

            result = new TreeNodeFile();
            result.UpdateFile(file);

            nodes.Add(result);

            if ((result.Parent != null) &&
                (!result.Parent.IsExpanded))
            {
                result.Parent.Expand();
            }

            return(result);
        }
        private void UpdateChildTreeNodes(TreeNodeCollection collection, IEnumerable <ISymbol> symbols)
        {
            foreach (ISymbol symbol in symbols)
            {
                if (symbol is ProgramRootSymbol)
                {
                    continue;
                }
                if (symbol is Defun)
                {
                    continue;
                }

                TreeNode node = collection.Cast <TreeNode>().Where(n => n.Tag == symbol).FirstOrDefault();
                if (node == null)
                {
                    node     = new TreeNode();
                    node.Tag = symbol;
                    collection.Add(node);
                }
                node.Checked = symbol.Enabled;
                node.Text    = symbol.Name;

                var groupSymbol = symbol as GroupSymbol;
                if (groupSymbol != null)
                {
                    UpdateChildTreeNodes(node.Nodes, groupSymbol.Symbols);
                }
            }
        }
Exemple #10
0
 private void ListDirectory(TreeNodeCollection nodes, string[] files, nodeImage image)
 {
     foreach (var path in files)
     {
         TreeNodeCollection curNodes  = nodes;
         string[]           nodeNames = path.Split('\\');
         int i = 1;
         foreach (var nodeName in nodeNames)
         {
             TreeNode[] newNode = curNodes
                                  .Cast <TreeNode>()
                                  .Where(r => r.Text == nodeName).ToArray();
             if (newNode.Length == 0)
             {
                 // last item
                 int idx = (int)((i == nodeNames.Length)? image : nodeImage.folder);
                 curNodes = curNodes.Add(nodeName, nodeName, idx, idx).Nodes;
             }
             else
             {
                 curNodes = newNode[0].Nodes;
             }
             i++;
         }
     }
 }
Exemple #11
0
        private void ReloadNodes(TreeNodeCollection nodes, string path)
        {
            SuspendUpdate();

            foreach (TreeNode node in nodes)
            {
                if (!IODirectory.Exists((string)node.Tag))
                {
                    node.Remove();
                }
            }

            foreach (string subPath in IODirectory.GetDirectories(path))
            {
                if (new FileInfo(subPath).Attributes.IsHidden())
                {
                    continue;
                }

                var node = nodes.Cast <TreeNode>().SingleOrDefault(p => PathUtil.ContainsPath((string)p.Tag, subPath) == PathContains.Equals);
                if (node == null)
                {
                    InsertSorted(nodes, BuildNode(subPath));
                }
            }

            ResumeUpdate();
        }
 private void CheckAll(TreeNodeCollection nodes)
 {
     nodes.Cast <TreeNode>().ForEach(n =>
     {
         n.Checked = true;
         CheckAll(n.Nodes);
     });
 }
        public static TreeNode FindTreeNodeByFullPath(this TreeNodeCollection collection, string fullPath, StringComparison comparison = StringComparison.InvariantCultureIgnoreCase)
        {
            var foundNode = collection.Cast <TreeNode>().FirstOrDefault(tn => string.Equals(tn.FullPath, fullPath, comparison));

            if (null == foundNode)
            {
                foreach (var childNode in collection.Cast <TreeNode>())
                {
                    var foundChildNode = FindTreeNodeByFullPath(childNode.Nodes, fullPath, comparison);
                    if (null != foundChildNode)
                    {
                        return(foundChildNode);
                    }
                }
            }
            return(foundNode);
        }
Exemple #14
0
        /// <summary>
        /// Does a breadth-first recursion to set the sorting property of any ICanSorts in the tree
        /// </summary>
        /// <param name="lstNodes">The list if TreeNodes to iterate over</param>
        private static void CacheSortOrderRecursive(TreeNodeCollection lstNodes)
        {
            List <TreeNode> lstEnumerable = lstNodes.Cast <TreeNode>().ToList();

            // Do this as two steps because non-sortables can own sortables
            lstEnumerable?.Where(n => n?.Tag is ICanSort).ToList().ForEach(n => (n.Tag as ICanSort).SortOrder = n.Index);
            lstEnumerable?.ForEach(n => CacheSortOrderRecursive(n.Nodes));
        }
 private void UpdateAll(TreeNodeCollection treeNodeCollection, bool check)
 {
     treeNodeCollection.Cast <TreeNode>().ForEach(node =>
     {
         node.Checked = check;
         UpdateAll(node.Nodes, check);
     });
 }
        private void CollectExpandedTreeNodeModels(TreeNodeCollection nodes)
        {
            var expandedNodes = nodes.Cast <TreeNode>()
                                .Where(tn => tn.IsExpanded)
                                .ToList();

            expandedTreeNodes.AddRange(expandedNodes);
            expandedNodes.ForEach(en => CollectExpandedTreeNodeModels(en.Nodes));
        }
Exemple #17
0
 private List <string> getCheckedReportPathes(TreeNodeCollection nodes, List <string> list)
 {
     list.AddRange(nodes.Cast <TreeNode>().Where(n => n.Checked && n.Nodes.Count == 0).Select(n => n.Name));
     foreach (TreeNode node in nodes)
     {
         getCheckedReportPathes(node.Nodes, list);
     }
     return(list);
 }
        private void ClearProjectNodes(TreeNodeCollection nodes)
        {
            var treeNodes = nodes.Cast <TreeNode>().ToArray();

            foreach (var treeNode in treeNodes)
            {
                treeNode.Tag = null;
                _projects.Nodes.Remove(treeNode);
            }
        }
        /// <summary>
        /// Search for the entity node that represents the entity in the given state.
        /// Returns null if not found.
        /// </summary>
        private static EntityNode FindNodeForState(IEntityState state, TreeNodeCollection nodes)
        {
            var result = nodes.OfType <EntityNode>().FirstOrDefault(x => state.IsStateOf(x.Entity));

            if (result != null)
            {
                return(result);
            }
            return(nodes.Cast <TreeNode>().Select(x => FindNodeForState(state, x.Nodes)).FirstOrDefault(x => x != null));
        }
Exemple #20
0
        private void ResetAllNodeHighlighting(TreeNodeCollection nodes)
        {
            labelNumFound.Text = "";

            foreach (TreeNode node in nodes.Cast <TreeNode>())
            {
                HighlightNode(node, false);
                ResetAllNodeHighlighting(node.Nodes);
            }
        }
        /// <summary>
        /// Determines whether [is child node selected] [the specified nodes].
        /// </summary>
        /// <param name="nodes">
        /// The nodes.
        /// </param>
        /// <returns>
        /// <c>true</c> if [is child node selected] [the specified nodes]; otherwise, <c>false</c>.
        /// </returns>
        /// <remarks>
        /// </remarks>
        private bool IsChildNodeSelected(TreeNodeCollection nodes)
        {
            var bRet = false;

            if (nodes != null)
            {
                bRet = nodes.Cast <TreeNode>().Any(node => node.Selected || this.IsChildNodeSelected(node.ChildNodes));
            }

            return(bRet);
        }
Exemple #22
0
        private void nameAllNodes(TreeNodeCollection Nodes)
        {
            List <TreeNode> allNodes = Nodes.Cast <TreeNode>().ToList();

            //flatten tree of nodes into list.
            for (int i = 0; i < allNodes.Count(); i++)
            {
                allNodes[i].Name = i.ToString();
                allNodes.AddRange(allNodes[i].Nodes.Cast <TreeNode>());
            }
        }
Exemple #23
0
        public static IEnumerable <TreeNode> Iterate(this TreeNodeCollection self)
        {
            foreach (var node in self.Cast <TreeNode>())
            {
                yield return(node);

                foreach (var internalNode in Iterate(node.Nodes))
                {
                    yield return(internalNode);
                }
            }
        }
Exemple #24
0
 static private TreeNode FindNode(TreeNode nodeToFind, TreeNodeCollection tv)
 {
     TreeNode[] treeNodes = tv.Cast <TreeNode>().Where(r => r.Text == nodeToFind.Text).ToArray();
     foreach (TreeNode node in treeNodes)
     {
         if (node.Level == nodeToFind.Level)
         {
             return(node);
         }
     }
     return(null);
 }
        /// <summary>
        /// The expand to depth.
        /// </summary>
        /// <param name="nodes">
        /// The nodes.
        /// </param>
        /// <param name="expandDepth">
        /// The expand depth.
        /// </param>
        public static void ExpandToDepth(TreeNodeCollection nodes, int expandDepth)
        {
            if (nodes == null)
            {
                return;
            }

            foreach (var node in nodes.Cast <TreeNode>().Where(node => node.Depth < expandDepth))
            {
                node.Expand();
                ExpandToDepth(node.ChildNodes, expandDepth);
            }
        }
        private TreeNode FindSubNode(TreeNodeCollection nodes, Queue <string> pathParts)
        {
            while (true)
            {
                var treeToFind = pathParts.Dequeue();
                if (pathParts.Count == 0)
                {
                    return(nodes.Cast <TreeNode>().SingleOrDefault(n => n?.Tag is GitItem item && item.Name == treeToFind));
                }

                var node = nodes.Cast <TreeNode>().SingleOrDefault(n =>
                                                                   n?.Tag is GitItem item && item.ObjectType == GitObjectType.Tree && item.Name == treeToFind);

                if (node is null)
                {
                    return(null);
                }

                node.Expand(); // load the sub nodes (otherwise, the search find nothing)
                nodes = node.Nodes;
            }
        }
Exemple #27
0
        /// <summary>
        /// Function to add a directory to the tree.
        /// </summary>
        /// <param name="nodes">Source collection.</param>
        /// <param name="directory">Directory to add.</param>
        /// <param name="autoExpand">TRUE to expand the new node (if it has children) after it's been added, FALSE to leave collapsed.</param>
        /// <returns>The new node.</returns>
        public static TreeNodeDirectory AddDirectory(this TreeNodeCollection nodes, GorgonFileSystemDirectory directory, bool autoExpand)
        {
            if (directory == null)
            {
                throw new ArgumentNullException("directory");
            }

            // Find check to ensure the node is unique.
            TreeNodeDirectory result = (from node in nodes.Cast <TreeNode>()
                                        let dirNode = node as TreeNodeDirectory
                                                      where dirNode != null &&
                                                      string.Equals(node.Name, directory.FullPath, StringComparison.OrdinalIgnoreCase)
                                                      select dirNode).FirstOrDefault();

            if (result != null)
            {
                return(result);
            }

            result = new TreeNodeDirectory(directory)
            {
                ForeColor = Color.White,
                Text      = directory.Name
            };

            if ((directory.Directories.Count > 0) || (directory.Files.Count > 0))
            {
                // Add a dummy node to indicate that there are children.
                result.Nodes.Add("DummyNode");
            }

            nodes.Add(result);

            // Expand the parent.
            if ((result.Parent != null) &&
                (!result.Parent.IsExpanded))
            {
                TreeNode parent = result.Parent;
                parent.Expand();
                result = (TreeNodeDirectory)parent.Nodes[result.Name];
            }

            // Expand the node if necessary.
            if ((autoExpand) &&
                (result.Nodes.Count > 0))
            {
                result.Expand();
            }

            return(result);
        }
Exemple #28
0
        private void AutoExpandPath()
        {
            if (_pathExpansionQueue == null || _pathExpansionQueue.Count <= 0)
            {
                return;
            }

            lock (_lock)
            {
                if (_pathExpansionQueue == null || _pathExpansionQueue.Count <= 0)
                {
                    return;
                }

                string pathPart = _pathExpansionQueue.Dequeue();
                if (!FolderMode && _pathExpansionQueue.Count == 0)
                {
                    List <FileSystemListViewItem> items      = GetListViewItems();
                    FileSystemListViewItem        targetItem = items.FirstOrDefault(item => item.Entry.Equals(pathPart));
                    if (targetItem != null)
                    {
                        SelectListViewItem(targetItem);
                    }
                }
                else
                {
                    TreeNodeCollection nodes = _lastAutoExpandedNode?.Nodes ?? _machineNode.Nodes;
                    _lastAutoExpandedNode = nodes.Cast <FileSystemTreeNode>().FirstOrDefault(node => node.Entry.Equals(pathPart));
                    if (_lastAutoExpandedNode != null)
                    {
                        if (_pathExpansionQueue.Count == (FolderMode ? 0 : 1))
                        {
                            SelectTreeNode(_lastAutoExpandedNode);
                        }
                        else
                        {
                            ExpandTreeNode(_lastAutoExpandedNode);
                        }
                    }
                    else
                    {
                        _pathExpansionQueue = null;
                    }
                }

                if (_pathExpansionQueue == null || _pathExpansionQueue.Count == 0)
                {
                    _pathExpansionWaitCursor.Dispose();
                }
            }
        }
        public void MoveLeft()
        {
            var parentNode = (AchievementCategoryTreeNode)tvwAchievementCategories.SelectedNode.Parent;

            if (parentNode?.AchievementCategory is null)
            {
                return;
            }

            var selectedCategory = GetSelectedAchievementCategory();

            dataManager.UpdateParent(selectedCategory, selectedCategory.Parent.Parent, selectedCategory.Parent.Location + 1);

            var node = parentNode.Parent;
            TreeNodeCollection nodes = null;

            if (node != null && node.Nodes != null)
            {
                nodes = node.Nodes;
            }
            else
            {
                nodes = tvwAchievementCategories.Nodes;
            }

            nodes.Insert(parentNode.Index + 1, new AchievementCategoryTreeNode(selectedCategory)); // Need to add this to ensure correct location numbers

            var categories = nodes.Cast <AchievementCategoryTreeNode>().Select(x => x.AchievementCategory).ToList();

            dataManager.UpdateLocations(selectedCategory, categories);

            var nextNode = (AchievementCategoryTreeNode)tvwAchievementCategories.SelectedNode.NextNode;

            if (nextNode is not null)
            {
                tvwAchievementCategories.SelectedNode.Remove();
                var prevNode = (AchievementCategoryTreeNode)nextNode.PrevNode;
                if (prevNode?.AchievementCategory is not null)
                {
                    var categories2 = prevNode.Parent.Nodes.Cast <AchievementCategoryTreeNode>().Select(x => x.AchievementCategory).ToList();
                    dataManager.UpdateLocations(prevNode.AchievementCategory, categories2);
                }
                else // removed item was 1st element so we use next element and adjust from a fictional 1st element
                {
                    var categories2 = nextNode.Parent.Nodes.Cast <AchievementCategoryTreeNode>().Select(x => x.AchievementCategory).ToList();
                    dataManager.UpdateLocations(new AchievementCategory(), categories2);
                }
            }

            RefreshTreeView();
        }
        void RefreshNodeColors(TreeNodeCollection nodes, bool recursive)
        {
            foreach (var node in nodes.Cast <GenericNode>())
            {
                if (recursive)
                {
                    RefreshNodeColors(node.Nodes, recursive);
                }

                node.BackColor        = this.BackColor;
                node.ForeColor        = this.ForeColor;
                node.ForeColorRequest = this.ForeColor;
            }
        }