private void OnRenameMesh(object sender, EventArgs e) { var node = GetTreeNodeForContextMenuEvent(sender); if (node == null || !(node.Tag as KeyValuePair <Node, Mesh>?).HasValue) { return; } var nodeMeshPair = (KeyValuePair <Node, Mesh>)node.Tag; var mesh = nodeMeshPair.Value; SafeRenamer renamer = new SafeRenamer(_scene); HashSet <string> greylist = renamer.GetAllNodeNames(); greylist.UnionWith(renamer.GetAllMaterialNames()); greylist.UnionWith(renamer.GetAllAnimationNames()); // Mesh names need not be unique, but it's good if they are. // Don't put in blacklist though. greylist.UnionWith(renamer.GetAllMeshNames()); RenameDialog dialog = new RenameDialog(mesh.Name, new HashSet <string>(), greylist); if (dialog.ShowDialog() == DialogResult.OK) { string newName = dialog.NewName; string oldName = mesh.Name; _scene.UndoStack.PushAndDo("Rename Mesh", () => { renamer.RenameMesh(mesh, newName); }, () => { renamer.RenameMesh(mesh, oldName); }, () => { node.Text = GetMeshDisplayName(mesh, GetIndexForMesh(mesh)); }); } }
private void OnContextMenuRename(object sender, EventArgs eventArgs) { // This renames the texture file on disk. The rename only affects the file name, not the path // prefix or file extension. // // Editing folders is complicated because the texture might be outside of the // base folder from which the scene is loaded. Also, when exporting we generally // prefer to copy all scene textures to a single folder anyway. if (Texture == null) { return; } if (Texture.ActualLocation == null) { MessageBox.Show("This is an embedded texture that cannot be renamed."); return; } SafeRenamer renamer = new SafeRenamer(_scene); RenameDialog dialog = new RenameDialog("", new HashSet <string>(), new HashSet <string>()); if (dialog.ShowDialog() == DialogResult.OK) { if (MessageBox.Show("This will rename the actual image file on disk.", "Rename texture", MessageBoxButtons.OKCancel) == DialogResult.OK) { string newName = dialog.NewName; string oldName = Texture.OriginalTextureId; _scene.UndoStack.PushAndDo("Rename Texture File", // Do () => renamer.RenameTexture(Texture, newName), // Undo () => renamer.RenameTexture(Texture, oldName), // Update () => { texCaptionLabel.Text = Path.GetFileName(Texture.OriginalTextureId); }); } } }