public override Object Clone()
        {
            InTemplateRule res = (InTemplateRule)MemberwiseClone();

            res.ruleControl_ = null;
            return(res);
        }
        private static string ReplaceOn(string template, TreeNode tn, string text, string title)
        {
            InTemplateRule r = (InTemplateRule)tn.Tag;

            foreach (TreeNode t in tn.Nodes)
            {
                IRule sr = (IRule)t.Tag;
                text = sr.Apply(t, text, title);
            }

            if (r.DoReplace_ && !string.IsNullOrEmpty(r.ReplaceWith_))
            {
                if (string.IsNullOrEmpty(template))
                {
                    return(text);
                }

                string pattern =
                    @"^([\s]*)" + Tools.CaseInsensitive(template) + @"([\s]*(?:<!--.*-->)?[\s]*(\}\}|\|))";

                pattern = pattern.Replace(" ", "[ _]+");

                text = Regex.Replace(text, pattern, "$1" + r.ReplaceWith_ + "$2");
            }

            return(text);
        }
        public void SaveToRule(InTemplateRule r)
        {
            if (r == null)
                return;

            r.enabled_ = RuleEnabledCheckBox.Checked;
            r.Name = NameTextbox.Text.Trim();
            r.ReplaceWith_ = ReplaceWithTextBox.Text.Trim();
            r.DoReplace_ = ReplaceCheckBox.Checked;

            r.TemplateNames_.Clear();
            foreach (string s in AliasesListBox.Items)
            {
                r.TemplateNames_.Add(s);
            }
        }
        public void RestoreFromRule(InTemplateRule r)
        {
            NameTextbox.Text = r.Name;
            RuleEnabledCheckBox.Checked = r.enabled_;
            ReplaceWithTextBox.Text = r.ReplaceWith_;
            ReplaceCheckBox.Checked = r.DoReplace_;

            AliasesListBox.BeginUpdate();
            AliasesListBox.Items.Clear();
            foreach (string s in r.TemplateNames_)
            {
                AliasesListBox.Items.Add(s);
            }
            AliasesListBox.EndUpdate();

            UpdateEndabledStates();
        }
        public void RestoreFromRule(InTemplateRule r)
        {
            NameTextbox.Text            = r.Name;
            RuleEnabledCheckBox.Checked = r.enabled_;
            ReplaceWithTextBox.Text     = r.ReplaceWith_;
            ReplaceCheckBox.Checked     = r.DoReplace_;

            AliasesListBox.BeginUpdate();
            AliasesListBox.Items.Clear();
            foreach (string s in r.TemplateNames_)
            {
                AliasesListBox.Items.Add(s);
            }
            AliasesListBox.EndUpdate();

            UpdateEndabledStates();
        }
        public void SaveToRule(InTemplateRule r)
        {
            if (r == null)
            {
                return;
            }

            r.enabled_     = RuleEnabledCheckBox.Checked;
            r.Name         = NameTextbox.Text.Trim();
            r.ReplaceWith_ = ReplaceWithTextBox.Text.Trim();
            r.DoReplace_   = ReplaceCheckBox.Checked;

            r.TemplateNames_.Clear();
            foreach (string s in AliasesListBox.Items)
            {
                r.TemplateNames_.Add(s);
            }
        }