source: EcnlProtoTool/trunk/webapp/webmrbc/Blocks/Variables.cs@ 270

Last change on this file since 270 was 270, checked in by coas-nagasima, 7 years ago

mruby版ECNLプロトタイピング・ツールを追加

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-csharp
File size: 3.7 KB
Line 
1/**
2 * @license
3 * Visual Blocks Editor
4 *
5 * Copyright 2012 Google Inc.
6 * https://developers.google.com/blockly/
7 *
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 */
20
21/**
22 * @fileoverview Variable blocks for Blockly.
23 * @author fraser@google.com (Neil Fraser)
24 */
25using System;
26using System.Linq;
27using System.Text;
28using Bridge;
29using Bridge.Html5;
30using Bridge.jQuery2;
31
32namespace WebMrbc
33{
34 public class VariablesGetBlock : Block
35 {
36 public const string type_name = "variables_get";
37 string contextMenuType_ = VariablesSetBlock.type_name;
38
39 public VariablesGetBlock()
40 : base(type_name)
41 {
42 }
43
44 /**
45 * Block for variable getter.
46 * @this Blockly.Block
47 */
48 public void init()
49 {
50 this.setHelpUrl(Msg.VARIABLES_GET_HELPURL);
51 this.setColour(Blockly.Variables.HUE);
52 this.appendDummyInput()
53 .appendField(new FieldVariable(
54 Msg.VARIABLES_DEFAULT_NAME), "VAR");
55 this.setOutput(true);
56 this.setTooltip(Msg.VARIABLES_GET_TOOLTIP);
57 this.contextMenuMsg_ = Msg.VARIABLES_GET_CREATE_SET;
58 }
59
60 /**
61 * Add menu option to create getter/setter block for this setter/getter.
62 * @param {!Array} options List of menu options to add to.
63 * @this Blockly.Block
64 */
65 public void customContextMenu(object[] options)
66 {
67 var option = new ContextMenuOption() { enabled = true };
68 var name = this.getFieldValue("VAR");
69 option.text = this.contextMenuMsg_.Replace("%1", name);
70 var xmlField = goog.dom.createDom("field", null, name);
71 xmlField.SetAttribute("name", "VAR");
72 var xmlBlock = goog.dom.createDom("block", null, xmlField);
73 xmlBlock.SetAttribute("type", this.contextMenuType_);
74 option.callback = ContextMenu.callbackFactory(this, xmlBlock);
75 options.Push(option);
76 }
77 }
78
79 public class VariablesSetBlock : Block
80 {
81 public const string type_name = "variables_set";
82 string contextMenuType_ = VariablesGetBlock.type_name;
83
84 public VariablesSetBlock()
85 : base(type_name)
86 {
87 }
88
89 /**
90 * Block for variable setter.
91 * @this Blockly.Block
92 */
93 public void init()
94 {
95 this.jsonInit(new {
96 message0 = Msg.VARIABLES_SET,
97 args0 = new object[] {
98 new {
99 type = "field_variable",
100 name = "VAR",
101 variable = Msg.VARIABLES_DEFAULT_NAME
102 },
103 new {
104 type = "input_value",
105 name = "VALUE"
106 }
107 },
108 previousStatement = (Union<string, string[]>)null,
109 nextStatement = (Union<string, string[]>)null,
110 colour = Blockly.Variables.HUE,
111 tooltip = Msg.VARIABLES_SET_TOOLTIP,
112 helpUrl = Msg.VARIABLES_SET_HELPURL
113
114 });
115 this.contextMenuMsg_ = Msg.VARIABLES_SET_CREATE_GET;
116 }
117
118 /**
119 * Add menu option to create getter/setter block for this setter/getter.
120 * @param {!Array} options List of menu options to add to.
121 * @this Blockly.Block
122 */
123 public void customContextMenu(object[] options)
124 {
125 var option = new ContextMenuOption() { enabled = true };
126 var name = this.getFieldValue("VAR");
127 option.text = this.contextMenuMsg_.Replace("%1", name);
128 var xmlField = goog.dom.createDom("field", null, name);
129 xmlField.SetAttribute("name", "VAR");
130 var xmlBlock = goog.dom.createDom("block", null, xmlField);
131 xmlBlock.SetAttribute("type", this.contextMenuType_);
132 option.callback = ContextMenu.callbackFactory(this, xmlBlock);
133 options.Push(option);
134 }
135 }
136}
Note: See TracBrowser for help on using the repository browser.