Beispiel #1
0
        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}]");
        }
Beispiel #2
0
 public UIInfo_TextLabel(string tooltip, int fontSize, UIInfo_TextLabel_Style style)
     : base(tooltip)
 {
     this.FontSize = fontSize;
     this.Style    = style;
 }