private void Delete(Group.Conditions c)
        {
            Group g = c.group;

            g.panel.Controls.Remove(c.fname);
            g.panel.Controls.Remove(c.cond);
            g.panel.Controls.Remove(c.value);
            g.panel.Controls.Remove(c.more);
            g.panel.Controls.Remove(c.del);

            g.condlist.Remove(c);

            if (g.condlist.Count == 0)
            {
                panelVScroll.Controls.Remove(g.panel);
                g.panel.Controls.Clear();
                groups.Remove(g);
                onChangeInGroups?.Invoke(groups.Count);
            }

            FixUpGroups();
        }
Пример #2
0
        private void ConditionDelClick(object sender, EventArgs e)
        {
            ExtendedControls.ButtonExt b = sender as ExtendedControls.ButtonExt;
            Group.Conditions           c = (Group.Conditions)b.Tag;
            Group g = c.group;

            g.panel.Controls.Remove(c.fname);
            g.panel.Controls.Remove(c.cond);
            g.panel.Controls.Remove(c.value);
            g.panel.Controls.Remove(c.more);
            g.panel.Controls.Remove(c.del);

            g.condlist.Remove(c);

            if (g.condlist.Count == 0)
            {
                panelVScroll.Controls.Remove(g.panel);
                g.panel.Controls.Clear();
                groups.Remove(g);
            }

            FixUpGroups();
        }
        public string Check()   // calculate if in error, fill Result with what is valid. Empty string if ok
        {
            Result = new ConditionLists();

            string errorlist = "";

            foreach (Group g in groups)
            {
                string innerc = g.innercond.Text;
                string outerc = g.outercond.Text;
                string evt    = (eventlist != null) ? g.evlist.Text : "Default";

                //System.Diagnostics.Debug.WriteLine("Event {0} inner {1} outer {2} action {3} data '{4}'", evt, innerc, outerc, actionname, actiondata );

                Condition fe = new Condition();

                if (evt.Length == 0)        // must have name
                {
                    errorlist += "Ignored group with empty name" + Environment.NewLine;
                }
                else
                {
                    if (fe.Create(evt, "", "", innerc, outerc)) // create must work
                    {
                        for (int i = 0; i < g.condlist.Count; i++)
                        {
                            Group.Conditions c      = g.condlist[i];
                            string           fieldn = c.fname.Text;
                            string           condn  = c.cond.Text;
                            string           valuen = c.value.Text;

                            if (fieldn.Length > 0 || ConditionEntry.IsNullOperation(condn))
                            {
                                ConditionEntry f = new ConditionEntry();

                                if (f.Create(fieldn, condn, valuen))
                                {
                                    if (valuen.Length == 0 && !ConditionEntry.IsUnaryOperation(condn) && !ConditionEntry.IsNullOperation(condn))
                                    {
                                        errorlist += "Do you want filter '" + fieldn + "' in group '" + fe.eventname + "' to have an empty value" + Environment.NewLine;
                                    }

                                    fe.Add(f);
                                }
                                else
                                {
                                    errorlist += "Cannot create filter '" + fieldn + "' in group '" + fe.eventname + "' check value" + Environment.NewLine;
                                }
                            }
                            else
                            {
                                errorlist += "Ignored empty filter " + (i + 1).ToString(System.Globalization.CultureInfo.InvariantCulture) + " in " + fe.eventname + Environment.NewLine;
                            }
                        }

                        if (fe.fields != null)
                        {
                            Result.Add(fe);
                        }
                        else
                        {
                            errorlist += "No valid filters found in group '" + fe.eventname + "'" + Environment.NewLine;
                        }
                    }
                    else
                    {
                        errorlist += "Cannot create " + evt + " not a normal error please report" + Environment.NewLine;
                    }
                }
            }

            return(errorlist);
        }
        private void FixUpGroups(bool calcminsize = true)      // fixes and positions groups.
        {
            SuspendLayout();
            panelVScroll.SuspendLayout();

            int panelwidth = Math.Max(panelVScroll.Width - panelVScroll.ScrollBarWidth, 10);
            int y          = panelymargin;

            for (int i = 0; i < groups.Count; i++)
            {
                Group g = groups[i];
                g.panel.SuspendLayout();

                // for all groups, see if another group below it has the same event selected as ours

                bool showouter = false;

                if (eventlist != null)
                {
                    for (int j = i - 1; j >= 0; j--)
                    {
                        if (groups[j].evlist.Text.Equals(groups[i].evlist.Text) && groups[i].evlist.Text.Length > 0)
                        {
                            showouter = true;
                        }
                    }

                    showouter = showouter && allowoutercond;     // qualify with outer condition switch
                }
                else
                {
                    showouter = (i > 0) && allowoutercond;       // and enabled/disable the outer condition switch
                }
                // Now position the conditions inside the panel

                int vnextcond = panelymargin;

                int condxoffset = (g.evlist != null) ? (g.evlist.Right + 8) : panelxmargin;
                int farx        = condxoffset; // should never not have a condition but ..

                int panelxspacing = Font.ScalePixels(4);
                int panelyspacing = Font.ScalePixels(6);

                for (int condc = 0; condc < g.condlist.Count; condc++)
                {
                    Group.Conditions c = g.condlist[condc];
                    c.fname.Location = new Point(condxoffset, vnextcond);
                    c.fname.Enabled  = !ConditionEntry.IsNullOperation(c.cond.Text);
                    if (!c.fname.Enabled)
                    {
                        c.fname.Text = "";
                    }

                    c.cond.Location = new Point(c.fname.Right + panelxspacing, vnextcond);

                    c.value.Location = new Point(c.cond.Right + panelxspacing, vnextcond);
                    c.value.Width    = panelwidth - condxoffset - c.fname.Width - 4 - c.cond.Width - 4 - c.del.Width - 4 - c.more.Width - 4 - g.innercond.Width - 4 - g.upbutton.Width + 8;
                    c.value.Enabled  = !ConditionEntry.IsNullOperation(c.cond.Text) && !ConditionEntry.IsUnaryOperation(c.cond.Text);
                    if (!c.value.Enabled)
                    {
                        c.value.Text = "";
                    }

                    c.del.Location  = new Point(c.value.Right + panelxspacing, vnextcond);
                    c.more.Location = new Point(c.del.Right + panelxspacing, vnextcond);
                    c.more.Visible  = (condc == g.condlist.Count - 1);

                    vnextcond += c.fname.Height + panelyspacing;
                    farx       = c.more.Left; // where the innercond/up buttons are
                }

                // and the outer/inner conditions

                g.innercond.Visible  = (g.condlist.Count > 1);        // inner condition on if multiple
                g.innercond.Location = new Point(farx, panelymargin); // inner condition is in same place as more button
                farx = g.innercond.Right + panelxspacing;             // move off

                // and the up button..
                g.upbutton.Visible  = (i != 0 && g.condlist.Count > 0);
                g.upbutton.Location = new Point(farx, panelymargin);

                // allocate space for the outercond if req.
                g.outercond.Enabled = g.outercond.Visible = g.outerlabel.Visible = showouter;       // and enabled/disable the outer condition switch

                if (showouter)
                {
                    g.outercond.Location  = new Point(panelxmargin, vnextcond);
                    g.outerlabel.Location = new Point(g.outercond.Location.X + g.outercond.Width + panelxspacing, g.outercond.Location.Y + 3);
                    vnextcond            += g.outercond.Height + panelyspacing;
                }

                // pos the panel

                g.panel.Location    = new Point(panelxmargin, y + panelVScroll.ScrollOffset);
                g.panel.Size        = new Size(Math.Max(panelwidth - panelxmargin * 2, farx), Math.Max(vnextcond + panelyspacing, g.innercond.Bottom + panelyspacing));
                g.panel.BorderStyle = (g.condlist.Count > 1) ? BorderStyle.FixedSingle : BorderStyle.None;

                y += g.panel.Height + panelyspacing * 2;

                // and make sure actions list is right

                g.panel.ResumeLayout();
            }

            if (allowoutercond || groups.Count == 0)
            {
                buttonMore.Location = new Point(panelxmargin, y + panelVScroll.ScrollOffset);
                buttonMore.Visible  = true;
                y = buttonMore.Bottom;
            }
            else
            {
                buttonMore.Visible = false;
            }

            if (calcminsize)
            {
                onCalcMinsize?.Invoke(y);
            }

            panelVScroll.ResumeLayout();
            ResumeLayout();
            Invalidate(true);
            Update();
        }
 private void ConditionDelClick(object sender, EventArgs e)
 {
     ExtendedControls.ExtButton b = sender as ExtendedControls.ExtButton;
     Group.Conditions           c = (Group.Conditions)b.Tag;
     Delete(c);
 }
        private void CreateConditionInt(Group g, string initialfname, string initialcond, string initialvalue)
        {
            g.panel.SuspendLayout();

            g.panel.Scale(FindForm().InvCurrentAutoScaleFactor());      // until i rewrite this, so conditions are all in a panel, we need to remove then reapply scaling

            Group.Conditions c = new Group.Conditions();

            c.fname = new ExtendedControls.ExtTextBoxAutoComplete();
            c.fname.EndButtonVisible = true;
            c.fname.Name             = "CVar";
            c.fname.Size             = new Size(200, 24);
            c.fname.SetAutoCompletor(AutoCompletor);
            c.fname.Tag = new Tuple <Group, Group.Conditions>(g, c);
            c.fname.AutoCompleteCommentMarker = commentmarker;
            if (initialfname != null)
            {
                c.fname.Text = initialfname;
            }
            g.panel.Controls.Add(c.fname);                                                // 1st control

            c.cond = new ExtendedControls.ExtComboBox();
            c.cond.Items.AddRange(ConditionEntry.MatchNames);
            c.cond.SelectedIndex = 0;
            c.cond.Size          = new Size(140, 24);
            c.cond.Tag           = g;

            if (initialcond != null)
            {
                c.cond.Text = initialcond.SplitCapsWord();
            }

            c.cond.SelectedIndexChanged += Cond_SelectedIndexChanged; // and turn on handler

            g.panel.Controls.Add(c.cond);                             // must be next

            c.value      = new ExtendedControls.ExtTextBox();
            c.value.Size = new Size(100, 24);  // width will be set in positioning

            if (initialvalue != null)
            {
                c.value.Text = initialvalue;
            }

            g.panel.Controls.Add(c.value);         // must be next

            c.del        = new ExtendedControls.ExtButton();
            c.del.Size   = new Size(24, 24);
            c.del.Text   = "X";
            c.del.Click += ConditionDelClick;
            c.del.Tag    = c;
            g.panel.Controls.Add(c.del);

            c.more        = new ExtendedControls.ExtButton();
            c.more.Size   = new Size(24, 24);
            c.more.Text   = "+";
            c.more.Click += NewConditionClick;
            c.more.Tag    = g;
            g.panel.Controls.Add(c.more);

            c.group = g;
            g.condlist.Add(c);

            g.variables             = CreateVariables(g.evlist?.Text);
            c.fname.EndButtonEnable = (g.variables?.Count ?? 0) > 0;

            c.fname.TextChanged += TextChangedInLeft;       // only when fully set up do we turn on the text change handler - exception if you do it sooner

            ExtendedControls.ThemeableFormsInstance.Instance.ApplyDialog(g.panel);
            g.panel.Scale(FindForm().CurrentAutoScaleFactor());

            g.panel.ResumeLayout();
        }
