<commit_before>/**
 * @license
 * Visual Blocks Editor
 *
 * Copyright 2012 Google Inc.
 * https://blockly.googlecode.com/
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * @fileoverview Object representing a UI block menu.
 * @author <EMAIL>
 */
'use strict';

goog.provide('Blockly.BlockMenu');

goog.require('Blockly.Workspace');


/**
 * Class for UI Block Menu
 * @param {!Element} element HTML div for block menu.
 * @constructor
 */
Blockly.BlockMenu = function(element) {

  /**
   * List of background buttons that lurk behind each block to catch clicks
   * landing in the blocks' lakes and bays.
   * @type {!Array.<!Element>}
   * @private
   */
  this.buttons_ = [];

  /**
   * List of event listeners.
   * @type {!Array.<!Array>}
   * @private
   */
  this.listeners_ = [];

  this.view_ = element;
  this.menuView_ = Blockly.createSvgElement('svg', {
    'xmlns': 'http://www.w3.org/2000/svg',
    'xmlns:html': 'http://www.w3.org/1999/xhtml',
    'xmlns:xlink': 'http://www.w3.org/1999/xlink',
    'version': '1.1',
    'class': 'blocklySvg'
  }, this.view_);
  var blockMenu = this;
  this.workspace_ = new Blockly.Workspace(
      function() {return blockMenu.getMetrics_();},
      function(ratio) {return blockMenu.setMetrics_(ratio);});
  this.menuView_.appendChild(this.workspace_.createDom());
  this.scrollbar_ = new Blockly.Scrollbar(this.workspace_, false, false);
  this.onResizeWrapper_ = Blockly.bindEvent_(window,
      goog.events.EventType.RESIZE, this, this.syncViewSize_);
};

/**
 * Show and populate the blockmenu.
 * @param {!Array|string} xmlList List of blocks to show.
 *     Variables and procedures have a custom set of blocks.
 */
