Beispiel #1
0
        BlockStack MergeStacks(IBlock b1, IBlock b2)
        {
            BlockStack ret = new BlockStack();

            if ((b1 is BlockStack))
            {
                BlockStack bs1 = b1 as BlockStack;
                ret.AddRange(bs1);
            }
            else
            {
                // We need to remove b1 from its parent before adding it to the newly merged stack
                // otherwise consider such a scenario:
                // 1- We drag a stack block into an existing stackBlock in a C block
                // 2- 'b1' is the existing stackBlock, it is not added to ret, but is still an arg of the C block
                // 3- after merge is called, we'll try to set ret as the arg of the C block; the C will try
                // to remove the old arg (b1)...but it doesn't have C as a parent! exception thrown
                b1.ParentRelationship.Detach(this);
                ret.Add(b1);
            }
            if ((b2 is BlockStack))
            {
                BlockStack bs2 = b2 as BlockStack;
                ret.AddRange(bs2);
            }
            else
            {
                b2.ParentRelationship.Detach(this);
                ret.Add(b2);
            }
            return(ret);
        }
Beispiel #2
0
        BlockStack makeSampleBlockStack()
        {
            InvokationBlock b1 = makeInvokationBlock("move % steps",
                                                     new DataType[] { DataType.Number },
                                                     DataType.Script,
                                                     new IBlock[] { new TextBlock("") });

            InvokationBlock b2 = makeInvokationBlock("turn % degrees right",
                                                     new DataType[] { DataType.Number },
                                                     DataType.Script,
                                                     new IBlock[] { new TextBlock("") });

            BlockStack stack = new BlockStack();

            stack.AddRange(new IBlock[] { b1, b2 });
            return(stack);
        }