<commit_before>class EnvironmentItem extends KDDiaObject

  constructor:(options={}, data)->

    options.cssClass       = KD.utils.curry "environments-item", \
                             options.cssClass
    options.bind           = KD.utils.curry "contextmenu", options.bind
    options.jointItemClass = EnvironmentItemJoint
    options.draggable      = no
    options.colorTag       ?= "#a2a2a2"

    super options, data

  contextMenuItems:->

    colorSelection = new ColorSelection
      selectedColor : @getOption 'colorTag'
    colorSelection.on "ColorChanged", @bound 'setColorTag'

    items =
      'Delete'    :
        separator : yes
        action    : 'delete'
      'Unfocus'   :
        separator : yes
        action    : 'unfocus'
      customView  : colorSelection

    return items

  contextMenu:(event)->

    KD.utils.stopDOMEvent event

    menuItems = @contextMenuItems()
    return  unless menuItems

    ctxMenu = new JContextMenu
      menuWidth   : 200
      delegate    : @
      x           : event.pageX
      y           : event.pageY
      lazyLoad    : yes
    ,
      menuItems

    ctxMenu.on 'ContextMenuItemReceivedClick', (item) =>
      {action} = item.getData()
      ctxMenu.destroy()  if @["cm#{action}"]?
      @["cm#{action}"]?()

  # - Context Menu Actions - #

  cmdelete : -> @confirmDestroy?()
  cmunfocus: -> @parent.emit 'UnhighlightDias'

  setColorTag : (color, save = yes) ->

    @getElement().style.borderLeftColor = color
    @options.colorTag                   = color
    @saveColorTag color  if save
    @parent.emit 'UpdateScene'

  saveColorTag:(color)->

    return unless @parent.appStorage

    colorTags = (@parent.appStorage.getValue 'colorTags') or {}
    name      = @constructor.name
    title     = pipedVmName @getData().title
    colorTags["#{name}-#{title}"] = color

    @parent.appStorage.setValue 'colorTags', colorTags

  loadColorTag:->

    colorTags = (@parent.appStorage.getValue 'colorTags') or {}
    name      = @constructor.name
    title     = pipedVmName @getData().title
    color     = colorTags["#{name}-#{title}"]

    @setColorTag color  if color

  pipedVmName = (vmName)-> vmName.replace /\./g, '|'

  click:(event)->
    if $(event.target).is ".chevron"
      @contextMenu event
      return no
    super

  viewAppended:->
    super

    @setColorTag @getOption('colorTag'), no
    @parent.appStorage?.ready @bound 'loadColorTag'

  pistachio:->
    """
      <div class='details'>
        {h3{#(title)}}
        {{#(description)}}
        <span class='chevron'></span>
      </div>
    """
<commit_msg>Allow mouseDown events if object is draggable<commit_after>class EnvironmentItem extends KDDiaObject

  constructor:(options={}, data)->

    options.cssClass       = KD.utils.curry "environments-item", \
                             options.cssClass
    options.bind           = KD.utils.curry "contextmenu", options.bind
    options.jointItemClass = EnvironmentItemJoint
    options.draggable      = no
    options.colorTag       ?= "#a2a2a2"

    super options, data

  contextMenuItems:->

    colorSelection = new ColorSelection
      selectedColor : @getOption 'colorTag'
    colorSelection.on "ColorChanged", @bound 'setColorTag'

    items =
      'Delete'    :
        separator : yes
        action    : 'delete'
      'Unfocus'   :
        separator : yes
        action    : 'unfocus'
      customView  : colorSelection

    return items

  contextMenu:(event)->

    KD.utils.stopDOMEvent event

    menuItems = @contextMenuItems()
    return  unless menuItems

    ctxMenu = new JContextMenu
      menuWidth   : 200
      delegate    : @
      x           : event.pageX
      y           : event.pageY
      lazyLoad    : yes
    ,
      menuItems

    ctxMenu.on 'ContextMenuItemReceivedClick', (item) =>
      {action} = item.getData()
      ctxMenu.destroy()  if @["cm#{action}"]?
      @["cm#{action}"]?()

  # - Context Menu Actions - #

  cmdelete : -> @confirmDestroy?()
  cmunfocus: -> @parent.emit 'UnhighlightDias'

  setColorTag : (color, save = yes) ->

    @getElement().style.borderLeftColor = color
    @options.colorTag                   = color
    @saveColorTag color  if save
    @parent.emit 'UpdateScene'

  saveColorTag:(color)->

    return unless @parent.appStorage

    colorTags = (@parent.appStorage.getValue 'colorTags') or {}
    name      = @constructor.name
    title     = pipedVmName @getData().title
    colorTags["#{name}-#{title}"] = color

    @parent.appStorage.setValue 'colorTags', colorTags

  loadColorTag:->

    colorTags = (@parent.appStorage.getValue 'colorTags') or {}
    name      = @constructor.name
    title     = pipedVmName @getData().title
    color     = colorTags["#{name}-#{title}"]

    @setColorTag color  if color

  pipedVmName = (vmName)-> vmName.replace /\./g, '|'


  click:(event)->

    if $(event.target).is ".chevron"
      @contextMenu event
      return no

    super

  viewAppended:->
    super

    @setColorTag @getOption('colorTag'), no
    @parent.appStorage?.ready @bound 'loadColorTag'

  pistachio:->
    """
      <div class='details'>
        {h3{#(title)}}
        {{#(description)}}
        <span class='chevron'></span>
      </div>
    """

{'fraction_non_alphanumeric': 0.12583412774070543, 'fraction_numerical': 0.002669208770257388, 'mean_word_length': 2.3160556257901392, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 37, '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': '2775396', 'n_tokens_mistral': 1639, 'n_tokens_neox': 1563, 'n_words': 334}