Beispiel #1
0
        // is_rhs indicates if this is an expression (right hand side) where no procedure calls may occur
        public static bool Complete_Suggestion(
            System.Windows.Forms.TextBox textbox,
            int kind,
            string current_suggestion,
            ref interpreter.suggestion_result suggestion_result)
        {
            int  location;
            int  paren_location;
            bool Handled = false;

            suggestion_result = interpreter_pkg.suggestion(textbox.Text, kind);

            if ((current_suggestion != null) &&
                current_suggestion != "" &&
                textbox.Text.Length > 1 &&
                textbox.Text[textbox.Text.Length - 1] != ')' &&
                // how can I fix this?  I don't want to complete if I'm in the bolded suggestion
                (suggestion_result.bold_start < 0 ||
                 suggestion_result.bold_finish < suggestion_result.bold_start ||
                 current_suggestion_line != 0))
            {
                // if we're inside the parens-- don't bother
                Handled  = true;
                location = textbox.Text.Length - 1;
                while ((location > 0) &&
                       (Char.IsLetterOrDigit(textbox.Text, location) ||
                        textbox.Text[location] == '_'))
                {
                    location--;
                }
                // ok, so now from location to end will be replaced by
                // the suggestion up to the parenthesis
                paren_location = current_suggestion.IndexOf("(");
                if (paren_location < 0)
                {
                    paren_location = current_suggestion.Length;
                }

                // we've got no () to do and are at the end.
                if (textbox.Text.Length - location >= current_suggestion.Length)
                {
                    return(false);
                }
                if (location == 0)
                {
                    textbox.Text =
                        current_suggestion.Substring(0, paren_location);
                }
                else
                {
                    textbox.Text =
                        textbox.Text.Substring(0, location + 1) +
                        current_suggestion.Substring(0, paren_location);
                }
                textbox.SelectionStart =
                    textbox.Text.Length;
                textbox.SelectionLength = 0;
            }
            return(Handled);
        }
Beispiel #2
0
        public static void Check_Hint(
            System.Windows.Forms.TextBox textbox,
            System.Windows.Forms.RichTextBox textBox1,
            int kind,
            ref string current_suggestion,
            ref interpreter.suggestion_result suggestion_result,
            ref bool error,
            System.Drawing.Font this_Font
            )
        {
            // collapse into a single line
            if (textbox.Lines.Length > 1)
            {
                textbox.Text = textbox.Lines[0] + textbox.Lines[1];
                textbox.Select(textbox.Text.Length, 0);
            }
            suggestion_result = interpreter_pkg.suggestion(textbox.Text, kind);
            have_bold         = suggestion_result.bold_start > 0 &&
                                suggestion_result.bold_finish >= suggestion_result.bold_start;
            if (have_bold)
            {
                string[] copy = new string[suggestion_result.suggestions.Length - 1];
                for (int k = 1; k < suggestion_result.suggestions.Length; k++)
                {
                    copy[k - 1] = suggestion_result.suggestions[k];
                }
                Array.Sort(copy);
                for (int k = 1; k < suggestion_result.suggestions.Length; k++)
                {
                    suggestion_result.suggestions[k] = copy[k - 1];
                }
            }
            else
            {
                Array.Sort(suggestion_result.suggestions);
            }
            if (!Component.MONO)
            {
                textBox1.Lines = suggestion_result.suggestions;
            }
            else
            {
                textBox1.Lines = addNewlines(suggestion_result.suggestions);
            }

            textBox1.SelectAll();
            textBox1.SelectionColor = System.Drawing.Color.Black;
            // if the current suggestion is unavailable, switch to the first one
            if (suggestion_result.suggestions.Length == 0)
            {
                current_suggestion      = "";
                current_suggestion_line = -1;
                textBox1.Hide();
            }
            else
            {
                if (suggestion_result.suggestions.Length > 1)
                {
                    int loc;
                    if (current_suggestion != null)
                    {
                        try
                        {
                            loc = textBox1.Find(current_suggestion);
                        }
                        catch
                        {
                            loc = -1;
                        }
                    }
                    else
                    {
                        loc = -1;
                    }
                    if (loc < 0 && !have_bold)
                    {
                        current_suggestion      = suggestion_result.suggestions[0];
                        current_suggestion_line = 0;
                    }
                    else if (loc <= 0 && have_bold)
                    {
                        current_suggestion      = suggestion_result.suggestions[1];
                        current_suggestion_line = 1;
                    }
                    int index;
                    try
                    {
                        index = textBox1.Find(current_suggestion);
                        current_suggestion_line = textBox1.GetLineFromCharIndex(index);

                        textBox1.Select(index,
                                        current_suggestion.Length);
                    }
                    catch
                    {
                    }
                    textBox1.SelectionColor = System.Drawing.Color.Red;
                    error = false;
                    textBox1.Show();
                }
                else if (suggestion_result.suggestions.Length == 1)
                {
                    current_suggestion      = suggestion_result.suggestions[0];
                    current_suggestion_line = 0;
                    try
                    {
                        textBox1.Select(textBox1.Find(current_suggestion),
                                        current_suggestion.Length);
                        if (have_bold)
                        {
                            textBox1.SelectionColor = System.Drawing.Color.Black;
                        }
                        else
                        {
                            textBox1.SelectionColor = System.Drawing.Color.Red;
                        }
                    }
                    catch
                    {
                    }
                }
                if (have_bold)
                {
                    textBox1.Select(suggestion_result.bold_start - 1, suggestion_result.bold_finish - suggestion_result.bold_start + 1);
                    textBox1.SelectionFont = new Font(this_Font, FontStyle.Bold);
                    textBox1.Select(0, textBox1.Lines[0].Length);
                    textBox1.SelectionColor = System.Drawing.Color.Black;
                }
                error = false;
                textBox1.Show();
            }
        }