/// <summary> /// Create/Update a session entry /// </summary> /// <param name="sender">The toolstripmenuitem control that was clicked</param> /// <param name="e">An Empty EventArgs object</param> private void CreateOrEditSessionToolStripMenuItem_Click(object sender, EventArgs e) { SessionData session = null; TreeNode node = null; TreeNode nodeRef = nodeRoot; string title = null; if (sender is ToolStripMenuItem menuItem) { bool isFolderNode = IsFolderNode(treeView1.SelectedNode); if (menuItem.Text.ToLower().Equals("new") || isFolderNode) { session = new SessionData(); nodeRef = isFolderNode ? treeView1.SelectedNode : treeView1.SelectedNode.Parent; title = "Create New Session"; } else if (menuItem == createLikeToolStripMenuItem) { // copy as session = (SessionData)((SessionData)treeView1.SelectedNode.Tag).Clone(); session.SessionId = SuperPuTTY.MakeUniqueSessionId(session.SessionId); session.SessionName = SessionData.GetSessionNameFromId(session.SessionId); nodeRef = treeView1.SelectedNode.Parent; title = "Create New Session Like " + session.OldName; } else { // edit, session node selected // We make a clone of the session since we do not want to directly edit the real object. session = (SessionData)((SessionData)treeView1.SelectedNode.Tag).Clone(); node = treeView1.SelectedNode; nodeRef = node.Parent; title = "Edit Session: " + session.SessionName; } } EditSessionDialog form = new EditSessionDialog(session, treeView1.ImageList) { Text = title }; form.SessionNameValidator += delegate(string txt, out string error) { bool IsValid = ValidateSessionNameChange(nodeRef, node, txt, out error); return(IsValid); }; if (form.ShowDialog(this) == DialogResult.OK) { /* "node" will only be assigned if we're editing an existing session entry */ if (node == null) { // get the path up to the ref (parent) node if (nodeRoot != nodeRef) { UpdateSessionId(nodeRef, session); session.SessionId = SessionData.CombineSessionIds(session.SessionId, session.SessionName); } SuperPuTTY.AddSession(session); // find new node and select it TreeNode nodeNew = nodeRef.Nodes[session.SessionName]; if (nodeNew != null) { treeView1.SelectedNode = nodeNew; } } else { SessionData RealSession = (SessionData)treeView1.SelectedNode.Tag; RealSession.CopyFrom(session); RealSession.SessionName = session.SessionName; treeView1.SelectedNode = node; } //treeView1.ExpandAll(); SuperPuTTY.SaveSessions(); } }
public void SessionPropertyChanged(SessionData Session, String PropertyName) { if (Session == null) { return; } if (PropertyName == "SessionName" || PropertyName == "ImageKey") { TreeNode Node = FindSessionNode(Session.SessionId); if (Node == null) { // It is possible that the session id was changed before the // session name. In this case, we check to see if we // can find a node with the old session id that is also associated // to the session data. Node = FindSessionNode(Session.OldSessionId); if (Node == null || Node.Tag != Session) { return; } } Node.Text = Session.SessionName; Node.Name = Session.SessionName; Node.ImageKey = Session.ImageKey; Node.SelectedImageKey = Session.ImageKey; bool IsSelectedSession = treeView1.SelectedNode == Node; ResortNodes(); if (IsSelectedSession) { // Re-selecting the node since it will be unselected when sorting. treeView1.SelectedNode = Node; } } else if (PropertyName == "SessionId") { TreeNode Node = FindSessionNode(Session.OldSessionId); if (Node == null) { // It is possible that the session name was changed before the // session id. In this case, we check to see if we // can find a node with the current session id that is also associated // to the session data. Node = FindSessionNode(Session.SessionId); if (Node == null || Node.Tag != Session) { return; } } try { isRenamingNode = true; SuperPuTTY.RemoveSession(Session.OldSessionId); SuperPuTTY.AddSession(Session); } finally { isRenamingNode = false; } } }