private void NewFolderTreeMenuItemClick(object sender, EventArgs e) { try { var treeView = GetTreeViewFromTreeMenuItem(sender); if (treeView == null || treeView.SelectedNode == null) { return; } var form = new DriveEntryNameForm { FormCaption = Resources.NewFolderFormCaption, DriveEntryName = "", SaveButtonText = Resources.NewFolderFormSaveButtonText }; if (form.ShowDialog() != DialogResult.OK) { return; } var drive = GetDriveFromTreeNode(treeView.SelectedNode); var newFolder = drive.CombinePath( treeView.SelectedNode.Name.Split('|')[0], form.DriveEntryName); drive.CreateDirectory(newFolder); RefreshDriveEntries(drive.Key, treeView.SelectedNode.Name); } catch (Exception ex) { MessageBox.Show(ex.Message, Resources.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); } }
private void RenameFileOrFolderFromFileGrid(DataGridView grid, string driveKey, string directoryKey) { if (grid == null || grid.SelectedRows.Count == 0) { return; } var drive = _drives[driveKey]; if (drive == null) { return; } var form = new DriveEntryNameForm(); foreach (DataGridViewRow row in grid.SelectedRows) { var currentPath = row.Cells[0].Value.ToString(); switch (drive.GetDriveEntryType(currentPath)) { case DriveEntryType.Directory: form.FormCaption = Resources.RenameFolderFormCaption; form.DriveEntryName = currentPath.Substring(currentPath.LastIndexOf(drive.PathDelimiter) + 1); form.SaveButtonText = Resources.RenameFolderFormSaveButtonText; if (form.ShowDialog() == DialogResult.OK) { var newPath = drive.CombinePath( currentPath.Substring(0, currentPath.LastIndexOf(drive.PathDelimiter) + 1), form.DriveEntryName); drive.RenameDirectory(currentPath, newPath); } break; case DriveEntryType.File: form.FormCaption = Resources.RenameFileFormCaption; form.DriveEntryName = currentPath.Substring(currentPath.LastIndexOf(drive.PathDelimiter) + 1); form.SaveButtonText = Resources.RenameFileFormSaveButtonText; if (form.ShowDialog() == DialogResult.OK) { var newPath = drive.CombinePath( currentPath.Substring(0, currentPath.LastIndexOf(drive.PathDelimiter) + 1), form.DriveEntryName); drive.RenameFile(currentPath, newPath); } break; } } RefreshDriveEntries(driveKey, directoryKey); }
private void RenameDirectoryFromTree(TreeNode selectedNode) { var drive = GetDriveFromTreeNode(selectedNode); var currentPath = selectedNode.Name; var form = new DriveEntryNameForm { FormCaption = Resources.RenameFolderFormCaption, DriveEntryName = currentPath.Substring(currentPath.LastIndexOf(drive.PathDelimiter) + 1), SaveButtonText = Resources.RenameFolderFormSaveButtonText }; if (form.ShowDialog() != DialogResult.OK) { return; } var newPath = drive.CombinePath( currentPath.Substring(0, currentPath.LastIndexOf(drive.PathDelimiter) + 1), form.DriveEntryName); drive.RenameDirectory(currentPath, newPath); RefreshDriveEntries(drive.Key, selectedNode.Parent.Name); }
private void RenameFileOrFolderFromFileGrid(DataGridView grid, string driveKey, string directoryKey) { if (grid == null || grid.SelectedRows.Count == 0) return; var drive = _drives[driveKey]; if (drive == null) return; var form = new DriveEntryNameForm(); foreach (DataGridViewRow row in grid.SelectedRows) { var currentPath = row.Cells[0].Value.ToString(); switch (drive.GetDriveEntryType(currentPath)) { case DriveEntryType.Directory: form.FormCaption = Resources.RenameFolderFormCaption; form.DriveEntryName = currentPath.Substring(currentPath.LastIndexOf(drive.PathDelimiter) + 1); form.SaveButtonText = Resources.RenameFolderFormSaveButtonText; if (form.ShowDialog() == DialogResult.OK) { var newPath = drive.CombinePath( currentPath.Substring(0, currentPath.LastIndexOf(drive.PathDelimiter) + 1), form.DriveEntryName); drive.RenameDirectory(currentPath, newPath); } break; case DriveEntryType.File: form.FormCaption = Resources.RenameFileFormCaption; form.DriveEntryName = currentPath.Substring(currentPath.LastIndexOf(drive.PathDelimiter) + 1); form.SaveButtonText = Resources.RenameFileFormSaveButtonText; if (form.ShowDialog() == DialogResult.OK) { var newPath = drive.CombinePath( currentPath.Substring(0, currentPath.LastIndexOf(drive.PathDelimiter) + 1), form.DriveEntryName); drive.RenameFile(currentPath, newPath); } break; } } RefreshDriveEntries(driveKey, directoryKey); }
private void RenameDirectoryFromTree(TreeNode selectedNode) { var drive = GetDriveFromTreeNode(selectedNode); var currentPath = selectedNode.Name; var form = new DriveEntryNameForm { FormCaption = Resources.RenameFolderFormCaption, DriveEntryName = currentPath.Substring(currentPath.LastIndexOf(drive.PathDelimiter) + 1), SaveButtonText = Resources.RenameFolderFormSaveButtonText }; if (form.ShowDialog() != DialogResult.OK) return; var newPath = drive.CombinePath( currentPath.Substring(0, currentPath.LastIndexOf(drive.PathDelimiter) + 1), form.DriveEntryName); drive.RenameDirectory(currentPath, newPath); RefreshDriveEntries(drive.Key, selectedNode.Parent.Name); }
private void NewFolderTreeMenuItemClick(object sender, EventArgs e) { try { var treeView = GetTreeViewFromTreeMenuItem(sender); if (treeView == null || treeView.SelectedNode == null) return; var form = new DriveEntryNameForm { FormCaption = Resources.NewFolderFormCaption, DriveEntryName = "", SaveButtonText = Resources.NewFolderFormSaveButtonText }; if (form.ShowDialog() != DialogResult.OK) return; var drive = GetDriveFromTreeNode(treeView.SelectedNode); var newFolder = drive.CombinePath( treeView.SelectedNode.Name.Split('|')[0], form.DriveEntryName); drive.CreateDirectory(newFolder); RefreshDriveEntries(drive.Key, treeView.SelectedNode.Name); } catch (Exception ex) { MessageBox.Show(ex.Message, Resources.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); } }