Пример #7
0
        void FixUpGroups(bool calcminsize = true)      // fixes and positions groups.
        {
            SuspendLayout();
            panelVScroll.SuspendLayout();

            int panelwidth = Math.Max(panelVScroll.Width - panelVScroll.ScrollBarWidth, 10);
            int y          = panelymargin;

            for (int i = 0; i < groups.Count; i++)
            {
                Group g = groups[i];
                g.panel.SuspendLayout();

                // for all groups, see if another group below it has the same event selected as ours

                bool showouter = false;

                if (eventlist != null)
                {
                    for (int j = i - 1; j >= 0; j--)
                    {
                        if (groups[j].evlist.Text.Equals(groups[i].evlist.Text) && groups[i].evlist.Text.Length > 0)
                        {
                            showouter = true;
                        }
                    }

                    showouter &= allowoutercond;                // qualify with outer condition switch
                }
                else
                {
                    showouter = (i > 0) && allowoutercond;                                    // and enabled/disable the outer condition switch
                }
                g.outercond.Enabled = g.outercond.Visible = g.outerlabel.Visible = showouter; // and enabled/disable the outer condition switch

                // Now position the conditions inside the panel

                int vnextcond = panelymargin;

                int farx = (g.evlist != null) ? (g.evlist.Right - g.innercond.Width + 8) : 0;   // innercond cause below adds it back on

                for (int condc = 0; condc < g.condlist.Count; condc++)
                {
                    Group.Conditions c = g.condlist[condc];
                    c.fname.Location = new Point(condxoffset, vnextcond + 2);
                    c.fname.Enabled  = !ConditionEntry.IsNullOperation(c.cond.Text);
                    if (!c.fname.Enabled)
                    {
                        c.fname.Text = "";
                    }

                    c.cond.Location = new Point(c.fname.Right + 4, vnextcond);

                    c.value.Location = new Point(c.cond.Right + 4, vnextcond + 2);
                    c.value.Size     = new Size(panelwidth - condxoffset - c.fname.Width - 4 - c.cond.Width - 4 - c.del.Width - 4 - c.more.Width - 4 - g.innercond.Width - 4 - g.upbutton.Width + 8, 24);
                    c.value.Enabled  = !ConditionEntry.IsNullOperation(c.cond.Text) && !ConditionEntry.IsUnaryOperation(c.cond.Text);
                    if (!c.value.Enabled)
                    {
                        c.value.Text = "";
                    }

                    c.del.Location  = new Point(c.value.Right + 4, vnextcond);
                    c.more.Location = new Point(c.del.Right + 4, vnextcond);
                    c.more.Visible  = (condc == g.condlist.Count - 1);

                    vnextcond += conditionhoff;
                    farx       = c.more.Left + 4; // where the more button is
                }

                // and the outer/inner conditions

                g.innercond.Visible  = (g.condlist.Count > 1);        // inner condition on if multiple
                g.innercond.Location = new Point(farx, panelymargin); // inner condition is in same place as more button
                farx = g.innercond.Right + 4;                         // move off

                // and the up button..
                g.upbutton.Location = new Point(farx, panelymargin);
                g.upbutton.Visible  = (i != 0);
                farx = g.upbutton.Right;

                // allocate space for the outercond if req.
                if (g.outercond.Enabled)
                {
                    g.outercond.Location  = new Point(panelxmargin, vnextcond);
                    g.outerlabel.Location = new Point(g.outercond.Location.X + g.outercond.Width + 4, g.outercond.Location.Y + 3);
                    vnextcond            += conditionhoff;
                }

                // pos the panel

                g.panel.Location    = new Point(panelxmargin, y + panelVScroll.ScrollOffset);
                g.panel.Size        = new Size(Math.Max(panelwidth - panelxmargin * 2, farx), Math.Max(vnextcond, panelymargin + conditionhoff));
                g.panel.BorderStyle = (g.condlist.Count > 1) ? BorderStyle.FixedSingle : BorderStyle.None;

                y += g.panel.Height + 2;

                // and make sure actions list is right

                g.panel.ResumeLayout();
            }

            buttonMore.Location = new Point(panelxmargin, y + panelVScroll.ScrollOffset);
            buttonMore.Visible  = allowoutercond || groups.Count == 0;

            Rectangle screenRectangle = RectangleToScreen(this.ClientRectangle);
            int       titleHeight     = screenRectangle.Top - this.Top;

            y += buttonMore.Height + titleHeight + ((panelTop.Enabled) ? (panelTop.Height + statusStripCustom.Height) : 8) + 16 + panelOK.Height;

            if (calcminsize)
            {
                this.MinimumSize = new Size(1000, y);
                this.MaximumSize = new Size(Screen.FromControl(this).WorkingArea.Width - 100, Screen.FromControl(this).WorkingArea.Height - 100);

                if (Bottom > Screen.FromControl(this).WorkingArea.Height)
                {
                    Top = Screen.FromControl(this).WorkingArea.Height - Height - 50;
                }
            }

            panelVScroll.ResumeLayout();
            ResumeLayout();
        }
