public override bool ExecuteAction(ActionProgramRun ap)
        {
            string exp;

            if (ap.Functions.ExpandString(UserData, out exp) != Functions.ExpandResult.Failed)
            {
                StringParser sp     = new StringParser(exp);
                string       handle = sp.NextWordComma();

                if (handle != null)
                {
                    bool infile  = ap.ActionFile.Dialogs.ContainsKey(handle);
                    bool inlocal = ap.Dialogs.ContainsKey(handle);

                    ExtendedControls.ConfigurableForm f = infile ? ap.ActionFile.Dialogs[handle] : (inlocal ? ap.Dialogs[handle] : null);

                    string cmd = sp.NextWordLCInvariant();

                    if (cmd == null)
                    {
                        ap.ReportError("Missing command in DialogControl");
                    }
                    else if (cmd.Equals("exists"))
                    {
                        ap["Exists"] = (f != null) ? "1" : "0";
                    }
                    else if (f == null)
                    {
                        ap.ReportError("No such dialog exists in DialogControl");
                    }
                    else if (cmd.Equals("continue"))
                    {
                        return((inlocal) ? false : true); // if local, pause. else just ignore
                    }
                    else if (cmd.Equals("position"))      // verified 10/1/21
                    {
                        int?x = sp.NextIntComma(",");
                        int?y = sp.NextInt();

                        if (x != null)
                        {
                            if (y != null)
                            {
                                f.Location = new System.Drawing.Point(x.Value, y.Value);
                            }
                            else
                            {
                                ap.ReportError("Missing position in DialogControl position");
                            }
                        }
                        else if (sp.IsEOL)
                        {
                            ap["X"] = f.Location.X.ToStringInvariant();
                            ap["Y"] = f.Location.Y.ToStringInvariant();
                        }
                        else
                        {
                            ap.ReportError("Missing position in DialogControl position");
                        }
                    }
                    else if (cmd.Equals("size"))    // verified 10/1/21
                    {
                        int?w = sp.NextIntComma(",");
                        int?h = sp.NextInt();

                        if (w != null)
                        {
                            if (h != null)
                            {
                                f.Size = new System.Drawing.Size(w.Value, h.Value);
                            }
                            else
                            {
                                ap.ReportError("Missing size in DialogControl size");
                            }
                        }
                        else if (sp.IsEOL)
                        {
                            ap["W"] = f.Size.Width.ToStringInvariant();
                            ap["H"] = f.Size.Height.ToStringInvariant();
                        }
                        else
                        {
                            ap.ReportError("Missing size in DialogControl size");
                        }
                    }
                    else if (cmd.Equals("get"))
                    {
                        string control = sp.NextQuotedWord();
                        string r;

                        if (control != null && (r = f.Get(control)) != null)
                        {
                            ap["DialogResult"] = r;
                        }
                        else
                        {
                            ap.ReportError("Missing or invalid dialog name in DialogControl get");
                        }
                    }
                    else if (cmd.Equals("set"))
                    {
                        string control = sp.NextQuotedWord(" =");
                        string value   = sp.IsCharMoveOn('=') ? sp.NextQuotedWord() : null;
                        if (control != null && value != null)
                        {
                            if (!f.Set(control, value))
                            {
                                ap.ReportError("Cannot set control " + control + " in DialogControl set");
                            }
                        }
                        else
                        {
                            ap.ReportError("Missing or invalid dialog name and/or value in DialogControl set");
                        }
                    }
                    else if (cmd.Equals("enable") || cmd.Equals("visible"))     // verified 10/1/21
                    {
                        string  control = sp.NextQuotedWord();
                        Control c;

                        if (control != null && (c = f.GetControl(control)) != null)
                        {
                            bool?r = sp.NextBoolComma();

                            if (r != null)
                            {
                                if (cmd.Equals("enable"))
                                {
                                    c.Enabled = r.Value;
                                }
                                else
                                {
                                    c.Visible = r.Value;
                                }
                            }
                            else if (sp.IsEOL)
                            {
                                if (cmd.Equals("enable"))
                                {
                                    ap["Enabled"] = c.Enabled.ToStringIntValue();
                                }
                                else
                                {
                                    ap["Visible"] = c.Visible.ToStringIntValue();
                                }
                            }
                            else
                            {
                                ap.ReportError("Missing or invalid " + cmd + "value in DialogControl " + cmd);
                            }
                        }
                        else
                        {
                            ap.ReportError("Missing or invalid dialog control name in DialogControl " + cmd);
                        }
                    }
                    else if (cmd.Equals("controlbounds"))       // verified 10/1/21
                    {
                        string  control = sp.NextQuotedWord();
                        Control c;

                        if (control != null && (c = f.GetControl(control)) != null)
                        {
                            int?x = sp.NextIntComma(",");
                            int?y = sp.NextIntComma(",");
                            int?w = sp.NextIntComma(",");
                            int?h = sp.NextInt();

                            if (x != null && y != null && w != null && h != null)
                            {
                                c.Bounds = new System.Drawing.Rectangle(x.Value, y.Value, w.Value, h.Value);
                            }
                            else if (sp.IsEOL)
                            {
                                ap["X"] = c.Left.ToStringInvariant();
                                ap["Y"] = c.Top.ToStringInvariant();
                                ap["W"] = c.Width.ToStringInvariant();
                                ap["H"] = c.Height.ToStringInvariant();
                            }
                            else
                            {
                                ap.ReportError("Missing or invalid bounds values in DialogControl controlbounds");
                            }
                        }
                        else
                        {
                            ap.ReportError("Missing or invalid dialog control name in DialogControl controlbounds");
                        }
                    }
                    else if (cmd.Equals("close"))
                    {
                        f.ReturnResult(f.DialogResult);
                        if (inlocal)
                        {
                            ap.Dialogs.Remove(handle);
                        }
                        else
                        {
                            ap.ActionFile.Dialogs.Remove(handle);
                        }
                    }
                    else
                    {
                        ap.ReportError("Unknown command in DialogControl");
                    }
                }
                else
                {
                    ap.ReportError("Missing handle in DialogControl");
                }
            }
            else
            {
                ap.ReportError(exp);
            }

            return(true);
        }
