Esempio n. 1
0
        public void AddBeforeTest()
        {
            Node <char> head = new Node <char>()
            {
                Data = 'H'
            };
            Node <char> node = new Node <char>()
            {
                Data = '!'
            };

            node.AddBefore(new Node <char>()
            {
                Data = 'e'
            });
            node.PreviousNode.AddBefore(head);
            node.AddBefore(new Node <char>()
            {
                Data = 'l'
            });
            node.AddBefore(new Node <char>()
            {
                Data = 'l'
            });
            node.AddBefore(new Node <char>()
            {
                Data = 'o'
            });
            var actual   = GetStringFromNode(head);
            var expected = "Hello!";

            Assert.AreEqual(expected, actual);
            new Node <char>().AddBefore(null);
        }
Esempio n. 2
0
 public void AddBeforeTest()
 {
     Node<char> head = new Node<char>() { Data = 'H' };
     Node<char> node = new Node<char>() { Data = '!' };
     node.AddBefore(new Node<char>() { Data = 'e' });
     node.PreviousNode.AddBefore(head);
     node.AddBefore(new Node<char>() { Data = 'l' });
     node.AddBefore(new Node<char>() { Data = 'l' });
     node.AddBefore(new Node<char>() { Data = 'o' });
     var actual = GetStringFromNode(head);
     var expected = "Hello!";
     Assert.AreEqual(expected, actual);
     new Node<char>().AddBefore(null);
 }
Esempio n. 3
0
        /*
         * adds a control to wysiwyg surface
         */
        private void AddControlToSurface(
            Node ip,
            Node controlToAddNode)
        {
            // defaulting to currently selected if exists, otherwise main surface
            string dna      = SelectedControlDna ?? DataSource["controls"].Dna;
            string position = "after";

            if (ip.Contains("where"))
            {
                if (ip["where"].ContainsValue("dna"))
                {
                    dna = ip["where"]["dna"].Get <string>();
                }
                if (ip["where"].ContainsValue("position"))
                {
                    position = ip["where"]["position"].Get <string>();
                }
            }

            if (dna == DataSource["controls"].Dna)
            {
                // main surface is destination, making sure position gets correct if user chose "before", and we can do such a thing
                if (position == "before" && DataSource["controls"].Count > 0)
                {
                    dna = DataSource["controls"][0].Dna;
                }
                else
                {
                    position = "child";
                }
            }

            if (!controlToAddNode.Contains("id") &&
                string.IsNullOrEmpty(controlToAddNode.Get <string>()))
            {
                GetNextAvailableControlId(controlToAddNode);
            }
            else if (controlToAddNode.Contains("id"))
            {
                if (controlToAddNode.Value != null)
                {
                    throw new ArgumentException("either supply [id] or value, not both");
                }

                // moving id into value for consistency
                controlToAddNode.Value = controlToAddNode["id"].Get <string>();
                controlToAddNode["id"].UnTie();
            }

            AddToUndoChain(!ip.ContainsValue("skip-undo") || !ip["skip-undo"].Get <bool>());

            Node destinationNode = DataSource.FindDna(dna);

            switch (position)
            {
            case "before":
                destinationNode.AddBefore(controlToAddNode);
                break;

            case "after":
                destinationNode.AddAfter(controlToAddNode);
                break;

            case "child":
            {
                if (destinationNode.Dna == DataSource["controls"].Dna)
                {
                    destinationNode.Add(controlToAddNode);
                }
                else
                {
                    // verifying control supports having children, otherwise defaulting to 'after'
                    Node inspectParent = new Node();
                    inspectParent["inspect"].Value = null;
                    RaiseActiveEvent(
                        "magix.forms.controls." + destinationNode.Name,
                        inspectParent);

                    if (inspectParent["magix.forms.create-web-part"]["controls"][0].Contains("controls"))
                    {
                        destinationNode["controls"].Add(controlToAddNode);
                    }
                    else
                    {
                        Node msg = new Node();
                        msg["message"].Value = "control didn't support children, added the control after your selection";
                        msg["color"].Value   = "#ffbbbb";
                        RaiseActiveEvent(
                            "magix.viewport.show-message",
                            msg);
                        destinationNode.AddAfter(controlToAddNode);         // defaulting to after
                    }
                }
            } break;

            default:
                throw new ArgumentException("only before, after or child are legal positions");
            }

            if (ip.Contains("auto-select") && ip["auto-select"].Get <bool>())
            {
                SelectedControlDna = controlToAddNode.Dna;
            }
            BuildForm();
            wrp.ReRender();
            RaiseSurfaceAndSelectionChangedChanged();
        }