Ejemplo n.º 1
0
        /**
         * Add custom menu options to this block's context menu.
         * @param {!Array} options List of menu options to add to.
         * @this Blockly.Block
         */
        public override void customContextMenu(JsArray <ContextMenuOption> options)
        {
            // Add option to create caller.
            var option = new ContextMenuOption()
            {
                enabled = true
            };
            var name = this.getFieldValue("NAME");

            option.text = Msg.PROCEDURES_CREATE_DO.Replace("%1", name);
            var xmlMutation = goog.dom.createDom("mutation");

            xmlMutation.SetAttribute("name", name);
            for (var i = 0; i < this.arguments_.Length; i++)
            {
                var xmlArg = goog.dom.createDom("arg");
                xmlArg.SetAttribute("name", this.arguments_[i]);
                xmlMutation.AppendChild(xmlArg);
            }
            var xmlBlock = goog.dom.createDom("block", null, xmlMutation);

            xmlBlock.SetAttribute("type", this.callType_);
            option.callback = ContextMenu.callbackFactory(this, xmlBlock);
            options.Push(option);

            // Add options to create getters for each parameter.
            if (!this.isCollapsed())
            {
                for (var i = 0; i < this.arguments_.Length; i++)
                {
                    option = new ContextMenuOption()
                    {
                        enabled = true
                    };
                    name        = this.arguments_[i];
                    option.text = Msg.VARIABLES_SET_CREATE_GET.Replace("%1", name);
                    var xmlField = goog.dom.createDom("field", null, name);
                    xmlField.SetAttribute("name", "VAR");
                    xmlBlock = goog.dom.createDom("block", null, xmlField);
                    xmlBlock.SetAttribute("type", VariablesGetBlock.type_name);
                    option.callback = ContextMenu.callbackFactory(this, xmlBlock);
                    options.Push(option);
                }
            }
        }
Ejemplo n.º 2
0
 /**
  * Add menu option to create getter block for loop variable.
  * @param {!Array} options List of menu options to add to.
  * @this Blockly.Block
  */
 public override void customContextMenu(JsArray <ContextMenuOption> options)
 {
     if (!this.isCollapsed())
     {
         var option = new ContextMenuOption()
         {
             enabled = true
         };
         var name = this.getFieldValue("VAR");
         option.text = Msg.VARIABLES_SET_CREATE_GET.Replace("%1", name);
         var xmlField = goog.dom.createDom("field", null, name);
         xmlField.SetAttribute("name", "VAR");
         var xmlBlock = goog.dom.createDom("block", null, xmlField);
         xmlBlock.SetAttribute("type", VariablesGetBlock.type_name);
         option.callback = ContextMenu.callbackFactory(this, xmlBlock);
         options.Push(option);
     }
 }
Ejemplo n.º 3
0
        /**
         * Add menu option to create getter/setter block for this setter/getter.
         * @param {!Array} options List of menu options to add to.
         * @this Blockly.Block
         */
        public override void customContextMenu(JsArray <ContextMenuOption> options)
        {
            var option = new ContextMenuOption()
            {
                enabled = true
            };
            var name = this.getFieldValue("VAR");

            option.text = this.contextMenuMsg_.Replace("%1", name);
            var xmlField = goog.dom.createDom("field", null, name);

            xmlField.SetAttribute("name", "VAR");
            var xmlBlock = goog.dom.createDom("block", null, xmlField);

            xmlBlock.SetAttribute("type", this.contextMenuType_);
            option.callback = ContextMenu.callbackFactory(this, xmlBlock);
            options.Push(option);
        }
Ejemplo n.º 4
0
        /**
         * Add menu option to find the definition block for this call.
         * @param {!Array} options List of menu options to add to.
         * @this Blockly.Block
         */
        public override void customContextMenu(JsArray <ContextMenuOption> options)
        {
            var option = new ContextMenuOption()
            {
                enabled = true
            };

            option.text = Msg.PROCEDURES_HIGHLIGHT_DEF;
            var name      = this.getProcedureCall();
            var workspace = this.workspace;

            option.callback = (e) => {
                var def = (BlockSvg)Core.Procedures.getDefinition(name, workspace);
                if (def != null)
                {
                    def.select();
                }
            };
            options.Push(option);
        }