/// <summary> /// Raises the <see cref="E:Command" /> event. /// </summary> /// <param name="e">The <see cref="BaseShellConsoleCommandEventArgs"/> instance containing the event data.</param> protected virtual void OnCommand(BaseShellConsoleCommandEventArgs e) { if (Command != null) { Command(this, e); } }
/// <summary> /// Handles the Command event of the BaseShellConsoleEditor1 control, and execute the command received. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="BaseShellConsoleCommandEventArgs"/> instance containing the event data.</param> private void BaseShellConsoleEditor_Command(object sender, BaseShellConsoleCommandEventArgs e) { if (e.Command == "cls") { BaseShellConsoleEditor.ClearMessages(); e.Cancel = true; return; } ExecuteScript(e.Command); }
/// <summary> /// Handles the KeyDown event of the txtInput control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="KeyEventArgs"/> instance containing the event data.</param> private void txtInput_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Return) { if (!string.IsNullOrEmpty(txtInput.Text)) { SuspendLayout(); string prevPrompt = lblPrompt.Text; Color prevPromptColor = PromptColor; // Add the command first if (rtbMessages.Lines.Length > 0) { rtbMessages.AppendText(Environment.NewLine); } AddCommand(prevPrompt, prevPromptColor, txtInput.Text); // Raise the command event BaseShellConsoleCommandEventArgs args = new BaseShellConsoleCommandEventArgs(txtInput.Text); OnCommand(args); if (args.Cancel == false) { if (!string.IsNullOrEmpty(args.Message)) { AddMessage(args.Message); } rtbMessages.ScrollToCaret(); _prevMessages.Add(txtInput.Text); _currentLine = _prevMessages.Count - 1; } txtInput.Text = string.Empty; ResumeLayout(); } e.Handled = true; return; } if (e.KeyCode == Keys.Up) { // Shows the previous executed command if (_currentLine >= 0 && _prevMessages.Count > 0) { txtInput.Text = _prevMessages[_currentLine].ToString(); txtInput.SelectionLength = 0; txtInput.SelectionStart = txtInput.Text.Length; _currentLine--; } e.Handled = true; return; } if (e.KeyCode == Keys.Down) { // Shows the next executed command if (_currentLine < _prevMessages.Count - 2) { _currentLine++; txtInput.Text = _prevMessages[_currentLine + 1].ToString(); txtInput.SelectionLength = 0; txtInput.SelectionStart = txtInput.Text.Length; } e.Handled = true; return; } if (e.KeyCode == Keys.Escape) { // Clear the txtInput. txtInput.Text = string.Empty; e.Handled = true; } }