Exemplo n.º 1
0
        private void ChooseMemberFromIntellisense(bool canChooseWhenEmpty)
        {
            if (!intellisense.Visible)
            {
                return;
            }

            var selectedMember = intellisense.GetSelectedMember();

            if (selectedMember != null)
            {
                // replace current part with selected member
                var typeAndAfter = StatementParser.GetTypeOfCurrentStatement(txtEvaluate.Text, txtEvaluate.SelectionStart - 1, thisObject, false);


                if ((!canChooseWhenEmpty && string.IsNullOrEmpty(typeAndAfter.Value)) || StatementParser.GetStringsNotToAutocompleteOn().Contains(typeAndAfter.Value))
                {
                    return;
                }

                string name;
                string alias = AliasManager.Instance.GetAlias(selectedMember);
                if (!string.IsNullOrEmpty(alias))
                {
                    name = alias;
                }
                else
                {
                    name = selectedMember.Name;
                }

                if (name.ToLower().StartsWith(txtEvaluate.Text.Substring(txtEvaluate.Text.Length - typeAndAfter.Value.Length).ToLower()))
                {
                    txtEvaluate.Text           = txtEvaluate.Text.Substring(0, txtEvaluate.Text.Length - typeAndAfter.Value.Length) + name;
                    txtEvaluate.SelectionStart = txtEvaluate.TextLength;
                }

                intellisense.Hide();
            }
        }
Exemplo n.º 2
0
        public override void Evaluate()
        {
            var oldType   = ObjectType;
            var oldObject = Object;

            try
            {
                var result = StatementParser.EvaluateStatement(Expression, ThisObject, true, true, false);
                Object     = result.Result;
                ObjectType = result.ResultType;

                if (Object != null)
                {
                    this[1] = Object;
                }
                else
                {
                    this[1] = "null";
                }

                if (ObjectType != null)
                {
                    this[2] = ObjectType.ToSignatureString();
                }
                else
                {
                    this[2] = "";
                }
            }
            catch (Exception ex)
            {
                this[1] = "(ERROR: " + ex.GetType().Name + " - " + ex.Message + ")";
            }

            SetChanged(oldObject, oldType);
        }
Exemplo n.º 3
0
        private void txtEvaluate_KeyDown(object sender, KeyEventArgs e)
        {
            try
            {
                if (e.KeyCode == Keys.Enter)
                {
                    if (intellisense.Visible)
                    {
                        ChooseMemberFromIntellisense(true);
                    }
                    else
                    {
                        try
                        {
                            this.Enabled = false;

                            string statement = txtEvaluate.Text;
                            var    value     = StatementParser.EvaluateStatement(statement, thisObject, true, true, useDebugger: ModifierKeys == Keys.Control);

                            OnExpressionEvaluated(new EvaluateArgs()
                            {
                                Result = value, Statement = statement
                            });

                            SetInput("");
                        }
                        catch (Exception ex)
                        {
                            ILDebugManager.Instance.Debugger = null;
                            MessageBox.Show("Unable to evaluate: " + ex.ToExceptionString());
                        }
                        finally
                        {
                            this.Enabled = true;
                        }
                    }
                    e.Handled = true;
                }
                else if (e.KeyCode == Keys.OemPeriod)
                {
                    if (intellisense.Visible)
                    {
                        ChooseMemberFromIntellisense(false);
                    }
                }
                else if (e.KeyCode == Keys.Up || e.KeyCode == Keys.Down)
                {
                    if (intellisense.Visible)
                    {
                        if (e.KeyCode == Keys.Up)
                        {
                            intellisense.Up();
                        }
                        else
                        {
                            intellisense.Down();
                        }

                        e.Handled = true;
                    }
                    else
                    {
                        if (e.KeyCode == Keys.Up)
                        {
                            GoBack();
                        }
                        else
                        {
                            GoForward();
                        }

                        e.Handled = true;
                    }
                }
                else if (e.KeyCode == Keys.PageUp || e.KeyCode == Keys.PageDown)
                {
                    if (intellisense.Visible)
                    {
                        if (e.KeyCode == Keys.PageUp)
                        {
                            intellisense.PageUp();
                        }
                        else
                        {
                            intellisense.PageDown();
                        }

                        e.Handled = true;
                    }
                }
                else if (e.KeyCode == Keys.Escape)
                {
                    if (intellisense.Visible)
                    {
                        intellisense.Hide();
                    }
                }
            }
            catch (Exception)
            {
                // don't go crashing the app
            }
        }
Exemplo n.º 4
0
        private void txtEvaluate_TextChanged(object sender, EventArgs e)
        {
            try
            {
                if (txtEvaluate.SelectionStart - 1 >= txtEvaluate.Text.Length)
                {
                    return;
                }

                var typeAndAfter = StatementParser.GetTypeOfCurrentStatement(txtEvaluate.Text, txtEvaluate.SelectionStart - 1, thisObject, false);


                if (typeAndAfter.Key != null)
                {
                    if (intellisense.CurrentType != typeAndAfter.Key)
                    {
                        Type fromType = typeAndAfter.Key;
                        UpdateIntellisense(fromType);
                    }

                    if (txtEvaluate.Text.EndsWith("."))
                    {
                        ShowIntellisense();
                    }

                    intellisense.SelectCurrentPart(typeAndAfter.Value);
                }
            }
            catch (Exception)
            {
                if (intellisense.Visible)
                {
                    intellisense.SetItems(new List <IntellisensePopup.ListItem>());
                    intellisense.CurrentType = null;
                    intellisense.Hide();
                }
            }

            try
            {
                if (txtEvaluate.SelectionStart - 1 >= txtEvaluate.Text.Length)
                {
                    return;
                }

                var methods = StatementParser.GetCurrentMethodOverloads(txtEvaluate.Text, txtEvaluate.SelectionStart - 1, thisObject);
                if (methods.Count > 0)
                {
                    string methodSignatures = string.Join(Environment.NewLine, methods.Select(m => m.ToSignatureString()).ToArray());

                    Point p = txtEvaluate.PointToScreen(txtEvaluate.GetPositionFromCharIndex(txtEvaluate.SelectionStart - 1));
                    p.Offset(16, -16 + -methods.Count * 10);
                    p.Offset(-this.Location.X, -this.Location.Y);

                    methodsToolTip.Show(methodSignatures, this, p);
                }
                else
                {
                    methodsToolTip.Hide(this);
                }
            }
            catch (Exception)
            {
                methodsToolTip.Hide(this);
            }
        }