Пример #8
0
        void CreateConditionInt(Group g, string initialfname, string initialcond, string initialvalue)
        {
            g.panel.SuspendLayout();

            Group.Conditions c = new Group.Conditions();

            c.fname      = new ExtendedControls.AutoCompleteTextBox();
            c.fname.Size = new Size(140, 24);
            c.fname.SetAutoCompletor(AutoCompletor);
            c.fname.Tag           = g;
            c.fname.DropDownWidth = 200;
            if (initialfname != null)
            {
                c.fname.Text = initialfname;
            }
            g.panel.Controls.Add(c.fname);                                                // 1st control

            c.cond = new ExtendedControls.ComboBoxCustom();
            c.cond.Items.AddRange(ConditionEntry.MatchNames);
            c.cond.SelectedIndex  = 0;
            c.cond.Size           = new Size(140, 24);
            c.cond.DropDownHeight = 400;
            c.cond.Tag            = g;

            if (initialcond != null)
            {
                c.cond.Text = initialcond.SplitCapsWord();
            }

            c.cond.SelectedIndexChanged += Cond_SelectedIndexChanged; // and turn on handler

            g.panel.Controls.Add(c.cond);                             // must be next

            c.value = new ExtendedControls.TextBoxBorder();

            if (initialvalue != null)
            {
                c.value.Text = initialvalue;
            }

            g.panel.Controls.Add(c.value);         // must be next

            c.del        = new ExtendedControls.ButtonExt();
            c.del.Size   = new Size(24, 24);
            c.del.Text   = "X";
            c.del.Click += ConditionDelClick;
            c.del.Tag    = c;
            g.panel.Controls.Add(c.del);

            c.more        = new ExtendedControls.ButtonExt();
            c.more.Size   = new Size(24, 24);
            c.more.Text   = "+";
            c.more.Click += NewConditionClick;
            c.more.Tag    = g;
            g.panel.Controls.Add(c.more);

            c.group = g;
            g.condlist.Add(c);

            g.panel.ResumeLayout();
        }
