2016-12-07 5 views
0

ブロックをワークスペースに追加するコンテキストメニューハンドラを実装しました。コンテキストメニューを呼び出したブロックとすでに接続されているブロック(previousConnection)の間にブロックを追加しようとしています。私は何のために撮影していると私が持っているコードとそれが...コード内のブロックへのブロック接続のブロックの作成

context menu option handler: 
    var option = 
    { 
     text: "Comment", 
     enabled: true, 
     callback: function() 
     { 
     var comment = workspace.newBlock('ta_comment'); 
     var block = Blockly.ContextMenu.currentBlock; 

     block.previousConnection.connect(comment.nextConnection); 

     comment.initSvg(); 
     comment.render(); 
     } 
    } 

    menuOptions.push(option); 

before after

+0

は 'ブロックのターゲット接続を保存するために、コメントを接続する前に、覚えているん.previousConnection'。 nullでない場合は、 'comment.previousConnection'をそれに接続する必要があります。 – Anm

+0

は意味がありますが、どのように見えますか?私は混在した結果でいくつかのことを試しました。たとえば、次のコードは同じブロックで3回目まで実行され、ブロックブロックとコミントブロックが切断されます。var comment = workspace.newBlock( 'ta_comment'); var block = Blockly.ContextMenu.currentBlock; var targetConnection = block.previousConnection.targetConnection; block.previousConnection.connect(comment.nextConnection); comment.previousConnection.connect(targetConnection); – objectthink

答えて

0
 //create comment block and get the block that summoned the context menu 
    var comment = workspace.newBlock('ta_comment'); 
    var block = Blockly.ContextMenu.currentBlock; 

    //connect up comment block 
    comment.previousConnection.connect(block.previousConnection.targetConnection); 
    comment.nextConnection.connect(block.previousConnection); 

    //init 
    comment.initSvg(); 

    //render updated workspace 
    workspace.render(); 
+0

上記のコードはトリックを行います... – objectthink

関連する問題