public void RemoveIntellisenseControls(ControlCollection controls) { IntellisenseListBox.Hide(); controls.Remove(IntellisenseListBox); ActiveTextBox = null; ActiveGridView = null; }
private void IntellisenseListBoxAutoComplete_DoubleClick(object sender, EventArgs e) { if (ActiveTextBox == null) { return; } IntellisenseListBox = (UIIntellisenseListBox)sender; // Item double clicked, select it if (IntellisenseListBox.SelectedItems.Count == 1) { WordMatched = true; SelectIntellisenseListBoxItem(); IntellisenseListBox.Hide(); if (ActiveGridView != null) { ActiveGridView.ListBoxShown = false; } if (ActiveTextBox is UITextBox) { ((UITextBox)ActiveTextBox).ListBoxShown = false; } else if (ActiveTextBox is UIScintilla) { ((UIScintilla)ActiveTextBox).ListBoxShown = false; } ActiveTextBox.Focus(); WordMatched = false; } }
public void CodeDGVInput_TextChanged(object sender, EventArgs e) { ActiveTextBox = (TextBox)sender; _carotLocation = ((TextBox)ActiveTextBox).SelectionStart; if (ActiveTextBox.Parent != null) { ActiveGridView = (UIDataGridView)ActiveTextBox.Parent.Parent; } if (PopulateIntellisenseListBox() && !KeepHidden) { // Find the position of the caret Point point = ActiveGridView.Location; var cellRowMultiplier = ActiveGridView.CurrentCellAddress.Y + 1; List <int> colWidths = new List <int>(); foreach (DataGridViewColumn col in ActiveGridView.Columns) { colWidths.Add(col.Width); } Point currentCellAddress = ActiveGridView.CurrentCellAddress; int widthToAdd = 0; for (int i = 0; i < currentCellAddress.X; i++) { widthToAdd += colWidths[i]; } point.Y += ActiveTextBox.Location.Y + (int)Math.Ceiling(ActiveTextBox.Font.GetHeight() * 1.4) + (ActiveGridView.RowTemplate.Height * cellRowMultiplier); point.X += ActiveTextBox.Location.X + TextRenderer.MeasureText(ActiveTextBox.Text.Substring(0, _carotLocation), ActiveTextBox.Font).Width + ActiveGridView.RowHeadersWidth + widthToAdd; Control currenControl = ActiveGridView; while (currenControl.Parent != null && !(currenControl.Parent is Form)) { point.Y += currenControl.Parent.Location.Y; point.X += currenControl.Parent.Location.X; currenControl = currenControl.Parent; } IntellisenseListBox.Location = point; IntellisenseListBox.BringToFront(); ActiveGridView.ListBoxShown = true; IntellisenseListBox.Show(); } else { IntellisenseListBox.Hide(); ActiveGridView.ListBoxShown = false; } }
public void CodeTBXInput_TextChanged(object sender, EventArgs e) { if (sender is UITextBox) { ActiveTextBox = (UITextBox)sender; if (ActiveTextBox.Text == "") { return; } _carotLocation = ((UITextBox)ActiveTextBox).SelectionStart; } else if (sender is UIScintilla) { ActiveTextBox = (UIScintilla)sender; if (ActiveTextBox.Text == "" || ScriptLoading) { ScriptLoading = false; return; } _carotLocation = ((UIScintilla)ActiveTextBox).SelectionStart; } if (PopulateIntellisenseListBox() && !KeepHidden && ActiveTextBox is UITextBox) { // Find the position of the caret Point point = new Point(0, 0); string[] lines = ActiveTextBox.Text.Split(new char[] { '\r', '\n' }); List <string> filteredLines = new List <string>(); int strippedChars = lines.Length - 1; foreach (string line in lines) { if (line != "") { filteredLines.Add(line); } } int lengthSum = 0; int currentLine = 1; int carotLocationOnLine = _carotLocation; for (int i = 0; i < filteredLines.Count; i++) { if (_carotLocation < lengthSum + strippedChars) { continue; } currentLine = i + 1; carotLocationOnLine = _carotLocation - (lengthSum + i * 2); lengthSum += filteredLines[i].Length; } int lineLength = TextRenderer.MeasureText(filteredLines[currentLine - 1].Substring(0, carotLocationOnLine), ActiveTextBox.Font).Width; point.Y += ActiveTextBox.Location.Y + (int)Math.Ceiling(ActiveTextBox.Font.GetHeight() * currentLine) + 2; point.X += ActiveTextBox.Location.X + lineLength; Control currentControl = ActiveTextBox; while (currentControl.Parent != null && !(currentControl.Parent is Form)) { point.Y += currentControl.Parent.Location.Y; point.X += currentControl.Parent.Location.X; currentControl = currentControl.Parent; } IntellisenseListBox.Location = point; IntellisenseListBox.BringToFront(); if (ActiveTextBox is UITextBox) { ((UITextBox)ActiveTextBox).ListBoxShown = true; } else if (ActiveTextBox is UIScintilla) { ((UIScintilla)ActiveTextBox).ListBoxShown = true; } IntellisenseListBox.Show(); } else if (PopulateIntellisenseListBox() && !KeepHidden && ActiveTextBox is UIScintilla) { // Find the position of the caret Point point = new Point(0, 0); string precursorText = ActiveTextBox.Text.Substring(0, ((UIScintilla)ActiveTextBox).SelectionStart); string[] splitPretext = precursorText.Replace("\r\n", "\n").Replace("\r", "\n").Split('\n'); string lastLine = splitPretext[splitPretext.Length - 1]; string spacesInTab = ""; for (int i = 0; i < ((UIScintilla)ActiveTextBox).TabSize; i++) { spacesInTab += " "; } int marginWidths = 0; foreach (Margin margin in ((UIScintilla)ActiveTextBox).Margins) { marginWidths += margin.Width; } var scintillaStyle = ((UIScintilla)ActiveTextBox).Styles[0]; Font fontUsed = new Font(scintillaStyle.Font, scintillaStyle.Size, FontStyle.Regular); int lineLength = TextRenderer.MeasureText(lastLine.Replace("\t", spacesInTab), fontUsed).Width; point.Y += ActiveTextBox.Location.Y + (int)Math.Ceiling(ActiveTextBox.Font.GetHeight() * (splitPretext.Length)) + 2; point.X += ActiveTextBox.Location.X + lineLength + marginWidths + 5; Control currentControl = ActiveTextBox; while (currentControl.Parent != null && !(currentControl.Parent is Form)) { point.Y += currentControl.Parent.Location.Y; point.X += currentControl.Parent.Location.X; currentControl = currentControl.Parent; } IntellisenseListBox.Location = point; IntellisenseListBox.BringToFront(); if (ActiveTextBox is UITextBox) { ((UITextBox)ActiveTextBox).ListBoxShown = true; } else if (ActiveTextBox is UIScintilla) { ((UIScintilla)ActiveTextBox).ListBoxShown = true; } IntellisenseListBox.Show(); } else { IntellisenseListBox.Hide(); if (ActiveTextBox is UITextBox) { ((UITextBox)ActiveTextBox).ListBoxShown = false; } else if (ActiveTextBox is UIScintilla) { ((UIScintilla)ActiveTextBox).ListBoxShown = false; } } }
public void CodeInput_KeyDown(object sender, KeyEventArgs e) { if (sender is TextBox) { ActiveTextBox = (TextBox)sender; } else if (sender is UIScintilla) { ActiveTextBox = (UIScintilla)sender; } KeepHidden = false; if (e.KeyCode == Keys.Return || e.KeyCode == Keys.Tab || e.KeyCode == Keys.Space) { // Autocomplete SelectIntellisenseListBoxItem(); //this.typed = ""; WordMatched = false; if (ActiveTextBox is TextBox) { e.Handled = true; } IntellisenseListBox.Hide(); if (ActiveGridView != null) { ActiveGridView.ListBoxShown = false; } if (ActiveTextBox is UITextBox) { ((UITextBox)ActiveTextBox).ListBoxShown = false; } else if (ActiveTextBox is UIScintilla) { ((UIScintilla)ActiveTextBox).ListBoxShown = false; } KeepHidden = true; } else if (e.KeyCode == Keys.Back || e.KeyCode == Keys.Left || e.KeyCode == Keys.Right || e.KeyCode == Keys.Delete) { IntellisenseListBox.Hide(); if (ActiveGridView != null) { ActiveGridView.ListBoxShown = false; } if (ActiveTextBox is UITextBox) { ((UITextBox)ActiveTextBox).ListBoxShown = false; } else if (ActiveTextBox is UIScintilla) { ((UIScintilla)ActiveTextBox).ListBoxShown = false; } KeepHidden = true; } else if (e.KeyCode == Keys.Up) { // The up key moves up our member list, if the list is visible if (IntellisenseListBox.Visible) { WordMatched = true; if (IntellisenseListBox.SelectedIndex > 0) { IntellisenseListBox.SelectedIndex--; } e.Handled = true; } } else if (e.KeyCode == Keys.Down) { // The up key moves down our member list, if the list is visible if (IntellisenseListBox.Visible) { WordMatched = true; if (IntellisenseListBox.SelectedIndex < IntellisenseListBox.Items.Count - 1) { IntellisenseListBox.SelectedIndex++; } e.Handled = true; } } }