Inheritance: SuperPutty.ToolWindow
Example #1
0
        void WinEventProc(IntPtr hWinEventHook, uint eventType, IntPtr hwnd, int idObject, int idChild, uint dwEventThread, uint dwmsEventTime)
        {
            //Log.DebugFormat("eventType={0}, hwnd={1}", eventType, hwnd);
            if (eventType == (int)NativeMethods.WinEvents.EVENT_OBJECT_NAMECHANGE && hwnd == m_AppWin)
            {
                // Putty xterm chdir - apply to title
                UpdateTitle();
            }
            else if (eventType == (int)NativeMethods.WinEvents.EVENT_SYSTEM_SWITCHSTART)
            {
                this.isSwitchingViaAltTab = true;
            }
            else if (eventType == (int)NativeMethods.WinEvents.EVENT_SYSTEM_SWITCHEND)
            {
                this.isSwitchingViaAltTab = false;
            }
            else if (eventType == (int)NativeMethods.WinEvents.EVENT_SYSTEM_FOREGROUND && hwnd == m_AppWin)
            {
                // if we got the EVENT_SYSTEM_FOREGROUND, and the hwnd is the putty terminal hwnd (m_AppWin)
                // then bring the supperputty window to the foreground
                Log.DebugFormat("[{0}] HandlingForegroundEvent: settingFG={1}", hwnd, settingForeground);
                if (settingForeground)
                {
                    settingForeground = false;
                    return;
                }

                // This is the easiest way I found to get the superputty window to be brought to the top
                // if you leave TopMost = true; then the window will always be on top.
                if (this.TopLevelControl != null)
                {
                    Form form = SuperPuTTY.MainForm;
                    if (form.WindowState == FormWindowState.Minimized)
                    {
                        return;
                    }

                    DesktopWindow window = DesktopWindow.GetFirstDesktopWindow();
                    this.m_windowActivator.ActivateForm(form, window, hwnd);

                    // focus back to putty via setting active dock panel
                    ctlPuttyPanel parent = (ctlPuttyPanel)this.Parent;
                    if (parent != null && parent.DockPanel != null)
                    {
                        if (parent.DockPanel.ActiveDocument != parent && parent.DockState == DockState.Document)
                        {
                            string activeDoc = parent.DockPanel.ActiveDocument != null
                                ? ((ToolWindow)parent.DockPanel.ActiveDocument).Text : "?";
                            Log.InfoFormat("[{0}] Setting Active Document: {1} -> {2}", hwnd, activeDoc, parent.Text);
                            parent.Show();
                        }
                        else
                        {
                            // give focus back
                            this.ReFocusPuTTY("WinEventProc-FG, AltTab=" + isSwitchingViaAltTab);
                        }
                    }
                }
            }
        }
Example #2
0
        protected override void OnVisibleChanged(EventArgs e)
        {
            base.OnVisibleChanged(e);
            if (this.Visible)
            {
                // load docs into the ListView
                this.listViewDocs.Items.Clear();
                int i = 0;
                foreach (IDockContent doc in VisualOrderTabSwitchStrategy.GetDocuments(this.dockPanel))
                {
                    i++;
                    ctlPuttyPanel pp = doc as ctlPuttyPanel;
                    if (pp != null)
                    {
                        string       tabNum = pp == this.dockPanel.ActiveDocument ? i + "*" : i.ToString();
                        ListViewItem item   = this.listViewDocs.Items.Add(tabNum);
                        item.SubItems.Add(new ListViewItem.ListViewSubItem(item, pp.Text));
                        item.SubItems.Add(new ListViewItem.ListViewSubItem(item, pp.Session.SessionId));
                        item.SubItems.Add(new ListViewItem.ListViewSubItem(item, pp.GetHashCode().ToString()));

                        item.Selected = IsDocumentSelected(pp);
                        item.Tag      = pp;
                    }
                }
                this.BeginInvoke(new Action(delegate { this.listViewDocs.Focus(); }));
            }
        }
 public bool IsDocumentSelected(ctlPuttyPanel document)
 {
     bool selected = false;
     if (document != null && document.Session != null)
     {
         selected = this.checkSendToVisible.Checked ? document.Visible : document.AcceptCommands;
     }
     return selected;
 }
