/// <summary> /// Render TextBox control. /// Return true if failed. /// </summary> /// <param name="canvas">Parent canvas</param> /// <param name="uiCmd">UICommand</param> /// <returns>Success = false, Failure = true</returns> public static void RenderTextBox(RenderInfo r, UICommand uiCmd) { // WB082 textbox control's y coord is of textbox's, not textlabel's. Debug.Assert(uiCmd.Info.GetType() == typeof(UIInfo_TextBox)); UIInfo_TextBox info = uiCmd.Info as UIInfo_TextBox; TextBox box = new TextBox() { Text = info.Value, FontSize = CalcFontPointScale(), VerticalContentAlignment = VerticalAlignment.Center, }; box.LostFocus += (object sender, RoutedEventArgs e) => { TextBox tBox = sender as TextBox; info.Value = tBox.Text; uiCmd.Update(); }; SetToolTip(box, info.ToolTip); DrawToCanvas(r, box, uiCmd.Rect); if (uiCmd.Text.Equals(string.Empty, StringComparison.Ordinal) == false) { TextBlock block = new TextBlock() { Text = uiCmd.Text, LineStackingStrategy = LineStackingStrategy.BlockLineHeight, LineHeight = CalcFontPointScale(), FontSize = CalcFontPointScale(), }; SetToolTip(block, info.ToolTip); double margin = PointToDeviceIndependentPixel * DefaultFontPoint * 1.2; Rect blockRect = new Rect(uiCmd.Rect.Left, uiCmd.Rect.Top - margin, uiCmd.Rect.Width, uiCmd.Rect.Height); DrawToCanvas(r, block, blockRect); } }
public static List <LogInfo> Set(EngineState s, CodeCommand cmd) { Debug.Assert(cmd.Info.GetType() == typeof(CodeInfo_Set)); CodeInfo_Set info = cmd.Info as CodeInfo_Set; Variables.VarKeyType varType = Variables.DetermineType(info.VarKey); if (varType == Variables.VarKeyType.None) { // Check Macro if (Regex.Match(info.VarKey, Macro.MacroNameRegex, RegexOptions.Compiled).Success) // Macro Name Validation { string macroCommand = StringEscaper.Preprocess(s, info.VarValue); if (macroCommand.Equals("NIL", StringComparison.OrdinalIgnoreCase)) { macroCommand = null; } LogInfo log = s.Macro.SetMacro(info.VarKey, macroCommand, cmd.Addr, info.Permanent); return(new List <LogInfo>(1) { log }); } } // [WB082 Behavior] // If PERMANENT was used but the key exists in interface command, the value will not be written to script.project but in interface. // Need to investigate where the logs are saved in this case. switch (info.Permanent) { case true: { // Check if interface contains VarKey List <LogInfo> logs = new List <LogInfo>(); if (Variables.DetermineType(info.VarKey) != Variables.VarKeyType.Variable) { goto case false; } string varKey = Variables.TrimPercentMark(info.VarKey); string finalValue = StringEscaper.Preprocess(s, info.VarValue); #region Set UI Plugin p = cmd.Addr.Plugin; PluginSection iface = p.GetInterface(out string sectionName); if (iface == null) { goto case false; } List <UICommand> uiCmds = iface.GetUICodes(true); UICommand uiCmd = uiCmds.Find(x => x.Key.Equals(varKey)); if (uiCmd == null) { goto case false; } bool match = false; switch (uiCmd.Type) { case UIType.TextBox: { Debug.Assert(uiCmd.Info.GetType() == typeof(UIInfo_TextBox)); UIInfo_TextBox uiInfo = uiCmd.Info as UIInfo_TextBox; uiInfo.Value = finalValue; logs.Add(new LogInfo(LogState.Success, $"Interface [{varKey}] set to [{finalValue}]")); match = true; } break; case UIType.NumberBox: { Debug.Assert(uiCmd.Info.GetType() == typeof(UIInfo_NumberBox)); UIInfo_NumberBox uiInfo = uiCmd.Info as UIInfo_NumberBox; // WB082 just write string value in case of error, but PEBakery will throw warning if (!NumberHelper.ParseInt32(finalValue, out int intVal)) { logs.Add(new LogInfo(LogState.Warning, $"[{finalValue}] is not valid integer")); return(logs); } uiInfo.Value = intVal; logs.Add(new LogInfo(LogState.Success, $"Interface [{varKey}] set to [{finalValue}]")); match = true; } break; case UIType.CheckBox: { Debug.Assert(uiCmd.Info.GetType() == typeof(UIInfo_CheckBox)); UIInfo_CheckBox uiInfo = uiCmd.Info as UIInfo_CheckBox; if (finalValue.Equals("True", StringComparison.OrdinalIgnoreCase)) { uiInfo.Value = true; logs.Add(new LogInfo(LogState.Success, $"Interface [{varKey}] set to [True]")); match = true; } else if (finalValue.Equals("False", StringComparison.OrdinalIgnoreCase)) { uiInfo.Value = false; logs.Add(new LogInfo(LogState.Success, $"Interface [{varKey}] set to [False]")); match = true; } else { // WB082 just write string value in case of error, but PEBakery will throw warning logs.Add(new LogInfo(LogState.Warning, $"[{finalValue}] is not valid boolean")); return(logs); } } break; case UIType.ComboBox: { Debug.Assert(uiCmd.Info.GetType() == typeof(UIInfo_ComboBox)); UIInfo_ComboBox uiInfo = uiCmd.Info as UIInfo_ComboBox; int idx = uiInfo.Items.FindIndex(x => x.Equals(finalValue, StringComparison.OrdinalIgnoreCase)); if (idx == -1) { // Invalid Index logs.Add(new LogInfo(LogState.Warning, $"[{finalValue}] not found in item list")); return(logs); } uiInfo.Index = idx; uiCmd.Text = uiInfo.Items[idx]; logs.Add(new LogInfo(LogState.Success, $"Interface [{varKey}] set to [{uiCmd.Text}]")); match = true; } break; case UIType.RadioButton: { Debug.Assert(uiCmd.Info.GetType() == typeof(UIInfo_RadioButton)); UIInfo_RadioButton uiInfo = uiCmd.Info as UIInfo_RadioButton; if (finalValue.Equals("True", StringComparison.OrdinalIgnoreCase)) { uiInfo.Selected = true; logs.Add(new LogInfo(LogState.Success, $"Interface [{varKey}] set to true]")); match = true; } else if (finalValue.Equals("False", StringComparison.OrdinalIgnoreCase)) { uiInfo.Selected = false; logs.Add(new LogInfo(LogState.Success, $"Interface [{varKey}] set to [False]")); match = true; } else { // WB082 just write string value, but PEBakery will ignore and throw and warning logs.Add(new LogInfo(LogState.Warning, $"[{finalValue}] is not valid boolean")); return(logs); } } break; case UIType.FileBox: { Debug.Assert(uiCmd.Info.GetType() == typeof(UIInfo_FileBox)); UIInfo_FileBox uiInfo = uiCmd.Info as UIInfo_FileBox; uiCmd.Text = finalValue; logs.Add(new LogInfo(LogState.Success, $"Interface [{varKey}] set to [{finalValue}]")); match = true; } break; case UIType.RadioGroup: { Debug.Assert(uiCmd.Info.GetType() == typeof(UIInfo_RadioGroup)); UIInfo_RadioGroup uiInfo = uiCmd.Info as UIInfo_RadioGroup; int idx = uiInfo.Items.FindIndex(x => x.Equals(finalValue, StringComparison.OrdinalIgnoreCase)); if (idx == -1) { // Invalid Index logs.Add(new LogInfo(LogState.Warning, $"[{finalValue}] not found in item list")); return(logs); } uiInfo.Selected = idx; logs.Add(new LogInfo(LogState.Success, $"Interface [{varKey}] set to [{finalValue}]")); match = true; } break; } if (match) { uiCmd.Update(); logs.AddRange(Variables.SetVariable(s, info.VarKey, info.VarValue, false, false)); return(logs); } else { goto case false; } #endregion } case false: default: return(Variables.SetVariable(s, info.VarKey, info.VarValue, info.Global, info.Permanent)); } }