Ejemplo n.º 2
0
        public override bool ExecuteAction(ActionProgramRun ap)
        {
            string exp;

            if (ap.functions.ExpandString(UserData, out exp) != ConditionFunctions.ExpandResult.Failed)
            {
                StringParser sp     = new StringParser(exp);
                string       handle = sp.NextWordComma();

                if (handle != null)
                {
                    bool infile  = ap.actionfile.dialogs.ContainsKey(handle);
                    bool inlocal = ap.dialogs.ContainsKey(handle);

                    ExtendedControls.ConfigurableForm f = infile ? ap.actionfile.dialogs[handle] : (inlocal ? ap.dialogs[handle] : null);

                    string cmd = sp.NextWord(lowercase: true);

                    if (cmd == null)
                    {
                        ap.ReportError("Missing command in DialogControl");
                    }
                    else if (cmd.Equals("exists"))
                    {
                        ap["Exists"] = (f != null) ? "1" : "0";
                    }
                    else if (f == null)
                    {
                        ap.ReportError("No such dialog exists in DialogControl");
                    }
                    else if (cmd.Equals("continue"))
                    {
                        return((inlocal) ? false : true);    // if local, pause. else just ignore
                    }
                    else if (cmd.Equals("position"))
                    {
                        ap["X"] = f.Location.X.ToStringInvariant();
                        ap["Y"] = f.Location.Y.ToStringInvariant();
                    }
                    else if (cmd.Equals("get"))
                    {
                        string control = sp.NextWord();
                        string r;

                        if (control != null && (r = f.Get(control)) != null)
                        {
                            ap["DialogResult"] = r;
                        }
                        else
                        {
                            ap.ReportError("Missing or invalid dialog name in DialogControl get");
                        }
                    }
                    else if (cmd.Equals("set"))
                    {
                        string control = sp.NextWord(" =");
                        string value   = sp.IsCharMoveOn('=') ? sp.NextQuotedWord() : null;
                        if (control != null && value != null)
                        {
                            if (!f.Set(control, value))
                            {
                                ap.ReportError("Cannot set control " + control + " in DialogControl set");
                            }
                        }
                        else
                        {
                            ap.ReportError("Missing or invalid dialog name and/or value in DialogControl set");
                        }
                    }
                    else if (cmd.Equals("close"))
                    {
                        f.Close();
                        if (inlocal)
                        {
                            ap.dialogs.Remove(handle);
                        }
                        else
                        {
                            ap.actionfile.dialogs.Remove(handle);
                        }
                    }
                    else
                    {
                        ap.ReportError("Unknown command in DialogControl");
                    }
                }
                else
                {
                    ap.ReportError("Missing handle in DialogControl");
                }
            }
            else
            {
                ap.ReportError(exp);
            }

            return(true);
        }