private void renameToolStripMenuItem_Click(object sender, EventArgs e) { // Get the session Session s = getSelectedSession(true); // Check we are not renaming the default session Session defaultSession = getSessionController().findDefaultSession(); if (defaultSession != null && defaultSession.Equals(s)) { MessageBox.Show("Cannot rename the default session" , "Alert", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // Display the rename requester RenameNameForm rnf = new RenameNameForm(s.SessionDisplayText, s.IsFolder); if (rnf.ShowDialog() == DialogResult.OK) { // Get the new name string newName = rnf.getName(); // Find the selected node TreeNode selectedNode = treeView.SelectedNode; // Find it's parent TreeNode parent = selectedNode.Parent; // Create the new session object Session newSession = null; if (s.IsFolder == false) { if (validateSessionName(newName)) { // Try to rename the session bool result = getSessionController().renameSession(s, newName, this); // Check it worked if (result == false) { MessageBox.Show("Failed to rename session" , "Alert", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // Create the new session object newSession = getSessionController().findSessionByName(newName); } } else if (s.IsFolder == true) { // Get the new folder name and the new full path string newPath = parent.FullPath + treeView.PathSeparator + newName; if (validateFolderName(newName, newPath)) { // Set up the new folder session newSession = new Session(newName, newPath, true); } } if ( newSession != null ) { // Suppress repainting the TreeView until all the objects have been created. treeView.BeginUpdate(); selectedNode.Tag = newSession; selectedNode.Text = newSession.SessionDisplayText; selectedNode.Name = newSession.NodeKey; if (newSession.IsFolder) { // Refresh the paths of all the child nodes updateFolders(selectedNode, parent); } // Fire a refresh event sc.invalidateSessionList(this, false); // Begin repainting the TreeView. treeView.EndUpdate(); } } }
private void newFolderMenuItem_Click(object sender, EventArgs e) { RenameNameForm ff = new RenameNameForm("",true); if (ff.ShowDialog() == DialogResult.OK) { // Find the selected node TreeNode selectedNode = treeView.SelectedNode; // Find it's parent TreeNode parent = selectedNode.Parent; // Get the new folder name and the new full path string folder = ff.getName(); string newpath = parent.FullPath + treeView.PathSeparator + folder; // Check the new folder name is valid if (validateFolderName(folder, newpath) == false) { return; } // Suppress repainting the TreeView until all the objects have been created. treeView.BeginUpdate(); // Remove the selected node from it's current location parent.Nodes.Remove(selectedNode); // Set up the new folder node and add it to the parent node Session sess = new Session(folder, newpath, true); // Create the folder node TreeNode foldernode = createNode(sess); // Add the selected node back to the folder foldernode.Nodes.Add(selectedNode); // Now add the node to the parent parent.Nodes.Add(foldernode); // Refresh the paths of all the child nodes updateFolders(selectedNode, foldernode); // Fire a refresh event sc.invalidateSessionList(this, false); // Begin repainting the TreeView. treeView.EndUpdate(); } }