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); } } } } }
/// <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); } }
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); } } } }
/// <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); } }
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(); }
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); }
/// <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; }
/// <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); }
/// <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); } }
/// <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); }