private void OnRenameNode(object sender, EventArgs e) { var node = GetTreeNodeForContextMenuEvent(sender); if (node == null || (node.Tag as Node) == null) { return; } var sceneNode = (Node)node.Tag; SafeRenamer renamer = new SafeRenamer(_scene); HashSet <string> greylist = renamer.GetAllMeshNames(); greylist.UnionWith(renamer.GetAllMaterialNames()); greylist.UnionWith(renamer.GetAllAnimationNames()); RenameDialog dialog = new RenameDialog(sceneNode.Name, renamer.GetAllNodeNames(), greylist); if (dialog.ShowDialog() == DialogResult.OK) { string newName = dialog.NewName; string oldName = sceneNode.Name; _scene.UndoStack.PushAndDo("Rename Node", () => { renamer.RenameNode(sceneNode, newName); node.Text = newName; }, () => { renamer.RenameNode(sceneNode, oldName); node.Text = oldName; }); } }
private void OnRenameAnimation(object sender, EventArgs e) { if (ActiveRawAnimation == null) { return; } Animation animation = ActiveRawAnimation; SafeRenamer renamer = new SafeRenamer(_scene); // Animations names need not be unique even amongst themselves, but it's good if they are. // Put all names in the entire scene into the greylist. RenameDialog dialog = new RenameDialog(animation.Name, new HashSet <string>(), renamer.GetAllAnimationNames()); if (dialog.ShowDialog() == DialogResult.OK) { string newName = dialog.NewName; string oldName = animation.Name; _scene.UndoStack.PushAndDo("Rename Animation", // Do () => renamer.RenameAnimation(animation, newName), // Undo () => renamer.RenameAnimation(animation, oldName), // Update () => listBoxAnimations.Items[FindAnimationIndex(animation) + 1] = FormatAnimationName(animation)); } }
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); }); } } }
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 OnRenameNode(object sender, EventArgs e) { var node = GetTreeNodeForContextMenuEvent(sender); if (node == null || (node.Tag as Node) == null) { return; } var sceneNode = (Node)node.Tag; SafeRenamer renamer = new SafeRenamer(_scene); HashSet<string> greylist = renamer.GetAllMeshNames(); greylist.UnionWith(renamer.GetAllMaterialNames()); greylist.UnionWith(renamer.GetAllAnimationNames()); RenameDialog dialog = new RenameDialog(sceneNode.Name, renamer.GetAllNodeNames(), greylist); if (dialog.ShowDialog() == DialogResult.OK) { string newName = dialog.NewName; string oldName = sceneNode.Name; _scene.UndoStack.PushAndDo("Rename Node", () => { renamer.RenameNode(sceneNode, newName); node.Text = newName; }, () => { renamer.RenameNode(sceneNode, oldName); node.Text = oldName; }); } }
private void OnRenameAnimation(object sender, EventArgs e) { if (ActiveRawAnimation == null) { return; } Animation animation = ActiveRawAnimation; SafeRenamer renamer = new SafeRenamer(_scene); // Animations names need not be unique even amongst themselves, but it's good if they are. // Put all names in the entire scene into the greylist. RenameDialog dialog = new RenameDialog(animation.Name, new HashSet<string>(), renamer.GetAllAnimationNames()); if (dialog.ShowDialog() == DialogResult.OK) { string newName = dialog.NewName; string oldName = animation.Name; _scene.UndoStack.PushAndDo("Rename Animation", // Do () => renamer.RenameAnimation(animation, newName), // Undo () => renamer.RenameAnimation(animation, oldName), // Update () => listBoxAnimations.Items[FindAnimationIndex(animation) + 1] = FormatAnimationName(animation)); } }