private void OnSubExpressionButtonClick(object sender, EventArgs e) { Button button = (Button)sender; ButtonInfo buttonInfo = (ButtonInfo)button.Tag; if (!highlightedAreas.ContainsKey(buttonInfo.toHighlight)) { this.highlightedAreas.Add(buttonInfo.toHighlight, Brushes.Yellow); } Rectangle toInvalidate = Rectangle.Truncate(buttonInfo.toHighlight); toInvalidate.Height += 1; toInvalidate.Width += 1; this.Invalidate(toInvalidate); foreach (ToolStripItem item in sharedContextMenu.Items) { if (item is ToolStripTextBox) { ((ToolStripTextBox)item).Control.Parent.Controls.Remove(((ToolStripTextBox)item).Control); } } this.sharedContextMenu.Items.Clear(); this.sharedContextMenu.Items.AddRange(ButtonAndMenuData.GetMenuItems(buttonInfo.associatedExpression).ToArray()); this.sharedContextMenu.Show(this.PointToScreen(new Point(button.Right, button.Bottom)), ToolStripDropDownDirection.AboveRight); }
private void OnSetValueClick(object sender, EventArgs e) { ToolStripMenuItem item = (ToolStripMenuItem)sender; ToExchange exchange = (ToExchange)item.Tag; ToolStripTextBox textBox = exchange.valueBox; object primitiveObject = null; try { primitiveObject = Convert.ChangeType(textBox.Text, EvaluatorGenerator.GetType(exchange.original, true)); } catch (FormatException) { MessageBox.Show(string.Format("Could not convert '{0}' to object of type '{1}'. Please enter a value into the textbox in the context menu.", textBox.Text, EvaluatorGenerator.GetType(exchange.original, false))); return; } CodePrimitiveExpression replacement = new CodePrimitiveExpression(primitiveObject); replacement.UserData.Add(typeof(ButtonAndMenuData), exchange.original.UserData[typeof(ButtonAndMenuData)]); EvaluatorGenerator.SetType(replacement, EvaluatorGenerator.GetType(exchange.original, true)); EvaluatorGenerator.SetParameterIndex(replacement, EvaluatorGenerator.GetParameterIndex(exchange.original, true)); CodeBinaryOperatorExpression expression = ParentLink.GetParent(exchange.original); if (ParentLink.GetSide(exchange.original) == ParentSide.Left) { expression.Left = replacement; } else { expression.Right = replacement; } ToolStripMenuItem menuItem = new ToolStripMenuItem(textBox.Text); menuItem.Tag = new ToExchange(exchange.original, replacement); menuItem.Click += OnContextMenuItemClick; List <ToolStripItem> menuItems = ButtonAndMenuData.GetMenuItems(exchange.original); menuItems.Insert(1, menuItem); if (menuItems.Count > 3 + 1 + 5) { menuItems.RemoveAt(6); } textBox.Clear(); this.highlightedAreas.Clear(); this.Refresh(); this.CheckEvaluateButtonEnable(); }