Пример #1
0
        /// <summary>
        /// Add project item to explorer.
        /// </summary>
        /// <param name="type">Type of the item.</param>
        /// <param name="path">Path of the item in Workspace.Project.</param>
        public void Add(TreeNodeType type, string path, bool expand)
        {
            // Check if the path is from Workspace.Project.
            if (path.Substring(0, Workspace.Project.BaseDirectory.Length) != Workspace.Project.BaseDirectory)
            {
                return;
            }

            // TODO: Check if file exists in project.

            short imageIndex = 1;

            string name      = Path.GetFileName(path);
            string extension = Path.GetExtension(path);

            // Check extension to know image index.
            if (extension == ".inc")
            {
                imageIndex = 4;
            }
            else if (string.IsNullOrEmpty(extension) == false)
            {
                imageIndex = 3;
            }

            // Create TreeView path of the folder.
            string directory = Path.Combine(Workspace.Project.Name, Path.GetDirectoryName(path.Remove(0, Workspace.Project.BaseDirectory.Length + 1)));

            TreeNode parentNode = TreeNodeHelper.GetNodeByPath(this.projectFiles.Nodes, directory);

            if (parentNode != null)
            {
                // Add the node to TreeView.
                TreeNode childNode = parentNode.Nodes.Add(path, name, imageIndex, imageIndex);
                childNode.Tag = type;

                // Now let's sort the TreeView.
                this.projectFiles.Sort();

                if (expand == true && parentNode.IsExpanded == false)
                {
                    parentNode.Expand();
                }

                if (ItemAdded != null)
                {
                    ItemAdded(this, new ItemEventArgs(path));
                }
            }
            else
            {
                // TODO: Write the a message to log file.
            }
        }