Esempio n. 1
0
        /// <summary>
        /// Parse the provided toolbox tree into a consistent DOM format.
        /// </summary>
        /// <param name="tree_">DOM tree of blocks, or text representation of same.</param>
        /// <returns>tree of blocks, or null.</returns>
        public static Element parseToolboxTree(Union <string, Element> tree_)
        {
            Element tree = tree_.As <Element>();

            if (tree_ != null)
            {
                if (!tree_.Is <string>())
                {
                    if (false /*typeof XSLTProcessor == 'undefined' && tree.outerHTML*/)
                    {
                        // In this case the tree will not have been properly built by the
                        // browser. The HTML will be contained in the element, but it will
                        // not have the proper DOM structure since the browser doesn't support
                        // XSLTProcessor (XML -> HTML). This is the case in IE 9+.
                        tree_ = tree_.As <Element>().OuterHTML;
                    }
                    else if (!(tree_.Is <Element>()))
                    {
                        tree = null;
                    }
                }
                if (tree_.Is <string>())
                {
                    tree = Xml.textToDom(tree_.As <string>());
                }
            }
            else
            {
                tree = null;
            }
            return(tree);
        }
Esempio n. 2
0
            /// <summary>
            /// Run a change event.
            /// </summary>
            /// <param name="forward">True if run forward, false if run backward (undo).</param>
            public override void run(bool forward)
            {
                var workspace = Workspace.getById(this.workspaceId);
                var block     = (BlockSvg)workspace.getBlockById(this.blockId);

                if (block == null)
                {
                    Console.WriteLine("Can't change non-existant block: " + this.blockId);
                    return;
                }
                if (block.mutator != null)
                {
                    // Close the mutator (if open) since we don't want to update it.
                    block.mutator.setVisible(false);
                }
                var value = forward ? this.newValue : this.oldValue;

                switch (this.element)
                {
                case "field":
                    var field = block.getField(this.name);
                    if (field != null)
                    {
                        // Run the validator for any side-effects it may have.
                        // The validator's opinion on validity is ignored.
                        field.callValidator(value);
                        field.setValue(value);
                    }
                    else
                    {
                        Console.WriteLine("Can't set non-existant field: " + this.name);
                    }
                    break;

                case "comment":
                    block.setCommentText(value);
                    break;

                case "collapsed":
                    block.setCollapsed(value == "true");
                    break;

                case "disabled":
                    block.setDisabled(value == "true");
                    break;

                case "inline":
                    block.setInputsInline(value == "true");
                    break;

                case "mutation":
                    var oldMutation = "";
                    if (true /*block.mutationToDom*/)
                    {
                        var oldMutationDom = block.mutationToDom();
                        oldMutation = oldMutationDom != null?oldMutationDom.ToString() : Xml.domToText(oldMutationDom);
                    }
                    if (true /*block.domToMutation*/)
                    {
                        value = value != null ? value : "<mutation></mutation>";
                        var dom = Xml.textToDom("<xml>" + value + "</xml>");
                        block.domToMutation((Element)dom.FirstChild);
                    }
                    Events.fire(new Events.Change(
                                    block, "mutation", null, oldMutation, value));
                    break;

                default:
                    Console.WriteLine("Unknown change type: " + this.element);
                    break;
                }
            }
Esempio n. 3
0
 /// <summary>
 /// Decode the JSON event.
 /// </summary>
 /// <param name="json">JSON representation.</param>
 public override void fromJson(EventJsonData json)
 {
     base.fromJson(json);
     this.xml = (Element)Xml.textToDom("<xml>" + json.xml + "</xml>").FirstChild;
     this.ids = json.ids;
 }