Beispiel #1
0
        private void Editor_KeyUp(object sender, KeyEventArgs e)
        {
            try
            {
                if (AutoComplete)
                {
                    if (e.Control)
                    {
                        switch (e.KeyCode)
                        {
                        case Keys.Space:
                            // Remove the space that has just been added
                            EditionTextBox.Select(EditionTextBox.SelectionStart - 1, 1);
                            EditionTextBox.SelectedText = "";
                            DisplayComboBox();
                            e.Handled = true;
                            break;

                        case Keys.I:
                            // Remove the space that has just been added
                            EditionTextBox.Select(EditionTextBox.SelectionStart - 1, 1);
                            EditionTextBox.SelectedText = "";
                            EditionTextBox.Indent();
                            e.Handled = true;
                            break;
                        }
                    }
                }
            }
            catch (Exception)
            {
            }

            if (!e.Handled)
            {
                if (e.Control)
                {
                    switch (e.KeyCode)
                    {
                    case Keys.A:
                        EditionTextBox.SelectAll();
                        e.Handled = true;
                        break;

                    case Keys.C:
                        EditionTextBox.Copy();
                        e.Handled = true;
                        break;

                    case Keys.V:
                        e.Handled = true;
                        break;
                    }
                }
            }
        }
Beispiel #2
0
        private void ConfirmComboBoxSelection()
        {
            if (PendingSelection)
            {
                PendingSelection = false;
                EditionTextBox.Select(_selectionStart, _selectionLength);

                EditionTextBox.SelectedText   = SelectionComboBox.Text;
                EditionTextBox.SelectionStart = EditionTextBox.SelectionStart;
                SelectionComboBox.Text        = "";
                SelectionComboBox.Items.Clear();
                SelectionComboBox.Hide();
                explainRichTextBox.Hide();
            }
        }
Beispiel #3
0
        /// <summary>
        ///     Displays the combo box if required and updates the edotor's text
        /// </summary>
        private void DisplayComboBox()
        {
            int index = EditionTextBox.SelectionStart - 1;

            string prefix = CurrentPrefix(index).Trim();

            index = Math.Max(0, index - prefix.Length);
            SortedSet <ObjectReference> allChoices = AllChoices(index, prefix);

            if (prefix.Length <= EditionTextBox.SelectionStart)
            {
                // It seems that selection start and length may be lost when losing the focus.
                // Store them to be able to reapply them
                _selectionStart  = EditionTextBox.SelectionStart - prefix.Length;
                _selectionLength = prefix.Length;
                EditionTextBox.Select(_selectionStart, _selectionLength);
                if (allChoices.Count == 1)
                {
                    EditionTextBox.SelectedText = allChoices.First().DisplayName;
                }
                else if (allChoices.Count > 1)
                {
                    SelectionComboBox.Items.Clear();
                    foreach (ObjectReference choice in allChoices)
                    {
                        SelectionComboBox.Items.Add(choice);
                    }
                    if (prefix.Length > 0)
                    {
                        SelectionComboBox.Text = prefix;
                    }
                    else
                    {
                        SelectionComboBox.Text = allChoices.First().DisplayName;
                    }

                    // Try to compute the combo box location
                    // TODO : Hypothesis. The first displayed line is the first line of the text
                    int    line     = 1;
                    string lineData = "";
                    for (int i = 0; i < EditionTextBox.SelectionStart; i++)
                    {
                        switch (EditionTextBox.Text[i])
                        {
                        case '\n':
                            line    += 1;
                            lineData = "";
                            break;

                        default:
                            lineData += EditionTextBox.Text[i];
                            break;
                        }
                    }

                    SizeF size             = CreateGraphics().MeasureString(lineData, EditionTextBox.Font);
                    int   x                = Math.Min((int)size.Width, Location.X + Size.Width - SelectionComboBox.Width);
                    int   y                = (line - 1) * EditionTextBox.Font.Height + 5;
                    Point comboBoxLocation = new Point(x, y);
                    SelectionComboBox.Location = comboBoxLocation;
                    PendingSelection           = true;
                    EditionTextBox.SendToBack();
                    SelectionComboBox.Show();
                    SelectionComboBox.Focus();
                }
            }
        }