protected void frmConsole_FormClosing(object sender, FormClosingEventArgs e) { if (e.CloseReason == CloseReason.UserClosing) { e.Cancel = true; if (_IsInputing) { if (MessageBox.Show($"Closing this window will dispose {ParentConsoleDevice.Title}" + $" and cancel input for {IsBusyInputtingBy}. Continue?", "Warning about IO device dispose" , MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1) != DialogResult.OK) { return; } _InputCancelled = true; _DisposeAfterInput = true; _IsInputing = false; } else { ParentConsoleDevice.Dispose(); } } }
protected void cmnDisplay_Opening(object sender, System.ComponentModel.CancelEventArgs e) { cmnDisplay.Items.Clear(); if (IsBusyInputting) { cmnDisplay.Items.Add(new ToolStripMenuItem ($"Input To {(IsBusyInputtingBy as IIdeComponent)?.ParentIDE.Machine ?? IsBusyInputtingBy}", null, (_s, _e) => { ParentConsoleDevice.ParentWorkplace.MainFormActivate(); ParentConsoleDevice.ParentWorkplace.MainFormSelectIDE((IsBusyInputtingBy as IIdeComponent)?.ParentIDE); }) { ToolTipText = $"The Console Device is busy inputting {InputtingForLength} bytes {(IsBusyInputtingBy is IInputPort ? $"for {(IsBusyInputtingBy as IInputPort).InputConverting}" : "")} by {IsBusyInputtingBy}" }); cmnDisplay.Items.Add("-"); } cmnDisplay.Items.Add("Scroll To Begin", null, (_s, _e) => { this.BeginInvoke(new Action(() => { rtbDisplay.SelectionStart = 0; rtbDisplay.ScrollToCaret(); })); }); cmnDisplay.Items.Add("Scroll To The End", null, (_s, _e) => { this.BeginInvoke(new Action(() => { rtbDisplay.SelectionStart = rtbDisplay.TextLength; rtbDisplay.ScrollToCaret(); })); }); cmnDisplay.Items.Add(new ToolStripMenuItem ("Auto Scroll To The End", null, (_s, _e) => { bool isAutoScroll = (_s as ToolStripMenuItem).Checked; (_s as ToolStripMenuItem).Checked = !isAutoScroll; ParentConsoleDevice.AutoScrollDisplayToEnd = !isAutoScroll; }) { Checked = ParentConsoleDevice.AutoScrollDisplayToEnd }); cmnDisplay.Items.Add("Clear Display", null, (_s, _e) => { this.BeginInvoke(new Action(() => { rtbDisplay.Clear(); })); }); cmnDisplay.Items.Add("-"); cmnDisplay.Items.Add(new ToolStripMenuItem ("Color Data Clients", null, (_s, _e) => { bool colored = (_s as ToolStripMenuItem).Checked; (_s as ToolStripMenuItem).Checked = !colored; ParentConsoleDevice.ColorDataClients = !colored; }) { Checked = ParentConsoleDevice.ColorDataClients }); cmnDisplay.Items.Add("-"); cmnDisplay.Items.Add(new ToolStripMenuItem("Initialized By:") { Enabled = false }); cmnDisplay.Items.Add(new ToolStripMenuItem (ParentConsoleDevice.InitializedBy.ToString(), null, (_s, _e) => { ParentConsoleDevice.ParentWorkplace.MainFormActivate(); ParentConsoleDevice.ParentWorkplace.MainFormSelectIDE((ParentConsoleDevice.InitializedBy as IIdeComponent)?.ParentIDE); }) { BackColor = System.Drawing.Color.FromArgb(255, 10, 10, 10), ForeColor = System.Drawing.Color.White }); if ((DataClients?.Count ?? -1) > 0) { cmnDisplay.Items.Add("-"); cmnDisplay.Items.Add(new ToolStripMenuItem("Data Clients:") { Enabled = false }); foreach (object key in DataClients.Keys) { cmnDisplay.Items.Add(new ToolStripMenuItem (key.ToString(), null, (_s, _e) => { ParentConsoleDevice.ParentWorkplace.MainFormActivate(); ParentConsoleDevice.ParentWorkplace.MainFormSelectIDE(((_s as ToolStripMenuItem)?.Tag as IIdeComponent)?.ParentIDE); }) { Tag = key, BackColor = System.Drawing.Color.FromArgb(255, 10, 10, 10), ForeColor = DataClientsColors[(int)DataClients[key]] }); } cmnDisplay.Items.Add("Clear Data Clients List", null, (_s, _e) => { this.BeginInvoke(new Action(() => { ParentConsoleDevice.ClearDataClientsList(); })); }); } }
protected string _Input(object sender, int length) { string inData; if (!this.IsDisposed) { IsBusyInputting = true; IsBusyInputtingBy = sender; InputtingForLength = length; _PreText = rtbDisplay.Text; _PreRtf = rtbDisplay.Rtf; rtbDisplay.ReadOnly = false; rtbDisplay.TextChanged += rtbDisplay_TextChanged; rtbDisplay.KeyDown += rtbDisplay_KeyDown; rtbDisplay.SelectionStart = rtbDisplay.TextLength; rtbDisplay.SelectionLength = 0; PostMessage(rtbDisplay.Handle, WM_VSCROLL, (IntPtr)SB_BOTTOM, IntPtr.Zero); _IsInputing = true; _InputCancelled = false; _DisposeAfterInput = false; IVirtualMachine senderMachine = (sender as IInputPort)?.ParentIDE.Machine ?? sender as IVirtualMachine; while (_IsInputing && !_InputCancelled && !(senderMachine?.Status == VirtualMachineRunningStatus.Breaking || senderMachine?.Status == VirtualMachineRunningStatus.StandBy || senderMachine?.Status == VirtualMachineRunningStatus.Paused) && !(senderMachine?.RunningTask.Status == TaskStatus.Canceled || senderMachine?.RunningTask.Status == TaskStatus.RanToCompletion || senderMachine?.RunningTask.Status == TaskStatus.Faulted)) { Application.DoEvents(); Thread.Yield(); } _IsInputing = false; if (!_InputCancelled && !(senderMachine?.Status == VirtualMachineRunningStatus.Breaking)) { inData = rtbDisplay.Text.Substring(_PreText.Length); } else { Display.Rtf = _PreRtf; inData = null; } rtbDisplay.ReadOnly = true; rtbDisplay.TextChanged -= rtbDisplay_TextChanged; rtbDisplay.KeyDown -= rtbDisplay_KeyDown; if (ParentConsoleDevice.AutoScrollDisplayToEnd) { PostMessage(rtbDisplay.Handle, WM_VSCROLL, (IntPtr)SB_BOTTOM, IntPtr.Zero); } IsBusyInputting = false; IsBusyInputtingBy = null; InputtingForLength = -1; if (_DisposeAfterInput) { ParentConsoleDevice.Dispose(); } } else { inData = null; } _CheckDisplayParameters(); return(inData); }