<commit_before>
define [
  "underscore"
  "backbone"
  "./build_views"
  "./continuum_view"
  "./collection"
  "./has_properties"
  "./logging"
  "./tool_manager"
  "./plot_template"
  "renderer/properties"
], (_, Backbone, build_views, ContinuumView, Collection, HasProperties, Logging, ToolManager, plot_template, Properties) ->

  logger = Logging.logger

  class _ToolProxy extends Backbone.Model
    attrs_and_props: () ->
      return @attributes.tools[0].attrs_and_props()

    get: (attr) ->
      return @attributes.tools[0].get(attr)

    set: (attr, value) ->
      super(attr, value)
      for tool in @attributes.tools
        tool.set(attr, value)

  class GridToolManager extends ToolManager.Model

    _init_tools: () ->
      # Note: no call to super(), intentionally

      inspectors = {}
      actions = {}
      gestures = {}

      for tm in @get('tool_managers')

        for et, info of tm.get('gestures')
          if et not of gestures
            gestures[et] = {}
          for tool in info.tools
            if tool.type not of gestures[et]
              gestures[et][tool.type] = []
            gestures[et][tool.type].push(tool)

        for tool in tm.get('inspectors')
          if tool.type not of inspectors
            inspectors[tool.type] = []
          inspectors[tool.type].push(tool)

        for tool in @get('actions')
          if tool.type not of actions
            actions[tool.type] = []
          actions[tool.type].push(tool)

      for et of gestures
        for typ, tools of gestures[et]
          if tools.length != @get('num_plots')
            continue
          proxy = new _ToolProxy({tools: tools})
          @get('gestures')[et].tools.push(proxy)
          @listenTo(proxy, 'change:active', _.bind(@_active_change, proxy))

        tools = @get('gestures')[et].tools
        if tools.length > 0
          @get('gestures')[et].tools = _.sortBy(tools, (tool) -> tool.get('default_order'))
          gestures[et].tools[0].set('active', true)

      for typ, tools of actions
        if tools.length != @get('num_plots')
          continue
        proxy = new _ToolProxy({tools: tools})
        @get('actions').tools.push(proxy)

      for typ, tools of inspectors
        if tools.length != @get('num_plots')
          continue
        proxy = new _ToolProxy({tools: tools})
        @get('inspectors').tools.push(proxy)<commit_msg>grid tool bar manager fixes<commit_after>
define [
  "underscore"
  "backbone"
  "./build_views"
  "./continuum_view"
  "./collection"
  "./has_properties"
  "./logging"
  "./tool_manager"
  "./plot_template"
  "renderer/properties"
], (_, Backbone, build_views, ContinuumView, Collection, HasProperties, Logging, ToolManager, plot_template, Properties) ->

  logger = Logging.logger

  class _ToolProxy extends Backbone.Model
    attrs_and_props: () ->
      return @attributes.tools[0].attrs_and_props()

    get: (attr) ->
      return @attributes.tools[0].get(attr)

    set: (attr, value) ->
      super(attr, value)
      for tool in @attributes.tools
        tool.set(attr, value)

  class GridToolManager extends ToolManager.Model

    _init_tools: () ->
      # Note: no call to super(), intentionally

      inspectors = {}
      actions = {}
      gestures = {}

      for tm in @get('tool_managers')

        for et, info of tm.get('gestures')
          if et not of gestures
            gestures[et] = {}
          for tool in info.tools
            if tool.type not of gestures[et]
              gestures[et][tool.type] = []
            gestures[et][tool.type].push(tool)

        for tool in tm.get('inspectors')
          if tool.type not of inspectors
            inspectors[tool.type] = []
          inspectors[tool.type].push(tool)

        for tool in @get('actions')
          if tool.type not of actions
            actions[tool.type] = []
          actions[tool.type].push(tool)

      for et of gestures
        for typ, tools of gestures[et]
          if tools.length != @get('num_plots')
            continue
          proxy = new _ToolProxy({tools: tools})
          @get('gestures')[et].tools.push(proxy)
          @listenTo(proxy, 'change:active', _.bind(@_active_change, proxy))

      for typ, tools of actions
        if tools.length != @get('num_plots')
          continue
        proxy = new _ToolProxy({tools: tools})
        @get('actions').tools.push(proxy)

      for typ, tools of inspectors
        if tools.length != @get('num_plots')
          continue
        proxy = new _ToolProxy({tools: tools})
        @get('inspectors').tools.push(proxy)

      for et, info of @get('gestures')
        tools = info.tools
        if tools.length == 0
          continue
        info.tools = _.sortBy(tools, (tool) -> tool.get('default_order'))
        info.tools[0].set('active', true)
{'fraction_non_alphanumeric': 0.13173777315296567, 'fraction_numerical': 0.0016649323621227888, 'mean_word_length': 2.2671651937457513, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 16, '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': '7546486', 'n_tokens_mistral': 1459, 'n_tokens_neox': 1434, 'n_words': 345}