/// <summary> /// Called when <see cref="IProtocolService.AsyncSSHConnect"/> is able to successfully establish the SSH connection. Creates a new /// <see cref="IPoderosaMainWindow"/> instance and points the newly created connection to a new document instance within that window. We then steal /// the <see cref="IContentReplaceableView"/> terminal window from Poderosa and set its parent to ourself, thus displaying the terminal within this /// control. /// </summary> /// <param name="result">Newly-created SSH connection.</param> public void SuccessfullyExit(ITerminalConnection result) { ICoreServices coreServices = (ICoreServices)_poderosaWorld.GetAdapter(typeof(ICoreServices)); IWindowManager windowManager = coreServices.WindowManager; // Wire up the event handlers on the newly-created connection. (result as ICloseableTerminalConnection).ConnectionClosed += TerminalControl_ConnectionClosed; (result as ICloseableTerminalConnection).ConnectionLost += TerminalControl_ConnectionLost; // We run all of this logic within an Invoke() to avoid trying to do this on the wrong GUI thread windowManager.MainWindows.First().AsForm().Invoke( new Action( () => { // Create a new Poderosa window to contain the connection terminal IPoderosaMainWindow window = windowManager.CreateNewWindow(new MainWindowArgument(ClientRectangle, FormWindowState.Normal, "", "", 1)); IViewManager viewManager = window.ViewManager; Sessions.TerminalSession session = new Sessions.TerminalSession(result, _settings); // Create a new connection window within the Poderosa window, which we will later steal IContentReplaceableView view = (IContentReplaceableView)viewManager.GetCandidateViewForNewDocument().GetAdapter(typeof(IContentReplaceableView)); coreServices.SessionManager.StartNewSession(session, view); session.TerminalControl.HideSizeTip = true; Form containerForm = view.ParentForm.AsForm(); // Hide all of the toolbar and statusbar chrome in the connection window and display only the terminal itself (it's a little // clumsy, I know) foreach (Control control in containerForm.Controls) { if (control is MenuStrip || control.GetType().Name == "PoderosaStatusBar") { control.Visible = false; } else if (control.GetType().Name == "PoderosaToolStripContainer") { foreach (ToolStripPanel child in control.Controls.OfType <ToolStripPanel>()) { child.Visible = false; } foreach (ToolStripContentPanel child in control.Controls.OfType <ToolStripContentPanel>()) { foreach (Control grandChild in child.Controls) { if (grandChild.GetType().Name != "TerminalControl") { grandChild.Visible = false; } } } } } // Steal the terminal view and display it within this control containerForm.TopLevel = false; containerForm.FormBorderStyle = FormBorderStyle.None; containerForm.Width = Width; containerForm.Height = Height; containerForm.Dock = DockStyle.Fill; containerForm.Parent = this; view.AsControl().Focus(); })); // Invoke the Connected event if (Connected != null) { Connected(this, new EventArgs()); } }