private static UIInfo ParseUICommandInfo(UIType type, List <string> fullArgs) { // Only use fields starting from 8th operand List <string> args = fullArgs.Skip(6).ToList(); // Remove Text, Visibility, X, Y, width, height switch (type) { #region TextBox case UIType.TextBox: { const int minOpCount = 1; const int maxOpCount = 1; if (CodeParser.CheckInfoArgumentCount(args, minOpCount, maxOpCount + 1)) // +1 for tooltip { throw new InvalidCommandException($"[{type}] can have [{minOpCount}] ~ [{maxOpCount + 1}] arguments"); } return(new UIInfo_TextBox(GetInfoTooltip(args, maxOpCount), StringEscaper.Unescape(args[0]))); } #endregion #region TextLabel case UIType.TextLabel: { const int minOpCount = 1; const int maxOpCount = 2; if (CodeParser.CheckInfoArgumentCount(args, minOpCount, maxOpCount + 1)) // +1 for tooltip { throw new InvalidCommandException($"[{type}] can have [{minOpCount}] ~ [{maxOpCount + 1}] arguments"); } NumberHelper.ParseInt32(args[0], out int fontSize); UIInfo_TextLabel_Style style = UIInfo_TextLabel_Style.Normal; if (args[1].Equals("Bold", StringComparison.OrdinalIgnoreCase)) { style = UIInfo_TextLabel_Style.Bold; } else if (args[1].Equals("Italic", StringComparison.OrdinalIgnoreCase)) { style = UIInfo_TextLabel_Style.Italic; } else if (args[1].Equals("Underline", StringComparison.OrdinalIgnoreCase)) { style = UIInfo_TextLabel_Style.Underline; } else if (args[1].Equals("Strike", StringComparison.OrdinalIgnoreCase)) { style = UIInfo_TextLabel_Style.Strike; } return(new UIInfo_TextLabel(GetInfoTooltip(args, maxOpCount), fontSize, style)); } #endregion #region NumberBox case UIType.NumberBox: { const int minOpCount = 4; const int maxOpCount = 4; if (CodeParser.CheckInfoArgumentCount(args, minOpCount, maxOpCount + 1)) // +1 for tooltip { throw new InvalidCommandException($"[{type}] can have [{minOpCount}] ~ [{maxOpCount + 1}] arguments"); } NumberHelper.ParseInt32(args[0], out int value); NumberHelper.ParseInt32(args[1], out int min); NumberHelper.ParseInt32(args[2], out int max); NumberHelper.ParseInt32(args[3], out int interval); return(new UIInfo_NumberBox(GetInfoTooltip(args, maxOpCount), value, min, max, interval)); } #endregion #region CheckBox case UIType.CheckBox: { const int minOpCount = 1; const int maxOpCount = 3; // +2 for [RunOptional] if (CodeParser.CheckInfoArgumentCount(args, minOpCount, maxOpCount + 1)) // +1 for tooltip { throw new InvalidCommandException($"[{type}] can have [{minOpCount}] ~ [{maxOpCount + 1}] arguments"); } bool _checked = false; if (args[0].Equals("True", StringComparison.OrdinalIgnoreCase)) { _checked = true; } else if (args[0].Equals("False", StringComparison.OrdinalIgnoreCase) == false) { throw new InvalidCommandException($"Invalid argument [{args[0]}], must be [True] or [False]"); } string tooltip = null; if (args.Last().StartsWith("__", StringComparison.Ordinal)) // Has <ToolTip> { tooltip = GetInfoTooltip(args, args.Count - 1); } string sectionName = null; bool hideProgress = false; if (3 <= args.Count && (args[2].Equals("True", StringComparison.OrdinalIgnoreCase) || args[2].Equals("False", StringComparison.OrdinalIgnoreCase)) && (args[1].StartsWith("_", StringComparison.Ordinal) && args[1].EndsWith("_", StringComparison.Ordinal))) { // Has [RunOptinal] -> <SectionName>,<HideProgress> if (args[2].Equals("True", StringComparison.OrdinalIgnoreCase)) { hideProgress = true; } else if (args[2].Equals("False", StringComparison.OrdinalIgnoreCase) == false) { throw new InvalidCommandException($"Invalid argument [{args[2]}], must be [True] or [False]"); } sectionName = args[1].Substring(1, args[1].Length - 2); } return(new UIInfo_CheckBox(tooltip, _checked, sectionName, hideProgress)); } #endregion #region ComboBox case UIType.ComboBox: { // Variable Length List <string> items = new List <string>(); // Have ToolTip? string toolTip = null; int cnt = args.Count; if (args.Last().StartsWith("__", StringComparison.Ordinal)) { toolTip = args.Last(); cnt -= 1; } string sectionName = null; bool hideProgress = false; if (2 <= cnt && (args[cnt - 1].Equals("True", StringComparison.OrdinalIgnoreCase) || args[cnt - 1].Equals("False", StringComparison.OrdinalIgnoreCase)) && (args[cnt - 2].StartsWith("_", StringComparison.Ordinal) && args[cnt - 2].EndsWith("_", StringComparison.Ordinal))) { // Has [RunOptinal] -> <SectionName>,<HideProgress> if (args[cnt - 1].Equals("True", StringComparison.OrdinalIgnoreCase)) { hideProgress = true; } else if (args[cnt - 1].Equals("False", StringComparison.OrdinalIgnoreCase) == false) { throw new InvalidCommandException($"Invalid argument [{args[cnt - 1]}], must be [True] or [False]"); } sectionName = args[cnt - 2].Substring(1, args[cnt - 2].Length - 2); cnt -= 2; } for (int i = 0; i < cnt; i++) { items.Add(args[i]); } int idx = items.IndexOf(fullArgs[0]); if (idx == -1) { throw new InvalidCommandException($"[{type}] has wrong selected value [{fullArgs[0]}]"); } return(new UIInfo_ComboBox(toolTip, items, idx, sectionName, hideProgress)); } #endregion #region Image case UIType.Image: { const int minOpCount = 0; const int maxOpCount = 1; // [URL] if (CodeParser.CheckInfoArgumentCount(args, minOpCount, maxOpCount + 1)) // +1 for tooltip { throw new InvalidCommandException($"[{type}] can have [{minOpCount}] ~ [{maxOpCount + 1}] arguments"); } string url = null; if (maxOpCount < args.Count) { url = args[maxOpCount]; } return(new UIInfo_Image(GetInfoTooltip(args, maxOpCount), url)); } #endregion #region TextFile case UIType.TextFile: { const int minOpCount = 0; const int maxOpCount = 0; if (CodeParser.CheckInfoArgumentCount(args, minOpCount, maxOpCount + 1)) { throw new InvalidCommandException($"[{type}] can have [{minOpCount}] ~ [{maxOpCount + 1}] arguments"); } return(new UIInfo_TextFile(GetInfoTooltip(args, maxOpCount))); } #endregion #region Button case UIType.Button: { // <SectionToRun>,<Picture>,[HideProgress] +[UnknownBoolean] +[RunOptional] // Ex) // pButton1 =,1,8,382,47,24,24,Process-OpenDriver_x86,opendir.bmp,False,_Process-OpenDriver_x86,False,_Process-OpenDriver_x86_,False // Button_Download=,1,8,403,21,24,24,DownloadXXX,DoubleJDesignRavenna3dArrowDown0016016.bmp,False,False,_DownloadXXX_,False,"__DOWNLOAD Plugin" // OpendirSMFilesButton=,1,8,475,204,24,24,Opendir_SMFiles,opendir.bmp,"__Open Custom .ini Folder" // Button_HiveUnload_Target="HiveUnload: Target + ProjectTemp + MountFolders",1,8,15,17,293,46,HiveUnload_Launch_B,HiveUnload3232.bmp,0,"__UnLoad hives" // Button_Tools_Folder="Open Tools Folder",1,8,98,256,134,25,Open_Tools_Folder const int minOpCount = 1; if (CodeParser.CheckInfoArgumentCount(args, minOpCount, -1)) { throw new InvalidCommandException($"[{type}] must have at least [{minOpCount}] arguments"); } int cnt = args.Count; string tooltip = null; if (args.Last().StartsWith("__", StringComparison.Ordinal)) // Has <ToolTip> { tooltip = GetInfoTooltip(args, cnt - 1); cnt -= 1; } string sectionName = args[0]; string picture = null; if (2 <= cnt) { if (args[1].Equals("0", StringComparison.OrdinalIgnoreCase) == false) { picture = args[1]; } } bool hideProgress = false; if (3 <= cnt) { if (args[2].Equals("True", StringComparison.OrdinalIgnoreCase)) { hideProgress = true; } else if (args[2].Equals("False", StringComparison.OrdinalIgnoreCase) == false) { // WB082 Compability Shim if (args[2].Equals("1", StringComparison.Ordinal)) { hideProgress = true; } else if (args[2].Equals("0", StringComparison.Ordinal) == false) { throw new InvalidCommandException($"Invalid argument [{args[2]}], must be [True] or [False]"); } } } // Ignore [UnknownBoolean] and [RunOptional] return(new UIInfo_Button(tooltip, args[0], picture, hideProgress)); } #endregion #region WebLabel case UIType.WebLabel: { const int minOpCount = 1; const int maxOpCount = 1; if (CodeParser.CheckInfoArgumentCount(args, minOpCount, maxOpCount + 1)) // +1 for tooltip { throw new InvalidCommandException($"[{type}] can have [{minOpCount}] ~ [{maxOpCount + 1}] arguments"); } return(new UIInfo_WebLabel(GetInfoTooltip(args, maxOpCount), StringEscaper.Unescape(args[0]))); } #endregion #region RadioButton case UIType.RadioButton: { const int minOpCount = 1; const int maxOpCount = 3; // +2 for [RunOptional] if (CodeParser.CheckInfoArgumentCount(args, minOpCount, maxOpCount + 1)) { throw new InvalidCommandException($"[{type}] can have [{minOpCount}] ~ [{maxOpCount + 1}] arguments"); } bool selected = false; if (args[0].Equals("True", StringComparison.OrdinalIgnoreCase)) { selected = true; } else if (args[0].Equals("False", StringComparison.OrdinalIgnoreCase) == false) { throw new InvalidCommandException($"Invalid argument [{args[0]}], must be [True] or [False]"); } string tooltip = null; if (args.Last().StartsWith("__", StringComparison.Ordinal)) // Has <ToolTip> { tooltip = GetInfoTooltip(args, args.Count - 1); } string sectionName = null; bool hideProgress = false; if (3 <= args.Count && (args[2].Equals("True", StringComparison.OrdinalIgnoreCase) || args[2].Equals("False", StringComparison.OrdinalIgnoreCase)) && (args[1].StartsWith("_", StringComparison.Ordinal) && args[1].EndsWith("_", StringComparison.Ordinal))) { // Has [RunOptinal] -> <SectionName>,<HideProgress> if (args[2].Equals("True", StringComparison.OrdinalIgnoreCase)) { hideProgress = true; } else if (args[2].Equals("False", StringComparison.OrdinalIgnoreCase) == false) { throw new InvalidCommandException($"Invalid argument [{args[2]}], must be [True] or [False]"); } sectionName = args[1].Substring(1, args[1].Length - 2); } return(new UIInfo_RadioButton(tooltip, selected, sectionName, hideProgress)); } #endregion #region Bevel case UIType.Bevel: { const int minOpCount = 0; const int maxOpCount = 0; if (CodeParser.CheckInfoArgumentCount(args, minOpCount, maxOpCount + 1)) { throw new InvalidCommandException($"[{type}] can have [{minOpCount}] ~ [{maxOpCount + 1}] arguments"); } return(new UIInfo_Bevel(GetInfoTooltip(args, maxOpCount))); } #endregion #region FileBox case UIType.FileBox: { const int minOpCount = 0; const int maxOpCount = 1; if (CodeParser.CheckInfoArgumentCount(args, minOpCount, maxOpCount + 1)) { throw new InvalidCommandException($"[{type}] can have [{minOpCount}] ~ [{maxOpCount + 1}] arguments"); } bool isFile = false; if (0 < args.Count) { if (args[0].Equals("file", StringComparison.OrdinalIgnoreCase)) { isFile = true; } else if (args[0].Equals("dir", StringComparison.OrdinalIgnoreCase)) { isFile = false; } else { throw new InvalidCommandException($"Argument [{type}] should be one of [file] or [dir]"); } } return(new UIInfo_FileBox(GetInfoTooltip(args, maxOpCount), isFile)); } #endregion #region RadioGroup case UIType.RadioGroup: { // Variable Length List <string> items = new List <string>(); string sectionName = null; bool showProgress = false; int cnt = args.Count - 1; if (args.Last().StartsWith("__", StringComparison.Ordinal)) // Has <ToolTip> { cnt -= 1; } if ((args[cnt].Equals("True", StringComparison.OrdinalIgnoreCase) || args[cnt].Equals("False", StringComparison.OrdinalIgnoreCase)) && (args[cnt - 1].StartsWith("_", StringComparison.Ordinal) && args[cnt - 1].EndsWith("_", StringComparison.Ordinal))) { // Has [RunOptinal] -> <SectionName>,<HideProgress> if (args[cnt].Equals("True", StringComparison.OrdinalIgnoreCase)) { showProgress = true; } else if (args[cnt].Equals("False", StringComparison.OrdinalIgnoreCase) == false) { throw new InvalidCommandException($"Invalid argument [{args[cnt]}], must be [True] or [False]"); } sectionName = args[cnt - 1].Substring(1, args[cnt - 1].Length - 2); cnt -= 2; } for (int i = 0; i < cnt; i++) { items.Add(args[i]); } if (NumberHelper.ParseInt32(args[cnt], out int idx) == false) { throw new InvalidCommandException($"Invalid argument [{args[cnt]}], must be integer"); } return(new UIInfo_RadioGroup(GetInfoTooltip(args, args.Count), items, idx, sectionName, showProgress)); } #endregion #region default default: Debug.Assert(false); break; #endregion } throw new InvalidCommandException($"Invalid UICommand [{type}]"); }
private static UIInfo ParseUIControlInfo(UIControlType type, List <string> fullArgs) { // Only use fields starting from 8th operand List <string> args = fullArgs.Skip(6).ToList(); // Remove Text, Visibility, X, Y, width, height switch (type) { #region TextBox case UIControlType.TextBox: { const int minOpCount = 1; const int maxOpCount = 1; if (CodeParser.CheckInfoArgumentCount(args, minOpCount, maxOpCount + 1)) // +1 for tooltip { throw new InvalidCommandException($"[{type}] can have [{minOpCount}] ~ [{maxOpCount + 1}] arguments"); } return(new UIInfo_TextBox(GetInfoTooltip(args, maxOpCount), args[0])); } #endregion #region TextLabel case UIControlType.TextLabel: { const int minOpCount = 2; const int maxOpCount = 3; if (CodeParser.CheckInfoArgumentCount(args, minOpCount, maxOpCount + 1)) // +1 for tooltip { throw new InvalidCommandException($"[{type}] can have [{minOpCount}] ~ [{maxOpCount + 1}] arguments"); } int cnt = args.Count; string tooltip = null; if (0 < args.Count && args.Last().StartsWith("__", StringComparison.Ordinal)) // Has <ToolTip> { tooltip = GetInfoTooltip(args, cnt - 1); cnt -= 1; } if (!NumberHelper.ParseInt32(args[0], out int fontSize)) { throw new InvalidCommandException($"FontSize [{args[0]}] is not a valid integer"); } UIFontWeight?weight = ParseUIFontWeight(args[1]); if (weight == null) { throw new InvalidCommandException($"FontWeight [{args[1]}] is invalid"); } UIFontStyle?style = null; if (3 <= cnt) { style = ParseUIFontStyle(args[2]); if (style == null) { throw new InvalidCommandException($"FontStyle [{args[2]}] is invalid"); } } return(new UIInfo_TextLabel(tooltip, fontSize, (UIFontWeight)weight, style)); } #endregion #region NumberBox case UIControlType.NumberBox: { const int minOpCount = 4; const int maxOpCount = 4; if (CodeParser.CheckInfoArgumentCount(args, minOpCount, maxOpCount + 1)) // +1 for tooltip { throw new InvalidCommandException($"[{type}] can have [{minOpCount}] ~ [{maxOpCount + 1}] arguments"); } NumberHelper.ParseInt32(args[0], out int value); NumberHelper.ParseInt32(args[1], out int min); NumberHelper.ParseInt32(args[2], out int max); NumberHelper.ParseInt32(args[3], out int interval); return(new UIInfo_NumberBox(GetInfoTooltip(args, maxOpCount), value, min, max, interval)); } #endregion #region CheckBox case UIControlType.CheckBox: { const int minOpCount = 1; const int maxOpCount = 3; // +2 for [RunOptional] if (CodeParser.CheckInfoArgumentCount(args, minOpCount, maxOpCount + 1)) // +1 for tooltip { throw new InvalidCommandException($"[{type}] can have [{minOpCount}] ~ [{maxOpCount + 1}] arguments"); } bool _checked = false; if (args[0].Equals("True", StringComparison.OrdinalIgnoreCase)) { _checked = true; } else if (args[0].Equals("False", StringComparison.OrdinalIgnoreCase) == false) { throw new InvalidCommandException($"Invalid argument [{args[0]}], must be [True] or [False]"); } string tooltip = null; if (0 < args.Count && args.Last().StartsWith("__", StringComparison.Ordinal)) // Has <ToolTip> { tooltip = GetInfoTooltip(args, args.Count - 1); } string sectionName = null; bool hideProgress = false; if (3 <= args.Count && (args[2].Equals("True", StringComparison.OrdinalIgnoreCase) || args[2].Equals("False", StringComparison.OrdinalIgnoreCase)) && args[1].StartsWith("_", StringComparison.Ordinal) && args[1].EndsWith("_", StringComparison.Ordinal)) { // Has [RunOptional] -> <SectionName>,<HideProgress> if (args[2].Equals("True", StringComparison.OrdinalIgnoreCase)) { hideProgress = true; } else if (args[2].Equals("False", StringComparison.OrdinalIgnoreCase) == false) { throw new InvalidCommandException($"Invalid argument [{args[2]}], must be [True] or [False]"); } // Trim one '_' from start and end string rawSectionName = args[1]; sectionName = rawSectionName.Substring(1, rawSectionName.Length - 2); } return(new UIInfo_CheckBox(tooltip, _checked, sectionName, hideProgress)); } #endregion #region ComboBox case UIControlType.ComboBox: { // Variable Length List <string> items = new List <string>(); int cnt = args.Count; string toolTip = null; if (0 < args.Count && args.Last().StartsWith("__", StringComparison.Ordinal)) // Has <ToolTip> { toolTip = GetInfoTooltip(args, args.Count - 1); cnt -= 1; } string sectionName = null; bool hideProgress = false; if (2 <= cnt && (args[cnt - 1].Equals("True", StringComparison.OrdinalIgnoreCase) || args[cnt - 1].Equals("False", StringComparison.OrdinalIgnoreCase)) && args[cnt - 2].StartsWith("_", StringComparison.Ordinal) && args[cnt - 2].EndsWith("_", StringComparison.Ordinal)) { // Has [RunOptional] -> <SectionName>,<HideProgress> if (args[cnt - 1].Equals("True", StringComparison.OrdinalIgnoreCase)) { hideProgress = true; } else if (args[cnt - 1].Equals("False", StringComparison.OrdinalIgnoreCase) == false) { throw new InvalidCommandException($"Invalid argument [{args[cnt - 1]}], must be [True] or [False]"); } // Trim one '_' from start and end string rawSectionName = args[cnt - 2]; sectionName = rawSectionName.Substring(1, rawSectionName.Length - 2); cnt -= 2; } for (int i = 0; i < cnt; i++) { items.Add(args[i]); } // Allow even if an index is -1. (At least SyntaxChecker will raise an error later) int idx = items.IndexOf(fullArgs[0]); return(new UIInfo_ComboBox(toolTip, items, idx, sectionName, hideProgress)); } #endregion #region Image case UIControlType.Image: { const int minOpCount = 0; const int maxOpCount = 1; // [URL] if (CodeParser.CheckInfoArgumentCount(args, minOpCount, maxOpCount + 1)) // +1 for tooltip { throw new InvalidCommandException($"[{type}] can have [{minOpCount}] ~ [{maxOpCount + 1}] arguments"); } int cnt = args.Count; string tooltip = null; if (0 < args.Count && args.Last().StartsWith("__", StringComparison.Ordinal)) // Has <ToolTip> { tooltip = GetInfoTooltip(args, cnt - 1); cnt -= 1; } string url = null; if (1 <= cnt) { url = args[0]; } return(new UIInfo_Image(tooltip, url)); } #endregion #region TextFile case UIControlType.TextFile: { const int minOpCount = 0; const int maxOpCount = 0; if (CodeParser.CheckInfoArgumentCount(args, minOpCount, maxOpCount + 1)) { throw new InvalidCommandException($"[{type}] can have [{minOpCount}] ~ [{maxOpCount + 1}] arguments"); } return(new UIInfo_TextFile(GetInfoTooltip(args, maxOpCount))); } #endregion #region Button case UIControlType.Button: { // <SectionToRun>,<Picture>,[HideProgress] +[UnknownBoolean] +[RunOptional] // Ex) // pButton1 =,1,8,382,47,24,24,Process-OpenDriver_x86,opendir.bmp,False,_Process-OpenDriver_x86,False,_Process-OpenDriver_x86_,False // Button_Download=,1,8,403,21,24,24,DownloadXXX,DoubleJDesignRavenna3dArrowDown0016016.bmp,False,False,_DownloadXXX_,False,"__DOWNLOAD Script" // OpendirSMFilesButton=,1,8,475,204,24,24,Opendir_SMFiles,opendir.bmp,"__Open Custom .ini Folder" // Button_HiveUnload_Target="HiveUnload: Target + ProjectTemp + MountFolders",1,8,15,17,293,46,HiveUnload_Launch_B,HiveUnload3232.bmp,0,"__UnLoad hives" // Button_Tools_Folder="Open Tools Folder",1,8,98,256,134,25,Open_Tools_Folder const int minOpCount = 1; if (CodeParser.CheckInfoArgumentCount(args, minOpCount, -1)) { throw new InvalidCommandException($"[{type}] must have at least [{minOpCount}] arguments"); } int cnt = args.Count; string tooltip = null; if (0 < args.Count && args.Last().StartsWith("__", StringComparison.Ordinal)) // Has <ToolTip> { tooltip = GetInfoTooltip(args, cnt - 1); cnt -= 1; } string picture = null; if (2 <= cnt) { if (!args[1].Equals("0", StringComparison.OrdinalIgnoreCase)) { picture = args[1]; } } bool hideProgress = false; if (3 <= cnt) { if (args[2].Equals("True", StringComparison.OrdinalIgnoreCase)) { hideProgress = true; } else if (!args[2].Equals("False", StringComparison.OrdinalIgnoreCase)) { // WB082 Compability Shim if (args[2].Equals("1", StringComparison.Ordinal)) { hideProgress = true; } else if (!args[2].Equals("0", StringComparison.Ordinal)) { throw new InvalidCommandException($"Invalid argument [{args[2]}], must be [True] or [False]"); } } } // Ignore [UnknownBoolean] and [RunOptional] return(new UIInfo_Button(tooltip, args[0], picture, hideProgress)); } #endregion #region WebLabel case UIControlType.WebLabel: { const int minOpCount = 1; const int maxOpCount = 1; if (CodeParser.CheckInfoArgumentCount(args, minOpCount, maxOpCount + 1)) // +1 for tooltip { throw new InvalidCommandException($"[{type}] can have [{minOpCount}] ~ [{maxOpCount + 1}] arguments"); } return(new UIInfo_WebLabel(GetInfoTooltip(args, maxOpCount), args[0])); } #endregion #region RadioButton case UIControlType.RadioButton: { const int minOpCount = 1; const int maxOpCount = 3; // +2 for [RunOptional] if (CodeParser.CheckInfoArgumentCount(args, minOpCount, maxOpCount + 1)) { throw new InvalidCommandException($"[{type}] can have [{minOpCount}] ~ [{maxOpCount + 1}] arguments"); } bool selected = false; if (args[0].Equals("True", StringComparison.OrdinalIgnoreCase)) { selected = true; } else if (!args[0].Equals("False", StringComparison.OrdinalIgnoreCase)) { throw new InvalidCommandException($"Invalid argument [{args[0]}], must be [True] or [False]"); } string tooltip = null; if (0 < args.Count && args.Last().StartsWith("__", StringComparison.Ordinal)) // Has <ToolTip> { tooltip = GetInfoTooltip(args, args.Count - 1); } string sectionName = null; bool hideProgress = false; if (3 <= args.Count && (args[2].Equals("True", StringComparison.OrdinalIgnoreCase) || args[2].Equals("False", StringComparison.OrdinalIgnoreCase)) && args[1].StartsWith("_", StringComparison.Ordinal) && args[1].EndsWith("_", StringComparison.Ordinal)) { // Has [RunOptional] -> <SectionName>,<HideProgress> if (args[2].Equals("True", StringComparison.OrdinalIgnoreCase)) { hideProgress = true; } else if (args[2].Equals("False", StringComparison.OrdinalIgnoreCase) == false) { throw new InvalidCommandException($"Invalid argument [{args[2]}], must be [True] or [False]"); } // Trim one '_' from start and end string rawSectionName = args[1]; sectionName = rawSectionName.Substring(1, rawSectionName.Length - 2); } return(new UIInfo_RadioButton(tooltip, selected, sectionName, hideProgress)); } #endregion #region Bevel case UIControlType.Bevel: { const int minOpCount = 0; const int maxOpCount = 3; if (CodeParser.CheckInfoArgumentCount(args, minOpCount, maxOpCount + 1)) // +1 for tooltip { throw new InvalidCommandException($"[{type}] can have [{minOpCount}] ~ [{maxOpCount + 1}] arguments"); } int cnt = args.Count; string tooltip = null; if (0 < args.Count && args.Last().StartsWith("__", StringComparison.Ordinal)) // Has <ToolTip> { tooltip = GetInfoTooltip(args, cnt - 1); cnt -= 1; } int? fontSize = null; UIFontWeight?weight = null; UIFontStyle? style = null; if (1 <= cnt) { if (!NumberHelper.ParseInt32(args[0], out int fontSizeVal)) { throw new InvalidCommandException($"FontSize {args[0]} is not a valid integer"); } fontSize = fontSizeVal; } if (2 <= cnt) { weight = ParseUIFontWeight(args[1]); if (weight == null) { throw new InvalidCommandException($"FontWeight [{args[1]}] is invalid"); } } if (3 <= cnt) { style = ParseUIFontStyle(args[2]); if (style == null) { throw new InvalidCommandException($"FontStyle [{args[2]}] is invalid"); } } return(new UIInfo_Bevel(tooltip, fontSize, weight, style)); } #endregion #region FileBox case UIControlType.FileBox: { const int minOpCount = 0; const int maxOpCount = 3; if (CodeParser.CheckInfoArgumentCount(args, minOpCount, maxOpCount + 1)) { throw new InvalidCommandException($"[{type}] can have [{minOpCount}] ~ [{maxOpCount + 1}] arguments"); } bool isFile = false; if (0 < args.Count) { if (args[0].Equals("file", StringComparison.OrdinalIgnoreCase)) { isFile = true; } else if (!args[0].Equals("dir", StringComparison.OrdinalIgnoreCase)) { throw new InvalidCommandException($"Argument [{type}] should be either [file] or [dir]"); } } string title = null; string filter = null; string tooltip = null; const string titleKey = "Title="; const string filterKey = "Filter="; for (int i = 1; i < args.Count; i++) { string arg = args[i]; if (arg.StartsWith(titleKey, StringComparison.OrdinalIgnoreCase)) { if (title != null) { throw new InvalidCommandException("Argument <Title> cannot be duplicated"); } title = arg.Substring(titleKey.Length); } else if (arg.StartsWith(filterKey, StringComparison.OrdinalIgnoreCase)) { if (!isFile) { throw new InvalidCommandException("Argument <Filter> can only be used for file selection"); } if (filter != null) { throw new InvalidCommandException("Argument <Filter> cannot be duplicated"); } filter = arg.Substring(filterKey.Length); } else if (arg.StartsWith("__", StringComparison.OrdinalIgnoreCase)) // ToolTip { tooltip = GetInfoTooltip(args, i); } else { throw new InvalidCommandException($"Invalid optional argument [{arg}]"); } } return(new UIInfo_FileBox(tooltip, isFile, title, filter)); } #endregion #region RadioGroup case UIControlType.RadioGroup: { // Variable Length List <string> items = new List <string>(); string sectionName = null; bool showProgress = false; int cnt = args.Count - 1; if (0 < args.Count && args.Last().StartsWith("__", StringComparison.Ordinal)) // Has <ToolTip> { cnt -= 1; } if ((args[cnt].Equals("True", StringComparison.OrdinalIgnoreCase) || args[cnt].Equals("False", StringComparison.OrdinalIgnoreCase)) && args[cnt - 1].StartsWith("_", StringComparison.Ordinal) && args[cnt - 1].EndsWith("_", StringComparison.Ordinal)) { // Has [RunOptional] -> <SectionName>,<HideProgress> if (args[cnt].Equals("True", StringComparison.OrdinalIgnoreCase)) { showProgress = true; } else if (!args[cnt].Equals("False", StringComparison.OrdinalIgnoreCase)) { throw new InvalidCommandException($"Invalid argument [{args[cnt]}], must be [True] or [False]"); } sectionName = args[cnt - 1].Substring(1, args[cnt - 1].Length - 2); cnt -= 2; } for (int i = 0; i < cnt; i++) { items.Add(args[i]); } if (!NumberHelper.ParseInt32(args[cnt], out int idx)) { throw new InvalidCommandException($"Invalid argument [{args[cnt]}], must be an integer"); } return(new UIInfo_RadioGroup(GetInfoTooltip(args, args.Count), items, idx, sectionName, showProgress)); } #endregion #region default default: Debug.Assert(false); break; #endregion } throw new InvalidCommandException($"Invalid interface control type [{type}]"); }