private void renameMenu_Click(object sender, EventArgs e)
        {
            OldLabelEditName = null;

            if (this.SelectedNode is ServerNode)
            {
                ServerNode node = (ServerNode)this.SelectedNode;
                OldLabelEditName = node.Text;
                node.Text        = node.GetServerData().name;
            }
            else if (this.SelectedNode is RemoteServerNode)
            {
                RemoteServerNode node = (RemoteServerNode)this.SelectedNode;
                OldLabelEditName = node.Text;
                node.Text        = node.GetServerData().name;
            }

            EditAction = LabelEditAction.Rename;
            this.SelectedNode.BeginEdit();
            this.SelectedNode = null;
        }
        private void ServersTreeView_AfterLabelEdit(object sender, NodeLabelEditEventArgs e)
        {
            LabelEditAction EditAction = this.EditAction;

            this.EditAction = LabelEditAction.None;
            if (e.Label == null || e.Label == "")
            {
                if (EditAction == LabelEditAction.Rename)
                {
                    if (OldLabelEditName != null)
                    {
                        e.Node.Text = OldLabelEditName;
                    }
                }
                else if (EditAction == LabelEditAction.NewFile || EditAction == LabelEditAction.NewDirectory)
                {
                    e.Node.Remove();
                }
                e.CancelEdit = true;
                return;
            }

            if (EditAction == LabelEditAction.Rename)
            {
                #region ActionRename
                if (e.Node is FileNode)
                {
                    FileNode node = (FileNode)e.Node;
                    FileInfo file = node.GetFile();
                    string   path = file.DirectoryName + Path.DirectorySeparatorChar + e.Label;

                    if (File.Exists(path))
                    {
                        Error.Show("ErrorFileExists");
                        e.CancelEdit = true; return;
                    }
                    try { file.MoveTo(path); }
                    catch (IOException)
                    {
                        Error.Show("ErrorFileInvalidName");
                        e.CancelEdit = true; return;
                    }
                }

                else if (e.Node is ServerNode)
                {
                    ServerNode    node      = (ServerNode)e.Node;
                    DirectoryInfo directory = node.GetDirectory();
                    string        path      = directory.Parent.FullName + Path.DirectorySeparatorChar + e.Label;

                    if (Directory.Exists(path))
                    {
                        Error.Show("ErrorServerExists");
                    }
                    else
                    {
                        try
                        {
                            directory.MoveTo(path);
                            node.GetServerData().name = e.Label;
                            node.GetServerData().Save();
                        }
                        catch (IOException)
                        {
                            Error.Show("ErrorServerInvalidName");
                        }
                    }
                    node.Text    = node.GetServerData().ToString();
                    e.CancelEdit = true;
                }

                else if (e.Node is DirectoryNode)
                {
                    DirectoryNode node      = (DirectoryNode)e.Node;
                    DirectoryInfo directory = node.GetDirectory();
                    string        path      = directory.Parent.FullName + Path.DirectorySeparatorChar + e.Label;

                    if (Directory.Exists(path))
                    {
                        Error.Show("ErrorDirectoryExists");
                        e.CancelEdit = true; return;
                    }
                    try
                    {
                        directory.MoveTo(path);
                    }
                    catch (IOException)
                    {
                        Error.Show("ErrorDirectoryInvalidName");
                        e.CancelEdit = true; return;
                    }
                }

                else if (e.Node is RemoteServerNode)
                {
                    RemoteServerNode  node = (RemoteServerNode)e.Node;
                    Data.RemoteServer data = new Data.RemoteServer();
                    data.name = e.Label;
                    if (!Directory.Exists(data.GetDirectory()))
                    {
                        Directory.Move(node.GetServerData().GetDirectory(), data.GetDirectory());
                        node.GetServerData().name = e.Label;
                        node.GetServerData().Save();
                    }
                    node.Text    = node.GetServerData().ToString();
                    e.CancelEdit = true;
                }

                else if (e.Node is RemoteDirectoryNode)
                {
                    RemoteDirectoryNode node = (RemoteDirectoryNode)e.Node;
                    Ftp.rename(node.data, node.directory, e.Label);
                    ((RemoteDirectoryNode)e.Node.Parent).Refresh();
                    e.CancelEdit = true;
                }

                else if (e.Node is RemoteFileNode)
                {
                    RemoteFileNode node = (RemoteFileNode)e.Node;
                    Ftp.rename(node.data, node.GetFile(), e.Label);
                    ((RemoteDirectoryNode)e.Node.Parent).Refresh();
                    e.CancelEdit = true;
                }
                #endregion
            }

            else if (EditAction == LabelEditAction.NewFile)
            {
                #region ActionNewFile
                if (e.Node.Parent is DirectoryNode)
                {
                    DirectoryNode node = (DirectoryNode)e.Node.Parent;
                    string        path = node.GetDirectory().FullName + Path.DirectorySeparatorChar + e.Label;
                    if (File.Exists(path))
                    {
                        Error.Show("ErrorFileExists");
                    }
                    else
                    {
                        try
                        {
                            File.Create(path).Close();
                        }
                        catch (IOException)
                        {
                            Error.Show("ErrorFileInvalidName");
                        }
                    }
                    e.Node.Remove();
                }
                else if (e.Node.Parent is RemoteDirectoryNode)
                {
                    RemoteDirectoryNode node = (RemoteDirectoryNode)e.Node.Parent;
                    File.Create(Main.TempDirectory + e.Label).Close();
                    Ftp.upload(node.data, node.directory + e.Label, Main.TempDirectory + e.Label);
                    e.Node.Remove();
                    node.Refresh();
                }
                #endregion ;
            }

            else if (EditAction == LabelEditAction.NewDirectory)
            {
                #region ActionNewDirectory
                if (e.Node.Parent is DirectoryNode)
                {
                    DirectoryNode node = (DirectoryNode)e.Node.Parent;
                    string        path = node.GetDirectory().FullName + Path.DirectorySeparatorChar + e.Label;
                    if (Directory.Exists(path))
                    {
                        Error.Show("ErrorDirectoryExists");
                    }
                    else
                    {
                        try
                        {
                            Directory.CreateDirectory(path);
                        }
                        catch (IOException)
                        {
                            Error.Show("ErrorDirectoryInvalidName");
                        }
                    }
                    e.Node.Remove();
                }
                else if (e.Node.Parent is RemoteDirectoryNode)
                {
                    RemoteDirectoryNode node = (RemoteDirectoryNode)e.Node.Parent;
                    Ftp.createDirectory(node.data, node.directory + e.Label);
                    e.Node.Remove();
                    node.Refresh();
                }
                #endregion
            }
        }