Пример #9
0
        private void CreateConditionInt(Group g, string initialfname, string initialcond, string initialvalue)
        {
            g.panel.SuspendLayout();

            Group.Conditions c = new Group.Conditions();

            c.fname = new ExtendedControls.ExtTextBoxAutoComplete();
            c.fname.EndButtonVisible = true;
            c.fname.Name             = "CVar";
            c.fname.Size             = new Size(LeftSizeConditionWidth, 32);
            c.fname.SetAutoCompletor(AutoCompletor);
            c.fname.Tag                       = new Tuple <Group, Group.Conditions>(g, c);
            c.fname.DropDownWidth             = LeftSizeConditionWidth * 3 / 2;
            c.fname.DropDownHeight            = DropDownHeight;
            c.fname.AutoCompleteCommentMarker = commentmarker;
            if (initialfname != null)
            {
                c.fname.Text = initialfname;
            }
            g.panel.Controls.Add(c.fname);                                                // 1st control

            c.cond = new ExtendedControls.ExtComboBox();
            c.cond.Items.AddRange(ConditionEntry.MatchNames);
            c.cond.SelectedIndex  = 0;
            c.cond.Size           = new Size(ConditionWidth, 24);
            c.cond.DropDownHeight = DropDownHeight;
            c.cond.Tag            = g;

            if (initialcond != null)
            {
                c.cond.Text = initialcond.SplitCapsWord();
            }

            c.cond.SelectedIndexChanged += Cond_SelectedIndexChanged; // and turn on handler

            g.panel.Controls.Add(c.cond);                             // must be next

            c.value = new ExtendedControls.ExtTextBox();

            if (initialvalue != null)
            {
                c.value.Text = initialvalue;
            }

            g.panel.Controls.Add(c.value);         // must be next

            c.del        = new ExtendedControls.ExtButton();
            c.del.Size   = new Size(24, 24);
            c.del.Text   = "X";
            c.del.Click += ConditionDelClick;
            c.del.Tag    = c;
            g.panel.Controls.Add(c.del);

            c.more        = new ExtendedControls.ExtButton();
            c.more.Size   = new Size(24, 24);
            c.more.Text   = "+";
            c.more.Click += NewConditionClick;
            c.more.Tag    = g;
            g.panel.Controls.Add(c.more);

            c.group = g;
            g.condlist.Add(c);

            g.variables             = CreateVariables(g.evlist?.Text);
            c.fname.EndButtonEnable = (g.variables?.Count ?? 0) > 0;

            c.fname.TextChanged += TextChangedInLeft;       // only when fully set up do we turn on the text change handler - exception if you do it sooner

            g.panel.ResumeLayout();
        }