示例#1
0
        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);
            }
        }
示例#2
0
        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);
        }
示例#3
0
        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);
        }
示例#4
0
 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);
 }
示例#5
0
        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);
        }
示例#6
0
        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);
            }
        }