private void removeMenu_Click(object sender, EventArgs e) { if (base.SelectedNode is FileNode) { FileNode node = (FileNode)base.SelectedNode; FileInfo file = node.GetFile(); DialogResult result = MessageBox.Show( String.Format(Language.GetString("DialogFileRemove"), file.Name), Language.GetString("Warning"), MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation); if (result == DialogResult.Yes) { file.Delete(); node.Remove(); } } else if (base.SelectedNode is DirectoryNode) { DirectoryNode node = (DirectoryNode)base.SelectedNode; DirectoryInfo directory = node.GetDirectory(); string message; if (base.SelectedNode is ServerNode) { message = String.Format(Language.GetString("DialogDirectoryRemove"), directory.Name); } else { message = String.Format(Language.GetString("DialogServerRemove"), directory.Name); } DialogResult result = MessageBox.Show(message, Language.GetString("Warning"), MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation); if (result == DialogResult.Yes) { try { if (directory.Exists) { new Computer().FileSystem.DeleteDirectory(directory.FullName, UIOption.AllDialogs, RecycleOption.SendToRecycleBin); } if (base.SelectedNode is ServerNode && ((ServerNode)base.SelectedNode).GetServerData().isImported) { File.Delete(((ServerNode)base.SelectedNode).GetServerData().GetFile()); } node.Destroy(); } catch (OperationCanceledException) { } } } else if (base.SelectedNode is RemoteServerNode) { RemoteServerNode node = (RemoteServerNode)base.SelectedNode; DialogResult result = MessageBox.Show( String.Format(Language.GetString("DialogRemoteServerRemove"), node.GetServerData().name), Language.GetString("Warning"), MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation); if (result == DialogResult.Yes) { Directory.Delete(Main.RemoteDirectory + node.GetServerData().name, true); node.Destroy(); } } else if (base.SelectedNode is RemoteDirectoryNode) { RemoteDirectoryNode node = (RemoteDirectoryNode)base.SelectedNode; DialogResult dr = MessageBox.Show( String.Format(Language.GetString("DialogDirectoryRemove"), node.Text), Language.GetString("Warning"), MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation); if (dr == DialogResult.Yes) { Ftp.deleteDirectory(node.data, node.directory); node.Destroy(); } } else if (base.SelectedNode is RemoteFileNode) { RemoteFileNode node = (RemoteFileNode)base.SelectedNode; DialogResult dr = MessageBox.Show( String.Format(Language.GetString("DialogFileRemove"), node.Text), Language.GetString("Warning"), MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation); if (dr == DialogResult.Yes) { Ftp.deleteFile(node.data, node.GetFile()); node.Remove(); } } }
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 } }