private void OnContextMenuItemClick(object sender, EventArgs e) { ToolStripMenuItem item = (ToolStripMenuItem)sender; if (item.Tag is ToExchange) { ToExchange exchange = (ToExchange)item.Tag; CodeBinaryOperatorExpression expression = ParentLink.GetParent(exchange.original); if (ParentLink.GetSide(exchange.original) == ParentSide.Left) { expression.Left = exchange.newExpression; } else { expression.Right = exchange.newExpression; } this.DisableButtons(exchange.original); this.highlightedAreas.Clear(); this.Refresh(); this.CheckEvaluateButtonEnable(); } }
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(); }