private void TreeClassView_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) { // detect right click on a valid member to popup a 'change name' box. if (e.Button == MouseButtons.Right && e.Node.Parent != null && e.Node.Parent.Parent != null) { ChangeName FChangeName = new ChangeName(); FChangeName.NameBox.Text = e.Node.Text; // get the full path of the node we clicked on, so we have all the information // relating to it // get parentmost node TreeNode pn = e.Node; while (pn.Parent != null) { pn = pn.Parent; } // get trailing node TreeNode tn = e.Node; while (tn.Nodes.Count > 0) { tn = tn.Nodes[0]; } string class_name = pn.Tag.ToString(); // classname string[] sl = tn.FullPath.Split('\\'); string type = sl[1]; string old_name = tn.Parent.Tag.ToString(); if (class_name == null || type == null || old_name == null) { return; } // check which subsection we are in, so we can add it to the right list if ((type == "Methods" || type == "Fields") && // section (FChangeName.ShowDialog() == DialogResult.OK)) { string old_descriptor = sl[3]; if (old_descriptor == null) return; if (type == "Methods") { RenameStore.AddRenameMethod(class_name, old_descriptor, old_name, old_descriptor, FChangeName.NameBox.Text); } else if (type == "Fields") { RenameStore.AddRenameField(class_name, old_descriptor, old_name, old_descriptor, FChangeName.NameBox.Text); } // update the tree without reloading it tn.Parent.Text = FChangeName.NameBox.Text; tn.Parent.ToolTipText = "was '" + tn.Parent.Tag.ToString() + "'"; tn.Parent.BackColor = Color.DodgerBlue; } } else if (e.Button == MouseButtons.Right && e.Node.Parent == null) { ChangeName FChangeName = new ChangeName(); string[] s = e.Node.Text.Split(':'); string old_name = s[0].Trim(); string old_descriptor = s[1].Trim(); if (s.Length == 0) return; FChangeName.NameBox.Text = old_name; // change the class name, since its a root node if (FChangeName.ShowDialog() == DialogResult.OK) { string new_name_and_type = FChangeName.NameBox.Text + " : " + old_descriptor; RenameStore.AddRenameClass(e.Node.Tag.ToString(), new_name_and_type); e.Node.BackColor = Color.DodgerBlue; e.Node.Text = new_name_and_type; e.Node.ToolTipText = "was '" + e.Node.Tag.ToString() + "'"; } } }
private void TreeClassView_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) { // detect right click on a valid member to popup a 'change name' box. if (e.Button == MouseButtons.Right && e.Node.Parent != null && e.Node.Parent.Parent != null) { ChangeName FChangeName = new ChangeName(); FChangeName.NameBox.Text = e.Node.Text; // get the full path of the node we clicked on, so we have all the information // relating to it // get parentmost node TreeNode pn = e.Node; while (pn.Parent != null) { pn = pn.Parent; } // get trailing node TreeNode tn = e.Node; while (tn.Nodes.Count > 0) { tn = tn.Nodes[0]; } string class_name = pn.Tag.ToString(); // classname string[] sl = tn.FullPath.Split('\\'); string type = sl[1]; string old_name = tn.Parent.Tag.ToString(); if (class_name == null || type == null || old_name == null) { return; } // check which subsection we are in, so we can add it to the right list if ((type == "Methods" || type == "Fields") && // section (FChangeName.ShowDialog() == DialogResult.OK)) { string old_descriptor = sl[3]; if (old_descriptor == null) { return; } if (type == "Methods") { RenameStore.AddRenameMethod(class_name, old_descriptor, old_name, old_descriptor, FChangeName.NameBox.Text); } else if (type == "Fields") { RenameStore.AddRenameField(class_name, old_descriptor, old_name, old_descriptor, FChangeName.NameBox.Text); } // update the tree without reloading it tn.Parent.Text = FChangeName.NameBox.Text; tn.Parent.ToolTipText = "was '" + tn.Parent.Tag.ToString() + "'"; tn.Parent.BackColor = Color.DodgerBlue; } } else if (e.Button == MouseButtons.Right && e.Node.Parent == null) { ChangeName FChangeName = new ChangeName(); string[] s = e.Node.Text.Split(':'); string old_name = s[0].Trim(); string old_descriptor = s[1].Trim(); if (s.Length == 0) { return; } FChangeName.NameBox.Text = old_name; // change the class name, since its a root node if (FChangeName.ShowDialog() == DialogResult.OK) { string new_name_and_type = FChangeName.NameBox.Text + " : " + old_descriptor; RenameStore.AddRenameClass(e.Node.Tag.ToString(), new_name_and_type); e.Node.BackColor = Color.DodgerBlue; e.Node.Text = new_name_and_type; e.Node.ToolTipText = "was '" + e.Node.Tag.ToString() + "'"; } } }