private void folderTreeView_AfterLabelEdit(object sender, NodeLabelEditEventArgs e) { folderTreeView.LabelEdit = false; OpenDat dat = ControlDat.GetDat(currentDat); if (createFolder) { dat.AddEmptyFolder(createFolderPath); e.Node.Name = createFolderPath.ToLowerInvariant(); createFolderPath = null; createFolder = false; } if (e.Label == null) { return; } if (e.Label.Equals(e.Node.Text)) { e.CancelEdit = true; return; } string folderPath = e.Node.Name; // in lower case; int i = folderPath.LastIndexOf(e.Node.Text.ToLowerInvariant() + '\\'); string renameFolderPath = folderPath.Remove(i) + e.Label + '\\'; if (dat.FolderExist(renameFolderPath, false)) { MessageBox.Show((LocaleRU) ? "Директория с таким именем уже существует." : "This directory already exists.", "Dat Explorer II", MessageBoxButtons.OK, MessageBoxIcon.Error); e.CancelEdit = true; return; } e.Node.Name = renameFolderPath.ToLowerInvariant(); dat.RenameFolder(folderPath, e.Label); SaveToolStripButton.Enabled = dat.ShouldSave(); dirToolStripStatusLabel.Text = "Directory: " + e.Node.Name; }
private void filesListView_AfterLabelEdit(object sender, LabelEditEventArgs e) { deleteFilesToolStripMenuItem.Enabled = true; filesListView.LabelEdit = false; skipKeyEvent = true; if (!createFolder && (e.Label == null || e.Label.Equals(filesListView.Items[e.Item].Text))) { e.CancelEdit = true; return; } string newName = e.Label ?? filesListView.Items[e.Item].Text; if (e.Label != null) { bool isSelfRename = e.Label.Equals(filesListView.Items[e.Item].Text, StringComparison.OrdinalIgnoreCase); if (!isSelfRename) { foreach (ListViewItem item in filesListView.Items) { if (e.Label.Equals(item.Text, StringComparison.OrdinalIgnoreCase)) { if (item.Tag == null) { MessageBox.Show((LocaleRU) ? "Директория с таким именем уже существует." : "This directory already exists.", "Dat Explorer II", MessageBoxButtons.OK, MessageBoxIcon.Error); if (createFolder) { newName = filesListView.Items[e.Item].Text; e.CancelEdit = true; break; } } else // file { MessageBox.Show((LocaleRU) ? "Файл с таким именем уже существует." : "The file with the same name already exists.", "Dat Explorer II", MessageBoxButtons.OK, MessageBoxIcon.Error); } e.CancelEdit = true; return; } } } } OpenDat dat = ControlDat.GetDat(currentDat); string fullPath = Misc.GetNodeFullPath(currentNode); if (createFolder) { string folderPath = fullPath + '\\' + newName + '\\'; folderPath = folderPath.Substring(currentDat.Length + 1); TreeNode addNode = new TreeNode(newName); addNode.Name = folderPath.ToLowerInvariant(); currentNode.Nodes.Add(addNode); filesListView.Items[e.Item].Name = addNode.Name; dat.AddEmptyFolder(folderPath); createFolder = false; } else { string pathTo = (fullPath + '\\' + filesListView.Items[e.Item].Text).ToLowerInvariant(); pathTo = pathTo.Substring(currentDat.Length + 1); if (filesListView.Items[e.Item].Tag == null) // folder { pathTo += '\\'; string renamePath = dat.RenameFolder(pathTo, e.Label); if (renamePath == null) { return; } filesListView.Items[e.Item].Name = renamePath; // rename path and name for tree node TreeNode node = Misc.FindPathNode(pathTo, currentNode); node.Name = renamePath; node.Text = e.Label; } else { filesListView.Items[e.Item].Tag = dat.RenameFile(pathTo, e.Label); } } SaveToolStripButton.Enabled = dat.ShouldSave(); }