Example #4
0
        private void UpdateTitle()
        {
            ctlPuttyPanel panel  = (ctlPuttyPanel)this.Parent;
            int           length = NativeMethods.SendMessage(m_AppWin, NativeMethods.WM_GETTEXTLENGTH, 0, 0) + 1;
            StringBuilder sb     = new StringBuilder(length + 1);

            NativeMethods.SendMessage(m_AppWin, NativeMethods.WM_GETTEXT, sb.Capacity, sb);
            string controlText = sb.ToString();
            string parentText  = panel.TextOverride;

            switch ((SuperPutty.frmSuperPutty.TabTextBehavior)Enum.Parse(typeof(frmSuperPutty.TabTextBehavior), SuperPuTTY.Settings.TabTextBehavior))
            {
            case frmSuperPutty.TabTextBehavior.Static:
                this.Parent.Text = parentText;
                break;

            case frmSuperPutty.TabTextBehavior.Dynamic:
                this.Parent.Text = controlText;
                break;

            case frmSuperPutty.TabTextBehavior.Mixed:
                this.Parent.Text = parentText + ": " + controlText;
                break;
            }

            // putty/kitty tab became inactive
            if (!panel.inactive && controlText.EndsWith("TTY (inactive)"))
            {
                Icon   icon     = null;
                string imageKey = (SuperPuTTY.Images.Images.ContainsKey("dead")) ? "dead" : null;
                try
                {
                    Image  img = SuperPuTTY.Images.Images[imageKey];
                    Bitmap bmp = img as Bitmap;
                    if (bmp != null)
                    {
                        icon = Icon.FromHandle(bmp.GetHicon());
                    }
                }
                catch (Exception ex)
                {
                    Log.Error("Error getting icon for dead tab", ex);
                }
                panel.inactive = true;
                panel.Icon     = icon;
                panel.AdjustMenu();
                panel.Pane.Refresh();
            }
            else if (panel.inactive && !controlText.EndsWith("TTY (inactive)"))
            {
                panel.inactive = false;
                panel.Icon     = SuperPuTTY.GetIconForSession(panel.Session);
                panel.AdjustMenu();
                panel.Pane.Refresh();
            }
        }
Example #5
0
        public static ctlPuttyPanel FromPersistString(String persistString)
        {
            ctlPuttyPanel panel = null;

            if (persistString.StartsWith(typeof(ctlPuttyPanel).FullName))
            {
                int idx = persistString.IndexOf("?");
                if (idx != -1)
                {
                    NameValueCollection data = HttpUtility.ParseQueryString(persistString.Substring(idx + 1));
                    string sessionId         = data["SessionId"] ?? data["SessionName"];
                    string tabName           = data["TabName"];

                    Log.InfoFormat("Restoring putty session, sessionId={0}, tabName={1}", sessionId, tabName);

                    SessionData session = SuperPuTTY.GetSessionById(sessionId);
                    if (session != null)
                    {
                        panel = ctlPuttyPanel.NewPanel(session);
                        if (panel == null)
                        {
                            Log.WarnFormat("Could not restore putty session, sessionId={0}", sessionId);
                        }
                        else
                        {
                            panel.Icon         = SuperPuTTY.GetIconForSession(session);
                            panel.Text         = tabName;
                            panel.TextOverride = tabName;
                        }
                    }
                    else
                    {
                        Log.WarnFormat("Session not found, sessionId={0}", sessionId);
                    }
                }
                else
                {
                    idx = persistString.IndexOf(":");
                    if (idx != -1)
                    {
                        string sessionId = persistString.Substring(idx + 1);
                        Log.InfoFormat("Restoring putty session, sessionId={0}", sessionId);
                        SessionData session = SuperPuTTY.GetSessionById(sessionId);
                        if (session != null)
                        {
                            panel = ctlPuttyPanel.NewPanel(session);
                        }
                        else
                        {
                            Log.WarnFormat("Session not found, sessionId={0}", sessionId);
                        }
                    }
                }
            }
            return(panel);
        }
Example #6
0
 public void FocusCurrentTab()
 {
     dockPanel1.Refresh();
     if (dockPanel1.ActiveDocument is ctlPuttyPanel)
     {
         ctlPuttyPanel p = (ctlPuttyPanel)dockPanel1.ActiveDocument;
         SetPanelTitle(p);
         p.SetFocusToChildApplication();
     }
 }
