void ProjectTreeView_MouseClick_PopupMenu_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
            if (!IsProjectOpen() || e.ClickedItem.Tag == null)
            {
                return;
            }

            ProjectTreeNode node = ((ProjectTreeNode)e.ClickedItem.Tag);

            if (sender.GetType() == typeof(ContextMenuStrip))
            {
                ((ContextMenuStrip)sender).Close();
            }

            bool clickHandled = true;

            if (e.ClickedItem.Text == "Folder")
            {
                node.Expand();
                ProjectTreeNode newNode = node.CreateNewFolder();
                _ProjectTree.SelectedNode = newNode;
                newNode.BeginEdit();
            }
            else if (e.ClickedItem.Text == "Add Existing Folder")
            {
                FolderBrowserDialog addExisting = new FolderBrowserDialog();
                addExisting.RootFolder          = Environment.SpecialFolder.Desktop;
                addExisting.SelectedPath        = Path.GetDirectoryName(ProjectFileName);
                addExisting.ShowNewFolderButton = false;
                if (addExisting.ShowDialog() == DialogResult.OK)
                {
                    DirectoryInfo source = new DirectoryInfo(addExisting.SelectedPath);
                    DirectoryInfo target = new DirectoryInfo(Path.Combine(Path.GetDirectoryName(ProjectFileName), Path.GetFileName(addExisting.SelectedPath)));

                    /*
                     * if (target.FullName.StartsWith(source.FullName) || source.FullName.StartsWith(target.FullName))
                     * {
                     *  MessageBox.Show("Cannot add the parent of the currently selected folder.");
                     *  return;
                     * }
                     */

                    ProjectTreeNode newNode = AddExstingDirectory(source, target, node, true);
                    if (newNode != null)
                    {
                        _ProjectTree.SelectedNode = newNode;
                        newNode.Expand();
                    }
                }
            }
            else if (e.ClickedItem.Text == "Code File")
            {
                if (node.Parent != null)
                {
                    node.Parent.Expand();
                }
                ProjectTreeNode newNode = node.CreateNewFile(global.CodeFileExtension);
                _ProjectTree.SelectedNode = newNode;

                newNode.BeginEdit();
            }
            else if (e.ClickedItem.Text == "HTML File")
            {
                if (node.Parent != null)
                {
                    node.Parent.Expand();
                }
                ProjectTreeNode newNode = node.CreateNewFile(".html");
                _ProjectTree.SelectedNode = newNode;

                newNode.BeginEdit();
            }
            else if (e.ClickedItem.Text == "Set as startup object")
            {
                node.IsStartupObject = !node.IsStartupObject;
            }
            else if (e.ClickedItem.Text == "Add Existing File")
            {
                System.Windows.Forms.OpenFileDialog ofdAddFile = new System.Windows.Forms.OpenFileDialog();

                ofdAddFile.Multiselect     = true;
                ofdAddFile.ShowHelp        = false;
                ofdAddFile.DefaultExt      = global.CodeFileExtension;
                ofdAddFile.CheckFileExists = true;
                ofdAddFile.CheckPathExists = true;
                ofdAddFile.ValidateNames   = true;
                ofdAddFile.Filter          = "Simple Script|*" + global.CodeFileExtension + "|Text Files|*.txt|All Files|*.*";

                if (ofdAddFile.ShowDialog() == DialogResult.OK)
                {
                    foreach (String sourceFileName in ofdAddFile.FileNames)
                    {
                        try
                        {
                            ProjectTreeNode newNode        = node.AddFile(sourceFileName);
                            string          targetFileName = newNode.LogicalPath();

                            if (sourceFileName.ToLower() != targetFileName.ToLower())
                            {
                                System.IO.File.Copy(sourceFileName, targetFileName);
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("Cannot add the file [" + sourceFileName + "] due to the following error:\r\n\r\n" + ex.Message);
                        }
                    }
                }
            }
            else if (e.ClickedItem.Text == "Explore Folder")
            {
                try
                {
                    System.Diagnostics.Process process = new System.Diagnostics.Process();
                    process.StartInfo.UseShellExecute = true;
                    process.StartInfo.FileName        = "explorer";
                    process.StartInfo.Arguments       = node.LogicalPath();
                    process.Start();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Cannot explore to the folder due to the following error:\r\n\r\n" + ex.Message);
                }
            }
            else
            {
                clickHandled = false;
            }

            if (!clickHandled) //These operations affected some tabs to be closed.
            {
                clickHandled = true;

                if (!CloseAffectedProjectTabs(node))
                {
                    return;
                }

                if (e.ClickedItem.Text == "Rename")
                {
                    node.BeginEdit();
                }
                else if (e.ClickedItem.Text == "Remove")
                {
                    if (MessageBox.Show("Are you sure you want to remove the " + node.BasicNodeType.ToString() + " \"" + node.Text + "\" from the project?", "Confirm Delete",
                                        MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) != System.Windows.Forms.DialogResult.Yes)
                    {
                        return;
                    }

                    node.Remove();
                }
                else if (e.ClickedItem.Text == "Delete")
                {
                    if (MessageBox.Show("Are you sure you want to PERMANENTLY delete the " + node.BasicNodeType.ToString() + " \"" + node.Text + "\"?", "Confirm Delete",
                                        MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) != System.Windows.Forms.DialogResult.Yes)
                    {
                        return;
                    }

                    try
                    {
                        if (node.BasicNodeType == ProjectTreeNode.BasicNodeTypes.File)
                        {
                            System.IO.File.Delete(node.LogicalPath());
                            node.Remove();
                        }
                        else if (node.BasicNodeType == ProjectTreeNode.BasicNodeTypes.Folder)
                        {
                            Directory.Delete(node.LogicalPath(), true);
                            node.Remove();
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("The object cannot be deleted due to the error below, try removing it instead.\r\n\r\n" + ex.Message);
                    }
                }
                else if (e.ClickedItem.Text == "Delete File")
                {
                }
                else
                {
                    clickHandled = false;
                }
            }

            SaveProjectFile();
        }
        private void _ProjectTree_DragDrop(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent("SSIDE.Classes.ProjectTreeNode", false))
            {
                Point           pt = ((TreeView)sender).PointToClient(new Point(e.X, e.Y));
                ProjectTreeNode destinationNode = (ProjectTreeNode)((TreeView)sender).GetNodeAt(pt);
                ProjectTreeNode sourceNode      = (ProjectTreeNode)e.Data.GetData("SSIDE.Classes.ProjectTreeNode");

                int insertionIndex = -1;

                if (destinationNode.BasicNodeType == ProjectTreeNode.BasicNodeTypes.File)
                {
                    insertionIndex  = destinationNode.Index;
                    destinationNode = (ProjectTreeNode)destinationNode.Parent;
                }

                if (destinationNode.TreeView == sourceNode.TreeView && sourceNode != destinationNode)
                {
                    if (!CloseAffectedProjectTabs(sourceNode))
                    {
                        return;
                    }

                    string          sourceFile    = sourceNode.LogicalPath();
                    ProjectTreeNode oldParentNode = (ProjectTreeNode)sourceNode.Parent;
                    sourceNode.Remove();

                    if (insertionIndex < 0)
                    {
                        if (sourceNode.BasicNodeType == ProjectTreeNode.BasicNodeTypes.File)
                        {
                            insertionIndex = destinationNode.Nodes.Count;
                        }
                    }

                    destinationNode.Nodes.Insert(insertionIndex, sourceNode);
                    destinationNode.Expand();

                    string destinationFile = sourceNode.LogicalPath();

                    try
                    {
                        if (sourceFile.ToLower() != destinationFile.ToLower())
                        {
                            if (sourceNode.BasicNodeType == ProjectTreeNode.BasicNodeTypes.File)
                            {
                                System.IO.File.Move(sourceFile, destinationFile);
                            }
                            else if (sourceNode.BasicNodeType == ProjectTreeNode.BasicNodeTypes.Folder)
                            {
                                Directory.Move(sourceFile, destinationFile);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        sourceNode.Remove();
                        oldParentNode.Nodes.Add(sourceNode);
                        oldParentNode.Expand();
                        MessageBox.Show(ex.Message);
                    }

                    SaveProjectFile();
                }
            }
            else
            {
                try
                {
                    string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
                    if (files != null)
                    {
                        foreach (string fullFileAndPath in files)
                        {
                            if (Path.GetExtension(fullFileAndPath).ToLower() == global.ProjectFileExtension)
                            {
                                LoadProjectFile(fullFileAndPath);
                            }
                            else
                            {
                                AddNewTab(fullFileAndPath);
                            }
                        }
                    }
                }
                catch { }
            }
        }
 private void RemoveNode(ProjectTreeNode node, bool onlyCollapsed = false)
 {
     if (node == null) return;
     if (!onlyCollapsed || !node.IsExpanded)
     {
         if (_nodes.Contains(node)) _nodes.Remove(node);
         if (node.TreeView != null) node.Remove();
         if (node.ProjectItem != null) node.ProjectItem.TreeNode = null;
     }
     if (node.Nodes.Count > 0) RemoveChildNodes(node, onlyCollapsed);
 }