<commit_before>'use strict';

var Component = require('./Component');
var _ = require('../util/helpers');
var $$ = Component.$$;

/**
  Abstract Tool interface for editing and annotation tools.

  A tool must be associated with a Command, which holds all the logic, while the tool
  is just the visual representation of the command state.

  Like with {@link ui/Command} are two categories of tools, {@link ui/SurfaceTool}
  and {@link ui/ControllerTool}.
  
  @class
  @component
*/

function Tool() {
  Component.apply(this, arguments);
  this.context.toolManager.registerTool(this);
}

Tool.Prototype = function() {

  /* 
    Initialize toolstate. Obtained from the toolmanager by asking for 
    the associated command state.
  */
  this.getInitialState = function() {
    return this.context.toolManager.getCommandState(this);
  };

  this.dispose = function() {
    this.context.toolManager.unregisterTool(this);
  };

  /**
    Get controller context
  */
  this.getController = function() {
    return this.context.controller;
  };

  /**
    Get tool registration name
  */
  this.getName = function() {
    var toolName = this.constructor.static.name;
    if (toolName) {
      return toolName;
    } else {
      throw new Error('Contract: Tool.static.name must have a value');
    }
  };

  this.onClick = function(e) {
    e.preventDefault();
    if (this.state.disabled) {
      return;
    }
    this.performAction();
  };

  /**
    Default tool rendering. You can override this method to provide your custom markup
  */
  this.render = function() {
    var title = this.props.title || this.i18n.t(this.getName());
    // Used only by annotation tool so far
    if (this.state.mode) {
      title = [_.capitalize(this.state.mode), title].join(' ');
    }
    var el = $$('div')
      .attr('title', title)
      .addClass('se-tool');
    el.append(
      $$('button').on('click', this.onClick)
                  .append(this.props.children)
    );<commit_msg>stopPropagation for Tool.onClick handler.<commit_after>'use strict';

var Component = require('./Component');
var _ = require('../util/helpers');
var $$ = Component.$$;

/**
  Abstract Tool interface for editing and annotation tools.

  A tool must be associated with a Command, which holds all the logic, while the tool
  is just the visual representation of the command state.

  Like with {@link ui/Command} are two categories of tools, {@link ui/SurfaceTool}
  and {@link ui/ControllerTool}.
  
  @class
  @component
*/

function Tool() {
  Component.apply(this, arguments);
  this.context.toolManager.registerTool(this);
}

Tool.Prototype = function() {

  /* 
    Initialize toolstate. Obtained from the toolmanager by asking for 
    the associated command state.
  */
  this.getInitialState = function() {
    return this.context.toolManager.getCommandState(this);
  };

  this.dispose = function() {
    this.context.toolManager.unregisterTool(this);
  };

  /**
    Get controller context
  */
  this.getController = function() {
    return this.context.controller;
  };

  /**
    Get tool registration name
  */
  this.getName = function() {
    var toolName = this.constructor.static.name;
    if (toolName) {
      return toolName;
    } else {
      throw new Error('Contract: Tool.static.name must have a value');
    }
  };

  this.onClick = function(e) {
    e.preventDefault();
    e.stopPropagation();
    if (this.state.disabled) {
      return;
    }
    this.performAction();
  };

  /**
    Default tool rendering. You can override this method to provide your custom markup
  */
  this.render = function() {
    var title = this.props.title || this.i18n.t(this.getName());
    // Used only by annotation tool so far
    if (this.state.mode) {
      title = [_.capitalize(this.state.mode), title].join(' ');
    }
    var el = $$('div')
      .attr('title', title)
      .addClass('se-tool');
    el.append(
      $$('button').on('click', this.onClick)
                  .append(this.props.children)
    );
{'fraction_non_alphanumeric': 0.13433208489388265, 'fraction_numerical': 0.0009987515605493133, 'mean_word_length': 2.851923076923077, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '5721305', 'n_tokens_mistral': 1197, 'n_tokens_neox': 1176, 'n_words': 328}