Example #7
0
        public bool IsDocumentSelected(ctlPuttyPanel document)
        {
            bool selected = false;

            if (document != null && document.Session != null)
            {
                selected = this.checkSendToVisible.Checked ? document.Visible : document.AcceptCommands;
            }
            return(selected);
        }
Example #8
0
        public void SetPanelTitle(ctlPuttyPanel panel)
        {
            IntPtr        handle        = panel.GetChildHandle();
            int           capacity      = WinAPI.GetWindowTextLength(new HandleRef(this, handle)) * 2;
            StringBuilder stringBuilder = new StringBuilder(capacity);

            WinAPI.GetWindowText(new HandleRef(this, handle), stringBuilder, stringBuilder.Capacity);

            panel.TabText = stringBuilder.ToString();
            this.Text     = stringBuilder.ToString().Replace(" - PuTTY", "") + " - SuperPutty";
        }
Example #9
0
        /// <summary>
        /// Handles focusing on tabs/windows which host PuTTY
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dockPanel1_ActiveDocumentChanged(object sender, EventArgs e)
        {
            if (dockPanel1.ActiveDocument is ctlPuttyPanel)
            {
                ctlPuttyPanel p = (ctlPuttyPanel)dockPanel1.ActiveDocument;

                this.Text = p.ApplicationTitle.Replace(" - PuTTY", "") + " - SuperPutty";
                p.Text    = p.ApplicationTitle.Replace(" - PuTTY", "");
                p.SetFocusToChildApplication();
            }
        }
Example #10
0
 /// <summary>Open a new putty window with its settings being passed in a <seealso cref="SessionData"/> object</summary>
 /// <param name="session">The <seealso cref="SessionData"/> object containing the settings</param>
 public static void OpenPuttySession(SessionData session)
 {
     Log.InfoFormat("Opening putty session, id={0}", session == null ? "" : session.SessionId);
     if (session != null)
     {
         ctlPuttyPanel sessionPanel = ctlPuttyPanel.NewPanel(session);
         ApplyDockRestrictions(sessionPanel);
         ApplyIconForWindow(sessionPanel, session);
         sessionPanel.Show(MainForm.DockPanel, session.LastDockstate);
         SuperPuTTY.ReportStatus("Opened session: {0} [{1}]", session.SessionId, session.Proto);
     }
 }
Example #11
0
        void UpdateForeground()
        {
            // if we got the EVENT_SYSTEM_FOREGROUND, and the hwnd is the putty terminal hwnd (m_AppWin)
            // then bring the supperputty window to the foreground
            Log.DebugFormat("[{0}] HandlingForegroundEvent: settingFG={1}", m_AppWin, settingForeground);
            if (settingForeground)
            {
                settingForeground = false;
                return;
            }


            // This is the easiest way I found to get the superputty window to be brought to the top
            // if you leave TopMost = true; then the window will always be on top.
            if (this.TopLevelControl != null)
            {
                Form form = SuperPuTTY.MainForm;
                if (form.WindowState == FormWindowState.Minimized)
                {
                    return;
                }

                DesktopWindow window = DesktopWindow.GetFirstDesktopWindow();
                this.m_windowActivator.ActivateForm(form, window, m_AppWin);

                // focus back to putty via setting active dock panel
                ctlPuttyPanel parent = (ctlPuttyPanel)this.Parent;
                if (parent != null && parent.DockPanel != null)
                {
                    if (parent.DockPanel.ActiveDocument != parent && parent.DockState == DockState.Document)
                    {
                        string activeDoc = parent.DockPanel.ActiveDocument != null
                            ? ((ToolWindow)parent.DockPanel.ActiveDocument).Text : "?";
                        Log.InfoFormat("[{0}] Setting Active Document: {1} -> {2}", m_AppWin, activeDoc, parent.Text);
                        parent.Show();
                    }
                    else
                    {
                        // give focus back
                        this.ReFocusPuTTY("WinEventProc-FG, AltTab=" + isSwitchingViaAltTab);
                    }
                }
            }
        }
