/// <summary> /// Processes given parameter value to interpretate inserted patch variables /// </summary> /// <param name="paramValue"></param> /// <returns></returns> public static string EvaluateParameter(string paramValue) { if (string.IsNullOrEmpty(paramValue)) { return(paramValue); } // Retrieves variable(s) in specified value Collection <int> markeupPositions = new Collection <int>(); int currentVarIndex = 0; while (currentVarIndex != -1 && currentVarIndex < paramValue.Length) { currentVarIndex = paramValue.IndexOf(PatchVariable.VARIABLE_MARKEUP, currentVarIndex); if (currentVarIndex != -1) { markeupPositions.Add(currentVarIndex); currentVarIndex++; } } for (int i = 0; i < markeupPositions.Count - 1; i = i + 2) { string currentVarName = paramValue.Substring(markeupPositions[i] + 1, markeupPositions[i + 1] - markeupPositions[i] - 1); PatchVariable var = PatchVariable.MakeVariable(currentVarName); if (var != null) { paramValue = paramValue.Replace(var.Code, var.GetValue()); } } return(paramValue); }
/// <summary> /// Creates a context menu applied to a Form /// </summary> /// <param name="baseForm">Form instance</param> /// <param name="parameters">Parameters to use. [0] : textBox instance to write variable value to.</param> /// <returns>null if input parameters are invalid</returns> public ContextMenuStrip CreateContextMenu(Form baseForm, params object[] parameters) { if (parameters == null || parameters.Length != 1) { return(null); } TextBox parameterTextBox = parameters[0] as TextBox; ContextMenuStrip newMenu = new ContextMenuStrip(); if (parameterTextBox == null) { return(null); } // Getting all variables string[] allVariables = Enum.GetNames(typeof(PatchVariable.VariableName)); foreach (string anotherVariableName in allVariables) { ToolStripItem newItem = new ToolStripMenuItem(anotherVariableName); PatchVariable varInstance = PatchVariable.MakeVariable(anotherVariableName); if (varInstance != null) { newItem.Click += delegate(object sender, EventArgs args) { parameterTextBox.SelectedText = varInstance.Code; parameterTextBox.Focus(); }; newItem.ToolTipText = varInstance.Description; } newMenu.Items.Add(newItem); } return(newMenu); }