Пример #1
0
        private void removeFolderToolStripMenuItem_Click(object sender, EventArgs e)
        {
            TreeNode node = treeView1.SelectedNode;

            if (node != null)
            {
                if (node.Nodes.Count > 0)
                {
                    List <SessionData> sessions = new List <SessionData>();
                    GetAllSessions(node, sessions);
                    if (DialogResult.Yes == MessageBox.Show(
                            "Remove Folder [" + node.Text + "] and [" + sessions.Count + "] sessions?",
                            "Remove Folder?",
                            MessageBoxButtons.YesNo))
                    {
                        foreach (SessionData session in sessions)
                        {
                            SuperPuTTY.RemoveSession(session.SessionId);
                        }
                        node.Remove();
                        SuperPuTTY.ReportStatus("Removed Folder, {0} and {1} sessions", node.Text, sessions.Count);
                        SuperPuTTY.SaveSessions();
                    }
                }
                else
                {
                    node.Remove();
                    SuperPuTTY.ReportStatus("Removed Folder, {0}", node.Text);
                }
            }
        }
Пример #2
0
        private void renameToolStripMenuItem_Click(object sender, EventArgs e)
        {
            TreeNode node = treeView1.SelectedNode;

            if (node != null)
            {
                dlgRenameItem dialog = new dlgRenameItem
                {
                    Text              = "Rename Folder",
                    ItemName          = node.Text,
                    DetailName        = "",
                    ItemNameValidator = delegate(string txt, out string error)
                    {
                        error = String.Empty;
                        if (node.Parent.Nodes.ContainsKey(txt) && txt != node.Text)
                        {
                            error = "Node with same name exists";
                        }
                        else if (txt.Contains(SessionIdDelim))
                        {
                            error = "Invalid character ( " + SessionIdDelim + " ) in name";
                        }
                        return(string.IsNullOrEmpty(error));
                    }
                };
                if (dialog.ShowDialog(this) == DialogResult.OK && node.Text != dialog.ItemName)
                {
                    node.Text = dialog.ItemName;
                    node.Name = dialog.ItemName;
                    UpdateSessionId(node);
                    SuperPuTTY.SaveSessions();
                    ResortNodes();
                }
            }
        }
Пример #3
0
        private void timerDelayedSave_Tick(object sender, EventArgs e)
        {
            // stop timer
            timerDelayedSave.Stop();

            // do save
            SuperPuTTY.SaveSessions();
            SuperPuTTY.ReportStatus("Saved Sessions after Drag-Drop @ {0}", DateTime.Now);
        }
Пример #4
0
        /// <summary>
        /// Delete a session entry from the treeview and the registry
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SessionData session = (SessionData)treeView1.SelectedNode.Tag;

            if (MessageBox.Show("Are you sure you want to delete " + session.SessionName + "?", "Delete Session?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                //session.RegistryRemove(session.SessionName);
                treeView1.SelectedNode.Remove();
                SuperPuTTY.RemoveSession(session.SessionId);
                SuperPuTTY.SaveSessions();
                //m_SessionsById.Remove(session.SessionId);
            }
        }
Пример #5
0
        private void sessionDetailPropertyGrid_PropertyValueChanged(object s, PropertyValueChangedEventArgs e)
        {
            if (sessionDetailPropertyGrid.SelectedObject is SessionData Session)
            {
                String HostPropertyName         = "Host";
                String PuttySessionPropertyName = "PuttySession";
                if (e.ChangedItem.PropertyDescriptor?.Name == HostPropertyName || e.ChangedItem.PropertyDescriptor?.Name == PuttySessionPropertyName)
                {
                    if (String.IsNullOrEmpty(Session.PuttySession) && String.IsNullOrEmpty(Session.Host))
                    {
                        if (e.ChangedItem.PropertyDescriptor.Name == HostPropertyName)
                        {
                            MessageBox.Show(LocalizedText.SessionDetail_sessionDetailPropertyGrid_PropertyValueChanged_A_host_name_must_be_specified_if_a_Putty_Session_Profile_is_not_selected);
                            Session.Host = (String)e.OldValue;
                        }
                        else
                        {
                            MessageBox.Show(LocalizedText.SessionDetail_sessionDetailPropertyGrid_PropertyValueChanged_A_Putty_Session_Profile_must_be_selected_if_a_Host_Name_is_not_provided);
                            Session.PuttySession = (String)e.OldValue;
                        }
                        sessionDetailPropertyGrid.Refresh();
                    }
                }


                String ExtraArgsPropertyName = "ExtraArgs";
                if (e.ChangedItem.PropertyDescriptor?.Name == ExtraArgsPropertyName)
                {
                    if (!String.IsNullOrEmpty(CommandLineOptions.getcommand(Session.ExtraArgs, "-pw")))
                    {
                        if (MessageBox.Show(LocalizedText.SessionDetail_sessionDetailPropertyGrid_PropertyValueChanged_, LocalizedText.SessionDetail_sessionDetailPropertyGrid_PropertyValueChanged_Are_you_sure_that_you_want_to_save_the_password_,
                                            MessageBoxButtons.OKCancel,
                                            MessageBoxIcon.Warning,
                                            MessageBoxDefaultButton.Button1) == DialogResult.Cancel)
                        {
                            Session.ExtraArgs = (String)e.OldValue;
                            return;
                        }
                    }
                    sessionDetailPropertyGrid.Refresh();
                }


                Session.SessionId = SessionData.CombineSessionIds(SessionData.GetSessionParentId(Session.SessionId), Session.SessionName);
            }
            SuperPuTTY.SaveSessions();
        }
Пример #6
0
        /// <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();
            }
        }