Esempio n. 1
0
        private void Editor_KeyPress(object sender, KeyPressEventArgs e)
        {
            try
            {
                if (AutoComplete)
                {
                    switch (e.KeyChar)
                    {
                    case '.':
                        EditionTextBox.SelectedText = e.KeyChar.ToString(CultureInfo.InvariantCulture);
                        e.Handled = true;
                        DisplayComboBox();
                        break;

                    case '{':
                        Structure structure = GetInstance(EditionTextBox.SelectionStart - 1) as Structure;
                        if (structure != null)
                        {
                            TextualExplanation text = new TextualExplanation();
                            text.WriteLine("{");
                            CreateDefaultStructureValue(text, structure, false);
                            EditionTextBox.SelectedText = text.Text;
                            EditionTextBox.ProcessAllLines(true);
                            e.Handled = true;
                        }
                        break;

                    case '(':
                        ICallable callable = GetInstance(EditionTextBox.SelectionStart - 1) as ICallable;
                        if (callable != null)
                        {
                            TextualExplanation text = new TextualExplanation();
                            CreateCallableParameters(text, callable);
                            EditionTextBox.SelectedText = text.Text;
                            EditionTextBox.ProcessAllLines(true);
                            e.Handled = true;
                        }
                        break;

                    case '>':
                    case '-':
                        char prev = EditionTextBox.Text[EditionTextBox.SelectionStart - 1];
                        if ((prev == '<' && e.KeyChar == '-') || (prev == '=' && e.KeyChar == '>'))
                        {
                            ITypedElement typedElement =
                                GetInstance(EditionTextBox.SelectionStart - 2) as ITypedElement;
                            if (typedElement != null)
                            {
                                EditionTextBox.SelectedText = e.KeyChar + " " + typedElement.Type.FullName;
                                e.Handled = true;
                            }
                        }
                        break;
                    }
                }
            }
            catch (Exception)
            {
            }
        }
Esempio n. 2
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;
                    }
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        ///     Explains a list of namables and shows the associated textbox
        /// </summary>
        /// <param name="namable">The namable to explain</param>
        /// <param name="location">
        ///     The location where the explain box should be displayed. If empty is displayed, the location is
        ///     computed based on the combo box location
        /// </param>
        /// <param name="sensibleToMouseMove">Indicates that the explain box should be closed when the mouse moves</param>
        private void ExplainAndShow(INamable namable, Point location, bool sensibleToMouseMove)
        {
            explainRichTextBox.Text = "";
            if (namable != null)
            {
                TextualExplanation explanation    = new TextualExplanation();
                ITextualExplain    textualExplain = namable as ITextualExplain;
                if (textualExplain != null)
                {
                    textualExplain.GetExplain(explanation, false);
                }

                explainRichTextBox.Text = explanation.Text;
                explainRichTextBox.ProcessAllLines();

                if (location == Point.Empty)
                {
                    if (SelectionComboBox.DroppedDown)
                    {
                        explainRichTextBox.Location = new Point(
                            SelectionComboBox.Location.X + SelectionComboBox.Size.Width,
                            SelectionComboBox.Location.Y + SelectionComboBox.Size.Height
                            );
                    }
                    else
                    {
                        explainRichTextBox.Location = new Point(
                            SelectionComboBox.Location.X,
                            SelectionComboBox.Location.Y + SelectionComboBox.Size.Height
                            );
                    }
                }
                else
                {
                    explainRichTextBox.Location = new Point(
                        Math.Min(location.X, EditionTextBox.Size.Width - explainRichTextBox.Size.Width),
                        Math.Min(location.Y, EditionTextBox.Size.Height - explainRichTextBox.Size.Height));
                }

                ConsiderMouseMoveToCloseExplanation = sensibleToMouseMove;

                explainRichTextBox.Size = new Size(400, 200);
                if (explainRichTextBox.Size.Width >= Size.Width * 0.8)
                {
                    explainRichTextBox.Size = new Size((int)(Size.Width * 0.8), explainRichTextBox.Size.Height);
                }
                if (explainRichTextBox.Size.Height >= Size.Height * 0.8)
                {
                    explainRichTextBox.Size = new Size(explainRichTextBox.Size.Width, (int)(Size.Height * 0.8));
                }

                explainRichTextBox.Show();
                EditionTextBox.SendToBack();
            }
        }
Esempio n. 4
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();
            }
        }
Esempio n. 5
0
        /// <summary>
        ///     Provides the instance related to a location in the textbox
        /// </summary>
        /// <param name="location"></param>
        /// <returns></returns>
        protected INamable GetInstance(Point location)
        {
            // ReSharper disable once RedundantAssignment
            INamable retVal = null;

            int index = EditionTextBox.GetCharIndexFromPosition(location);

            // Ensure that the index actually corresponds to the desired location
            Point confirmLocation = EditionTextBox.GetPositionFromCharIndex(index);
            int   dX       = Math.Abs(confirmLocation.X - location.X);
            int   dY       = Math.Abs(confirmLocation.Y - location.Y);
            int   distance = (int)Math.Sqrt(dX * dX + dY * dY);

            if (distance < 30)
            {
                retVal = GetInstance(index);
            }

            return(retVal);
        }
Esempio n. 6
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();
                }
            }
        }
Esempio n. 7
0
 private void indentToolStripMenuItem_Click(object sender, EventArgs e)
 {
     EditionTextBox.Indent();
 }
Esempio n. 8
0
 public void Redo()
 {
     EditionTextBox.Redo();
     EditionTextBox.ProcessAllLines();
 }
Esempio n. 9
0
 public void Undo()
 {
     EditionTextBox.Undo();
     EditionTextBox.ProcessAllLines();
 }
Esempio n. 10
0
 public void Paste()
 {
     EditionTextBox.Paste();
     EditionTextBox.ProcessAllLines();
 }
Esempio n. 11
0
 public void Cut()
 {
     EditionTextBox.Cut();
     EditionTextBox.ProcessAllLines();
 }
Esempio n. 12
0
 public void Copy()
 {
     EditionTextBox.Copy();
 }