Blockly.BlockMenu.prototype.show = function(xmlList) {
  this.hide();
  var margin = 0;
  this.menuView_.style.display = 'block';

  // Create the blocks to be shown in this blockMenu.
  var blocks = [];
  var gaps = [];
  if (xmlList == Blockly.Variables.NAME_TYPE) {
    // Special category for variables.
    Blockly.Variables.blockMenuCategory(blocks, gaps, margin,
        /** @type {!Blockly.Workspace} */ (this.workspace_));
  } else if (xmlList == Blockly.Procedures.NAME_TYPE) {
    // Special category for procedures.
    Blockly.Procedures.blockMenuCategory(blocks, gaps, margin,
        /** @type {!Blockly.Workspace} */ (this.workspace_));
  } else {
    for (var i = 0, xml; xml = xmlList[i]; i++) {
      if (xml.tagName && xml.tagName.toUpperCase() == 'BLOCK') {
        var block = Blockly.Xml.domToBlock(
            /** @type {!Blockly.Workspace} */ (this.workspace_), xml);
        block.isInFlyout = true;
        blocks.push(block);
        gaps.push(margin);
      }
    }
  }

  // Lay out the blocks vertically.
  var cursorY = 10;
  for (var i = 0, block; block = blocks[i]; i++) {
    var allBlocks = block.getDescendants();
    for (var j = 0, child; child = allBlocks[j]; j++) {
      // Mark blocks as being inside a blockMenu.  This is used to detect and
      // prevent the closure of the blockMenu if the user right-clicks on such a
      // block.
      child.isInFlyout = true;
      // There is no good way to handle comment bubbles inside the blockMenu.
      // Blocks shouldn't come with predefined comments, but someone will
      // try this, I'm sure.  Kill the comment.
      Blockly.Comment && child.setCommentText(null);
    }
    block.render();
    var root = block.getSvgRoot();
    var blockHW = block.getHeightWidth();
    var x = 10;
    if (block.outputConnection) {
      x += blockHW.height/2;
        console.log(block);
    } else if (!block.previousConnection && block.nextConnection){
      cursorY += 10;
    } else if (!block.previousConnection && !block.nextConnection){
      cursorY += 10;
    } else {
      cursorY += 7;
    }
    block.moveBy(x, cursorY);
    if (!block.previousConnection && !block.nextConnection){
      cursorY += 10;
    }

    if (block.type == 'ask_and_wait' || block.type == 'hide_variable') {
        cursorY += 12;
    }
    cursorY += blockHW.height + gaps[i];

    // Create an invisible rectangle under the block to act as a button.  Just
    // using the block as a button is poor, since blocks have holes in them.
    var rect = Blockly.createSvgElement('rect', {'fill-opacity': 0}, null);
    // Add the rectangles under the blocks, so that the blocks' tooltips work.
    this.workspace_.getCanvas().insertBefore(rect, block.getSvgRoot());
    block.blockMenuRect_ = rect;
    this.buttons_[i] = rect;

    if (block.isAddable()) {
      this.listeners_.push(Blockly.bindEvent_(root, 'mousedown', null,
          this.blockMouseDown_(block)));
    }
    if (typeof(Entry) == "object" && block.type == "make_variable") {<commit_msg>delete console log<commit_after>/**
 * @license
 * Visual Blocks Editor
 *
 * Copyright 2012 Google Inc.
 * https://blockly.googlecode.com/
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * @fileoverview Object representing a UI block menu.
 * @author <EMAIL>
 */
'use strict';

goog.provide('Blockly.BlockMenu');

goog.require('Blockly.Workspace');


/**
 * Class for UI Block Menu
 * @param {!Element} element HTML div for block menu.
 * @constructor
 */
Blockly.BlockMenu = function(element) {

  /**
   * List of background buttons that lurk behind each block to catch clicks
   * landing in the blocks' lakes and bays.
   * @type {!Array.<!Element>}
   * @private
   */
  this.buttons_ = [];

  /**
   * List of event listeners.
   * @type {!Array.<!Array>}
   * @private
   */
  this.listeners_ = [];

  this.view_ = element;
  this.menuView_ = Blockly.createSvgElement('svg', {
    'xmlns': 'http://www.w3.org/2000/svg',
    'xmlns:html': 'http://www.w3.org/1999/xhtml',
    'xmlns:xlink': 'http://www.w3.org/1999/xlink',
    'version': '1.1',
    'class': 'blocklySvg'
  }, this.view_);
  var blockMenu = this;
  this.workspace_ = new Blockly.Workspace(
      function() {return blockMenu.getMetrics_();},
      function(ratio) {return blockMenu.setMetrics_(ratio);});
  this.menuView_.appendChild(this.workspace_.createDom());
  this.scrollbar_ = new Blockly.Scrollbar(this.workspace_, false, false);
  this.onResizeWrapper_ = Blockly.bindEvent_(window,
      goog.events.EventType.RESIZE, this, this.syncViewSize_);
};

/**
 * Show and populate the blockmenu.
 * @param {!Array|string} xmlList List of blocks to show.
 *     Variables and procedures have a custom set of blocks.
 */
Blockly.BlockMenu.prototype.show = function(xmlList) {
  this.hide();
  var margin = 0;
  this.menuView_.style.display = 'block';

  // Create the blocks to be shown in this blockMenu.
  var blocks = [];
  var gaps = [];
  if (xmlList == Blockly.Variables.NAME_TYPE) {
    // Special category for variables.
    Blockly.Variables.blockMenuCategory(blocks, gaps, margin,
        /** @type {!Blockly.Workspace} */ (this.workspace_));
  } else if (xmlList == Blockly.Procedures.NAME_TYPE) {
    // Special category for procedures.
    Blockly.Procedures.blockMenuCategory(blocks, gaps, margin,
        /** @type {!Blockly.Workspace} */ (this.workspace_));
  } else {
    for (var i = 0, xml; xml = xmlList[i]; i++) {
      if (xml.tagName && xml.tagName.toUpperCase() == 'BLOCK') {
        var block = Blockly.Xml.domToBlock(
            /** @type {!Blockly.Workspace} */ (this.workspace_), xml);
        block.isInFlyout = true;
        blocks.push(block);
        gaps.push(margin);
      }
    }
  }

  // Lay out the blocks vertically.
  var cursorY = 10;
  for (var i = 0, block; block = blocks[i]; i++) {
    var allBlocks = block.getDescendants();
    for (var j = 0, child; child = allBlocks[j]; j++) {
      // Mark blocks as being inside a blockMenu.  This is used to detect and
      // prevent the closure of the blockMenu if the user right-clicks on such a
      // block.
      child.isInFlyout = true;
      // There is no good way to handle comment bubbles inside the blockMenu.
      // Blocks shouldn't come with predefined comments, but someone will
      // try this, I'm sure.  Kill the comment.
      Blockly.Comment && child.setCommentText(null);
    }
    block.render();
    var root = block.getSvgRoot();
    var blockHW = block.getHeightWidth();
    var x = 10;
    if (block.outputConnection) {
      x += blockHW.height/2;
    } else if (!block.previousConnection && block.nextConnection){
      cursorY += 10;
    } else if (!block.previousConnection && !block.nextConnection){
      cursorY += 10;
    } else {
      cursorY += 7;
    }
    block.moveBy(x, cursorY);
    if (!block.previousConnection && !block.nextConnection){
      cursorY += 10;
    }

    if (block.type == 'ask_and_wait' || block.type == 'hide_variable') {
        cursorY += 12;
    }
    cursorY += blockHW.height + gaps[i];

    // Create an invisible rectangle under the block to act as a button.  Just
    // using the block as a button is poor, since blocks have holes in them.
    var rect = Blockly.createSvgElement('rect', {'fill-opacity': 0}, null);
    // Add the rectangles under the blocks, so that the blocks' tooltips work.
    this.workspace_.getCanvas().insertBefore(rect, block.getSvgRoot());
    block.blockMenuRect_ = rect;
    this.buttons_[i] = rect;

    if (block.isAddable()) {
      this.listeners_.push(Blockly.bindEvent_(root, 'mousedown', null,
          this.blockMouseDown_(block)));
    }
    if (typeof(Entry) == "object" && block.type == "make_variable") {
{'fraction_non_alphanumeric': 0.13563549160671462, 'fraction_numerical': 0.00844124700239808, 'mean_word_length': 3.011542901115814, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 2, 'lorem ipsum': 0, 'www.': 8, 'xml': 26}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7176082', 'n_tokens_mistral': 3279, 'n_tokens_neox': 3198, 'n_words': 951}