private void richTextBox1_PreviewKeyDown(object sender, KeyEventArgs e) { if (lstOptions.Visibility == Visibility.Visible) { lstOptions.Focus(); return; } if (!IsCaretPositionValid()) { this.richTextBox1.CaretPosition = this.richTextBox1.CaretPosition.DocumentEnd; return; } if (e.Key == Key.Space) { var command = new TextRange(richTextBox1.CaretPosition.GetLineStartPosition(0), richTextBox1.CaretPosition).Text; command = command.Substring(command.IndexOf(">") + 1).Trim(); ShowOptions(command); return; } if (e.Key == Key.Enter) { var command = GetCommand(); RunCommand(command); e.Handled = true; } else if (e.Key == Key.Up) { GetCommand(--commandIdx); e.Handled = true; } else if (e.Key == Key.Down) { GetCommand(++commandIdx); e.Handled = true; } else if (e.Key == Key.Escape) { ChangePrompt("", new SolidColorBrush(Colors.Black)); lstOptions.Visibility = Visibility.Collapsed; } else if (e.Key == Key.Back) { var text = new TextRange(richTextBox1.CaretPosition.GetLineStartPosition(0), richTextBox1.CaretPosition).Text; if (text.EndsWith(">")) { e.Handled = true; } } }
public static string Rtb_GetContent(RichTextBox textBox) { string text_str = new TextRange(textBox.Document.ContentStart, textBox.Document.ContentEnd).Text; if (text_str.EndsWith("\r\n")) { text_str = text_str.Substring(0, text_str.Length - 2); // Because RichTextBox always adds a new line at the end } else { throw new Exception(String.Format("Ma non doveva finire così!")); } return(text_str); }
private void richTextBox1_PreviewKeyDown(object sender, KeyEventArgs e) { if (lstOptions.Visibility == Visibility.Visible) { if (e.Key == Key.Escape) { this.HideOptions(); } } if (!IsCaretPositionValid()) { this.richTextBox1.CaretPosition = this.richTextBox1.CaretPosition.DocumentEnd; return; } if (e.Key == Key.Tab) { if (lstOptions.Visibility == Visibility.Visible) { InsertText(lstOptions.SelectedValue as string); } e.Handled = true; } else if (e.Key == Key.Enter) { if (lstOptions.Visibility == Visibility.Visible) { InsertText(lstOptions.SelectedValue as string); e.Handled = true; } else { var command = GetCommand(); if (this.IsProcessRunning) { this.WriteInput(command); } else { RunCommand(command); e.Handled = true; } } } else if (e.Key == Key.Up) { if (lstOptions.Visibility == Visibility.Visible) { if (lstOptions.SelectedIndex > 0) { lstOptions.SelectedIndex -= 1; } lstOptions.ScrollIntoView(lstOptions.SelectedItem); } else { GetCommand(--commandIdx); } e.Handled = true; } else if (e.Key == Key.Down) { if (lstOptions.Visibility == Visibility.Visible) { lstOptions.SelectedIndex += 1; if (lstOptions.SelectedIndex < lstOptions.Items.Count - 1) { lstOptions.SelectedIndex += 1; } } else { GetCommand(++commandIdx); } e.Handled = true; } else if (e.Key == Key.Escape) { ChangePrompt("", BRUSH_PROMPT); this.HideOptions(); } else if (e.Key == Key.Back) { var text = new TextRange(richTextBox1.CaretPosition.GetLineStartPosition(0), richTextBox1.CaretPosition).Text; if (text.EndsWith(">") && text.IndexOf(">") == text.Length - 1) { e.Handled = true; } } else if (e.Key == Key.C && Keyboard.Modifiers == ModifierKeys.Control) { if (IsProcessRunning) { SendShutdownToConsole(); e.Handled = true; } } }
private void richTextBox1_PreviewKeyDown(object sender, KeyEventArgs e) { if (lstOptions.Visibility == Visibility.Visible) { lstOptions.Focus(); return; } if (!IsCaretPositionValid()) { this.richTextBox1.CaretPosition = this.richTextBox1.CaretPosition.DocumentEnd; return; } if (e.Key == Key.Space) { var command = new TextRange(richTextBox1.CaretPosition.GetLineStartPosition(0), richTextBox1.CaretPosition).Text; command = command.Substring(command.IndexOf(">") + 1).Trim(); ShowOptions(command); return; } if (e.Key == Key.Enter) { var command = GetCommand(); if (this.IsProcessRunning) { this.WriteInput(command); } else { RunCommand(command); e.Handled = true; } } else if (e.Key == Key.Up) { GetCommand(--commandIdx); e.Handled = true; } else if (e.Key == Key.Down) { GetCommand(++commandIdx); e.Handled = true; } else if (e.Key == Key.Escape) { ChangePrompt("", BRUSH_PROMPT); lstOptions.Visibility = Visibility.Collapsed; } else if (e.Key == Key.Back) { var text = new TextRange(richTextBox1.CaretPosition.GetLineStartPosition(0), richTextBox1.CaretPosition).Text; if (text.EndsWith(">") && text.IndexOf(">") == text.Length - 1) { e.Handled = true; } } else if (e.Key == Key.C && Keyboard.Modifiers == ModifierKeys.Control) { if (IsProcessRunning) { SendShutdownToConsole(); e.Handled = true; } } }