Example #12
0
        /// <summary>
        /// Opens the selected session when the node is double clicked in the treeview
        /// </summary>
        /// <param name="sender">The treeview control that was double clicked</param>
        /// <param name="e">An Empty EventArgs object</param>
        private void treeView1_DoubleClick(object sender, EventArgs e)
        {
            if (treeView1.SelectedNode.ImageIndex > 0)
            {
                SessionData   sessionData  = (SessionData)treeView1.SelectedNode.Tag;
                ctlPuttyPanel sessionPanel = null;

                // This is the callback fired when the panel containing the terminal is closed
                // We use this to save the last docking location
                PuttyClosedCallback callback = delegate(bool closed)
                {
                    if (sessionPanel != null)
                    {
                        // save the last dockstate (if it has been changed)
                        if (sessionData.LastDockstate != sessionPanel.DockState &&
                            sessionPanel.DockState != DockState.Unknown &&
                            sessionPanel.DockState != DockState.Hidden)
                        {
                            sessionData.LastDockstate = sessionPanel.DockState;
                            sessionData.SaveToRegistry();
                        }

                        if (sessionPanel.InvokeRequired)
                        {
                            this.BeginInvoke((MethodInvoker) delegate()
                            {
                                sessionPanel.Close();
                            });
                        }
                        else
                        {
                            sessionPanel.Close();
                        }
                    }
                };

                sessionPanel = new ctlPuttyPanel(sessionData, callback);
                sessionPanel.Show(m_DockPanel, sessionData.LastDockstate);
            }
        }
Example #13
0
        public void CreatePuttyPanel(SessionData sessionData, bool isPutty)
        {
            ctlPuttyPanel sessionPanel = null;

            // This is the callback fired when the panel containing the terminal is closed
            // We use this to save the last docking location
            PuttyClosedCallback callback = delegate(bool closed)
            {
                if (sessionPanel != null)
                {
                    // save the last dockstate (if it has been changed)
                    if (sessionData.LastDockstate != sessionPanel.DockState &&
                        sessionPanel.DockState != DockState.Unknown &&
                        sessionPanel.DockState != DockState.Hidden)
                    {
                        sessionData.LastDockstate = sessionPanel.DockState;
                        sessionData.SaveToRegistry();
                    }

                    if (sessionPanel.InvokeRequired)
                    {
                        this.BeginInvoke((MethodInvoker) delegate()
                        {
                            sessionPanel.Close();
                        });
                    }
                    else
                    {
                        sessionPanel.Close();
                    }
                }
            };

            sessionPanel = new ctlPuttyPanel(this, sessionData, callback, isPutty);
            sessionPanel.Show(dockPanel1, sessionData.LastDockstate);
            FocusCurrentTab();
        }
Example #14
0
        public static ctlPuttyPanel NewPanel(SessionData sessionData)
        {
            ctlPuttyPanel puttyPanel = null;
            // This is the callback fired when the panel containing the terminal is closed
            // We use this to save the last docking location
            PuttyClosedCallback callback = delegate(bool closed)
            {
                if (puttyPanel != null)
                {
                    // save the last dockstate (if it has been changed)
                    if (sessionData.LastDockstate != puttyPanel.DockState &&
                        puttyPanel.DockState != DockState.Unknown &&
                        puttyPanel.DockState != DockState.Hidden)
                    {
                        sessionData.LastDockstate = puttyPanel.DockState;
                        SuperPuTTY.SaveSessions();
                        //sessionData.SaveToRegistry();
                    }

                    if (puttyPanel.InvokeRequired)
                    {
                        puttyPanel.BeginInvoke((MethodInvoker) delegate()
                        {
                            puttyPanel.Close();
                        });
                    }
                    else
                    {
                        puttyPanel.Close();
                    }
                }
            };

            puttyPanel = new ctlPuttyPanel(sessionData, callback);
            return(puttyPanel);
        }
        /// <summary>
        /// Opens the selected session when the node is double clicked in the treeview
        /// </summary>
        /// <param name="sender">The treeview control that was double clicked</param>
        /// <param name="e">An Empty EventArgs object</param>
        private void treeView1_DoubleClick(object sender, EventArgs e)
        {
            if (treeView1.SelectedNode.ImageIndex > 0)
            {
                SessionData sessionData = (SessionData)treeView1.SelectedNode.Tag;
                ctlPuttyPanel sessionPanel = null;

                // This is the callback fired when the panel containing the terminal is closed
                // We use this to save the last docking location
                PuttyClosedCallback callback = delegate(bool closed)
                {
                    if (sessionPanel != null)
                    {
                        // save the last dockstate (if it has been changed)
                        if (sessionData.LastDockstate != sessionPanel.DockState
                            && sessionPanel.DockState != DockState.Unknown
                            && sessionPanel.DockState != DockState.Hidden)
                        {
                            sessionData.LastDockstate = sessionPanel.DockState;
                            sessionData.SaveToRegistry();
                        }

                        if (sessionPanel.InvokeRequired)
                        {
                            this.BeginInvoke((MethodInvoker)delegate()
                            {
                                sessionPanel.Close();
                            });
                        }
                        else
                        {
                            sessionPanel.Close();
                        }
                    }
                };

                sessionPanel = new ctlPuttyPanel(sessionData, callback);
                sessionPanel.Show(m_DockPanel, sessionData.LastDockstate);
            }
        }
