private void btnAddCondition_Click(object sender, EventArgs e)
        {
            ConditionSingle re = new ConditionSingle();
            TreeNode        tn = new TreeNode();

            AttachConditionComponentToNode(tn, re);
            TreeNode           tx = trvNodes.SelectedNode;
            ConditionComponent rx = (ConditionComponent)tx.Tag;

            if (rx is ConditionSingle)
            {
                tx        = GetReverseLookup(rx.Parent);
                re.Parent = rx.Parent;
            }
            if (rx is ConditionGroup)
            {
                tx        = GetReverseLookup(rx);
                re.Parent = (ConditionGroup)rx;
            }
            re.Parent.Children.Add(re);
            tx.Nodes.Add(tn);
            RecolorStartingFromNode(tx, tx.Checked);
            TreeSort();
            trvNodes.SelectedNode = tn;
            if (tx.IsExpanded == false)
            {
                tx.Expand();
            }
            expLeft.Focus();
        }
예제 #2
0
 public bool ConditionMatches(Regex rex, ConditionGroup cg)
 {
     if (cg == null)
     {
         return(false);
     }
     foreach (ConditionComponent cc in cg.Children)
     {
         if (cc is ConditionSingle)
         {
             ConditionSingle cs = (ConditionSingle)cc;
             if (RegexMatches(rex, cs.ExpressionL) == true)
             {
                 return(true);
             }
             if (RegexMatches(rex, cs.ExpressionR) == true)
             {
                 return(true);
             }
         }
         if (cc is ConditionGroup)
         {
             if (ConditionMatches(rex, (ConditionGroup)cc) == true)
             {
                 return(true);
             }
         }
     }
     return(false);
 }
        private void cbxOpType_SelectedIndexChanged(object sender, EventArgs e)
        {
            TreeNode        tn = trvNodes.SelectedNode;
            ConditionSingle re = (ConditionSingle)tn.Tag;

            re.ConditionType = (ConditionSingle.CndTypeEnum)cbxOpType.SelectedIndex;
            TreeSort();
        }
        private void expRight_TextChanged(object sender, EventArgs e)
        {
            TreeNode        tn = trvNodes.SelectedNode;
            ConditionSingle re = (ConditionSingle)tn.Tag;

            re.ExpressionR = expRight.Expression;
            TreeSort();
        }
        private void cbxExpLType_SelectedIndexChanged(object sender, EventArgs e)
        {
            TreeNode        tn = trvNodes.SelectedNode;
            ConditionSingle re = (ConditionSingle)tn.Tag;

            switch (cbxExpLType.SelectedIndex)
            {
            case 0:
                expLeft.ExpressionType = ExpressionTextBox.SupportedExpressionTypeEnum.String;
                re.ExpressionTypeL     = ConditionSingle.ExprTypeEnum.String;
                break;

            case 1:
                expLeft.ExpressionType = ExpressionTextBox.SupportedExpressionTypeEnum.Numeric;
                re.ExpressionTypeL     = ConditionSingle.ExprTypeEnum.Numeric;
                break;
            }
            TreeSort();
        }
        internal void PasteSelected(bool overWrite)
        {
            string data = null;

            try
            {
                if (plug.cfg.UseOsClipboard == true)
                {
                    data = System.Windows.Forms.Clipboard.GetText(TextDataFormat.Text);
                }
                else
                {
                    data = plug.ui.Clipboard;
                }
                if (data != null && data.Length > 0)
                {
                    XmlDocument doc = new XmlDocument();
                    doc.LoadXml(data);
                    XmlSerializer xs = null;
                    if (doc.DocumentElement.Name == "ConditionGroup")
                    {
                        xs = new XmlSerializer(typeof(ConditionGroup));
                    }
                    else if (doc.DocumentElement.Name == "ConditionSingle")
                    {
                        xs = new XmlSerializer(typeof(ConditionSingle));
                    }
                    else
                    {
                        // doesn't look like valid paste
                        return;
                    }
                    ConditionComponent cx;
                    using (XmlNodeReader nr = new XmlNodeReader(doc.DocumentElement))
                    {
                        cx = (ConditionComponent)xs.Deserialize(nr);
                    }
                    TreeNode           tn     = trvNodes.SelectedNode;
                    ConditionComponent target = (ConditionComponent)tn.Tag;
                    if (
                        (
                            (cx is ConditionGroup && target is ConditionGroup)
                            ||
                            (cx is ConditionSingle && target is ConditionSingle)
                        )
                        &&
                        overWrite == true
                        )
                    {
                        if (cx is ConditionGroup && target is ConditionGroup)
                        {
                            ConditionGroup sc = (ConditionGroup)cx;
                            ConditionGroup tc = (ConditionGroup)target;
                            tc.Children.AddRange(sc.Children);
                            foreach (ConditionComponent cc in sc.Children)
                            {
                                cc.Parent = tc;
                                BuildTreeFromConditionItem(tn, cc);
                            }
                            tc.Enabled  = sc.Enabled;
                            tn.Checked  = tc.Enabled;
                            tc.Grouping = sc.Grouping;
                            RecolorStartingFromNode(tn, tn.Checked);
                            TreeSort();
                            UpdateEditorToConditionComponent(target);
                            tn.Expand();
                        }
                        else if (cx is ConditionSingle && target is ConditionSingle)
                        {
                            ConditionSingle sc = (ConditionSingle)cx;
                            ConditionSingle tc = (ConditionSingle)target;
                            tc.ConditionType   = sc.ConditionType;
                            tc.Enabled         = sc.Enabled;
                            tn.Checked         = tc.Enabled;
                            tc.ExpressionL     = sc.ExpressionL;
                            tc.ExpressionR     = sc.ExpressionR;
                            tc.ExpressionTypeL = sc.ExpressionTypeL;
                            tc.ExpressionTypeR = sc.ExpressionTypeR;
                            RecolorStartingFromNode(tn, tn.Checked);
                            TreeSort();
                            UpdateEditorToConditionComponent(target);
                        }
                    }
                    else
                    {
                        if (target is ConditionSingle)
                        {
                            target = target.Parent;
                            tn     = tn.Parent;
                        }
                        ConditionGroup tg = (ConditionGroup)target;
                        tg.Children.Add(cx);
                        cx.Parent = tg;
                        TreeNode ex = BuildTreeFromConditionItem(tn, cx);
                        RecolorStartingFromNode(tn, tn.Checked);
                        TreeSort();
                        trvNodes.SelectedNode = ex;
                        ex.ExpandAll();
                    }
                }
            }
            catch (Exception ex)
            {
                plug.FilteredAddToLog(Plugin.DebugLevelEnum.Error, I18n.Translate("internal/ConditionViewer/pastefail", "Tree paste failed due to exception: {0}", ex.Message));
            }
        }
        private void UpdateEditorToConditionComponent(ConditionComponent re)
        {
            if (re is ConditionSingle)
            {
                pnlEditorGroup.Visible  = false;
                PanelStateFromSelection = true;
                ConditionSingle r = (ConditionSingle)re;
                expLeft.Expression  = r.ExpressionL;
                expRight.Expression = r.ExpressionR;
                switch (r.ExpressionTypeL)
                {
                case ConditionSingle.ExprTypeEnum.String:
                    cbxExpLType.SelectedIndex = 0;
                    break;

                case ConditionSingle.ExprTypeEnum.Numeric:
                    cbxExpLType.SelectedIndex = 1;
                    break;
                }
                switch (r.ExpressionTypeR)
                {
                case ConditionSingle.ExprTypeEnum.String:
                    cbxExpRType.SelectedIndex = 0;
                    break;

                case ConditionSingle.ExprTypeEnum.Numeric:
                    cbxExpRType.SelectedIndex = 1;
                    break;
                }
                cbxOpType.SelectedIndex = (int)r.ConditionType;
                capProperties.Caption   = I18n.Translate("internal/ConditionViewer/condprops", "Condition properties");
                pnlEditorSingle.Visible = true;
            }
            else if (re is ConditionGroup)
            {
                pnlEditorSingle.Visible = false;
                PanelStateFromSelection = true;
                ConditionGroup r = (ConditionGroup)re;
                switch (r.Grouping)
                {
                case ConditionGroup.CndGroupingEnum.And:
                    cbxGroupingType.SelectedIndex = 0;
                    break;

                case ConditionGroup.CndGroupingEnum.Or:
                    cbxGroupingType.SelectedIndex = 1;
                    break;

                case ConditionGroup.CndGroupingEnum.Xor:
                    cbxGroupingType.SelectedIndex = 2;
                    break;

                case ConditionGroup.CndGroupingEnum.Not:
                    cbxGroupingType.SelectedIndex = 3;
                    break;
                }
                capProperties.Caption  = I18n.Translate("internal/ConditionViewer/groupprops", "Group properties");
                pnlEditorGroup.Visible = true;
            }
            else
            {
                pnlEditorSingle.Visible = false;
                pnlEditorGroup.Visible  = false;
                PanelStateFromSelection = false;
            }
            btnAddGroup.Enabled     = true;
            btnAddCondition.Enabled = true;
            btnDelete.Enabled       = (re.Parent != null);
        }