Example #16
0
        public void SetPanelTitle(ctlPuttyPanel panel)
        {
            IntPtr handle = panel.GetChildHandle();
            int capacity = WinAPI.GetWindowTextLength(new HandleRef(this, handle)) * 2;
            StringBuilder stringBuilder = new StringBuilder(capacity);
            WinAPI.GetWindowText(new HandleRef(this, handle), stringBuilder, stringBuilder.Capacity);

            panel.TabText = stringBuilder.ToString();
            this.Text = stringBuilder.ToString().Replace(" - PuTTY", "") + " - SuperPutty";
        }
Example #17
0
 public bool IsActiveDocument(ctlPuttyPanel panel)
 {
     return(panel == (ctlPuttyPanel)dockPanel1.ActiveDocument);
 }
Example #18
0
        /// <summary>Open a new putty window with its settings being passed in a <seealso cref="SessionData"/> object</summary>
        /// <param name="session">The <seealso cref="SessionData"/> object containing the settings</param>
        public static ctlPuttyPanel OpenProtoSession(SessionData session)
        {
            Log.InfoFormat("Opening putty session, id={0}", session == null ? "" : session.SessionId);
            ctlPuttyPanel panel = null;

            if (session != null)
            {
                String Executable = PuttyStartInfo.GetExecutable(session);
                if (String.IsNullOrEmpty(Executable))
                {
                    MessageBox.Show("Error trying to create session: " + session.ToString() +
                                    "\nExecutable not set for " + session.Proto.ToString() + " protocol." +
                                    "\nGo to tools->options->General tab to set the path to the executable."
                                    , "Failed to create a session", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(null);
                }
                if (!File.Exists(Executable))
                {
                    MessageBox.Show("Error trying to create session: " + session.ToString() +
                                    "\nExecutable not found for " + session.Proto.ToString() + " protocol." +
                                    "\nThe path for the executable was set as \"" + Executable + "\"." +
                                    "\nGo to tools->options->General tab to set the path to the executable."
                                    , "Failed to create a session", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(null);
                }

                // This is the callback fired when the panel containing the terminal is closed
                // We use this to save the last docking location and to close the panel
                PuttyClosedCallback callback = delegate
                {
                    if (panel != null)
                    {
                        // save the last dockstate (if it has been changed)
                        if (session.LastDockstate != panel.DockState &&
                            panel.DockState != DockState.Unknown &&
                            panel.DockState != DockState.Hidden)
                        {
                            session.LastDockstate = panel.DockState;
                            SuperPuTTY.SaveSessions();
                        }

                        if (panel.InvokeRequired)
                        {
                            panel.BeginInvoke((MethodInvoker) delegate {
                                panel.Close();
                            });
                        }
                        else
                        {
                            panel.Close();
                        }
                    }
                };

                try {
                    panel = new ctlPuttyPanel(session, callback);

                    ApplyDockRestrictions(panel);
                    ApplyIconForWindow(panel, session);
                    panel.Show(MainForm.DockPanel, session.LastDockstate);
                    ReportStatus("Opened session: {0} [{1}]", session.SessionId, session.Proto);

                    if (!String.IsNullOrEmpty(session.SPSLFileName) &&
                        File.Exists(session.SPSLFileName))
                    {
                        ExecuteScriptEventArgs scriptArgs = new ExecuteScriptEventArgs()
                        {
                            Script = File.ReadAllText(session.SPSLFileName), Handle = panel.AppPanel.AppWindowHandle
                        };
                        if (!String.IsNullOrEmpty(scriptArgs.Script))
                        {
                            SPSL.BeginExecuteScript(scriptArgs);
                        }
                    }
                } catch (InvalidOperationException ex)
                {
                    MessageBox.Show("Error trying to create session " + ex.Message, "Failed to create session panel", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            return(panel);
        }
Example #19
0
        public static ctlPuttyPanel NewPanel(SessionData sessionData)
        {
            ctlPuttyPanel puttyPanel = null;
            // This is the callback fired when the panel containing the terminal is closed
            // We use this to save the last docking location
            PuttyClosedCallback callback = delegate(bool closed)
            {
                if (puttyPanel != null)
                {
                    // save the last dockstate (if it has been changed)
                    if (sessionData.LastDockstate != puttyPanel.DockState
                        && puttyPanel.DockState != DockState.Unknown
                        && puttyPanel.DockState != DockState.Hidden)
                    {
                        sessionData.LastDockstate = puttyPanel.DockState;
                        SuperPuTTY.SaveSessions();
                        //sessionData.SaveToRegistry();
                    }

                    if (puttyPanel.InvokeRequired)
                    {
                        puttyPanel.BeginInvoke((MethodInvoker)delegate()
                        {
                            puttyPanel.Close();
                        });
                    }
                    else
                    {
                        puttyPanel.Close();
                    }
                }
            };
            puttyPanel = new ctlPuttyPanel(sessionData, callback);
            return puttyPanel;
        }
Example #20
0
        /// <summary>Open a new putty window with its settings being passed in a <seealso cref="SessionData"/> object</summary>
        /// <param name="session">The <seealso cref="SessionData"/> object containing the settings</param>
        public static ctlPuttyPanel OpenPuttySession(SessionData session)
        {
            Log.InfoFormat("Opening putty session, id={0}", session == null ? "" : session.SessionId);
            ctlPuttyPanel panel = null;
            if (session != null)
            {
                // This is the callback fired when the panel containing the terminal is closed
                // We use this to save the last docking location and to close the panel
                PuttyClosedCallback callback = delegate
                {
                    if (panel != null)
                    {
                        // save the last dockstate (if it has been changed)
                        if (session.LastDockstate != panel.DockState
                            && panel.DockState != DockState.Unknown
                            && panel.DockState != DockState.Hidden)
                        {
                            session.LastDockstate = panel.DockState;
                            SuperPuTTY.SaveSessions();
                        }

                        if (panel.InvokeRequired)
                        {
                            panel.BeginInvoke((MethodInvoker)delegate {
                                panel.Close();
                            });
                        }
                        else
                        {
                            panel.Close();
                        }
                    }
                };

                try {
                    panel = new ctlPuttyPanel(session, callback);

                    ApplyDockRestrictions(panel);
                    ApplyIconForWindow(panel, session);
                    panel.Show(MainForm.DockPanel, session.LastDockstate);
                    ReportStatus("Opened session: {0} [{1}]", session.SessionId, session.Proto);

                    if (!String.IsNullOrEmpty(session.SPSLFileName)
                        && File.Exists(session.SPSLFileName))
                    {
                        ExecuteScriptEventArgs scriptArgs = new ExecuteScriptEventArgs() { Script = File.ReadAllText(session.SPSLFileName), Handle = panel.AppPanel.AppWindowHandle };
                        if (!String.IsNullOrEmpty(scriptArgs.Script))
                        {
                            SPSL.BeginExecuteScript(scriptArgs);
                        }
                    }
                } catch (InvalidOperationException ex)
                {
                    MessageBox.Show("Error trying to create session " + ex.Message, "Failed to create session panel", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            return panel;
        }
Example #21
0
 public void AddChild(ctlPuttyPanel panel, IntPtr handle)
 {
     AddChild(handle);
     m_panelMapping.TryAdd(handle, panel);
 }
Example #22
0
        public void CreatePuttyPanel(SessionData sessionData)
        {
            ctlPuttyPanel sessionPanel = null;

            // This is the callback fired when the panel containing the terminal is closed
            // We use this to save the last docking location
            PuttyClosedCallback callback = delegate(bool closed)
            {
                if (sessionPanel != null)
                {
                    // save the last dockstate (if it has been changed)
                    if (sessionData.LastDockstate != sessionPanel.DockState
                        && sessionPanel.DockState != DockState.Unknown
                        && sessionPanel.DockState != DockState.Hidden)
                    {
                        sessionData.LastDockstate = sessionPanel.DockState;
                        sessionData.SaveToRegistry();
                    }

                    if (sessionPanel.InvokeRequired)
                    {
                        this.BeginInvoke((MethodInvoker)delegate()
                        {
                            sessionPanel.Close();
                         });
                    }
                    else
                    {
                        sessionPanel.Close();
                    }
                }
            };

            sessionPanel = new ctlPuttyPanel(sessionData, callback);
            sessionPanel.Show(dockPanel1, sessionData.LastDockstate);
        }
Example #23
0
 public void AddChild(ctlPuttyPanel panel, IntPtr handle)
 {
     AddChild(handle);
     m_panelMapping.TryAdd(handle, panel);
 }
Example #24
0
 public bool IsActiveDocument(ctlPuttyPanel panel)
 {
     return panel == (ctlPuttyPanel)dockPanel1.ActiveDocument;
 }
Example #25
0
        /// <summary>Open a new putty window with its settings being passed in a <seealso cref="SessionData"/> object</summary>
        /// <param name="session">The <seealso cref="SessionData"/> object containing the settings</param>
        public static ctlPuttyPanel OpenProtoSession(SessionData session)
        {
            Log.InfoFormat("Opening putty session, id={0}", session == null ? "" : session.SessionId);
            ctlPuttyPanel panel = null;

            if (session != null)
            {
                String Executable = PuttyStartInfo.GetExecutable(session);
                if (String.IsNullOrEmpty(Executable))
                {
                    MessageBox.Show("Error trying to create session: " + session.ToString() +
                                    "\nExecutable not set for " + session.Proto.ToString() + " protocol." +
                                    "\nGo to tools->options->General tab to set the path to the executable."
                                    , "Failed to create a session", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(null);
                }
                if (!File.Exists(Executable))
                {
                    MessageBox.Show("Error trying to create session: " + session.ToString() +
                                    "\nExecutable not found for " + session.Proto.ToString() + " protocol." +
                                    "\nThe path for the executable was set as \"" + Executable + "\"." +
                                    "\nGo to tools->options->General tab to set the path to the executable."
                                    , "Failed to create a session", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(null);
                }

                // This is the callback fired when the panel containing the terminal is closed
                // We use this to save the last docking location and to close the panel
                PuttyClosedCallback callback = delegate
                {
                    if (panel != null)
                    {
                        // save the last dockstate (if it has been changed)
                        if (session.LastDockstate != panel.DockState &&
                            panel.DockState != DockState.Unknown &&
                            panel.DockState != DockState.Hidden)
                        {
                            session.LastDockstate = panel.DockState;
                            SuperPuTTY.SaveSessions();
                        }

                        if (panel.InvokeRequired)
                        {
                            panel.BeginInvoke((MethodInvoker) delegate {
                                panel.Close();
                            });
                        }
                        else
                        {
                            panel.Close();
                        }
                    }
                };

                try {
                    panel = new ctlPuttyPanel(session, callback);

                    ApplyDockRestrictions(panel);
                    ApplyIconForWindow(panel, session);
                    panel.Show(MainForm.DockPanel, session.LastDockstate);
                    ReportStatus("Opened session: {0} [{1}]", session.SessionId, session.Proto);

                    if (!String.IsNullOrWhiteSpace(session.SPSLFileName))
                    {
                        String fileName = session.SPSLFileName;
                        String script   = String.Empty;

                        if (Regex.IsMatch(fileName, @"^https?:\/\/", RegexOptions.IgnoreCase))
                        {
                            try
                            {
                                HttpWebRequest req      = WebRequest.CreateHttp(fileName);
                                var            response = req.GetResponse();
                                using (var stream = new StreamReader(response.GetResponseStream()))
                                {
                                    script = stream.ReadToEnd();
                                }
                            }
                            catch (Exception)
                            {
                                script = String.Empty;
                            }
                        }
                        else
                        {
                            if (fileName.StartsWith("file://", StringComparison.OrdinalIgnoreCase))
                            {
                                fileName = fileName.Substring("file://".Length);
                            }

                            if (File.Exists(fileName))
                            {
                                script = File.ReadAllText(fileName);
                            }
                        }

                        if (!String.IsNullOrEmpty(script))
                        {
                            ExecuteScriptEventArgs scriptArgs = new ExecuteScriptEventArgs()
                            {
                                Script = script, Handle = panel.AppPanel.AppWindowHandle
                            };
                            SPSL.BeginExecuteScript(scriptArgs);
                        }
                    }
                } catch (InvalidOperationException ex)
                {
                    MessageBox.Show("Error trying to create session " + ex.Message, "Failed to create session panel", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            return(panel);
        }