<commit_before>{CompositeDisposable} = require 'atom'
{$, $$, View} = require 'atom-space-pen-views'
_ = require 'underscore-plus'
Grim = require 'grim'

{getSelectorDeprecations, getSelectorDeprecationsCount} = require './helpers'

module.exports =
class DeprecationCopStatusBarView extends View
  @content: ->
    @div class: 'deprecation-cop-status inline-block text-warning', tabindex: -1, =>
      @span class: 'icon icon-alert'
      @span class: 'deprecation-number', outlet: 'deprecationNumber', '0'

  lastLength: null
  toolTipDisposable: null

  initialize: ->
    @subscriptions = new CompositeDisposable
    @subscriptions.add Grim.on 'updated', @update
    @subscriptions.add atom.packages.onDidLoadPackage @updateDeprecatedSelectorCount
    @subscriptions.add atom.packages.onDidUnloadPackage @updateDeprecatedSelectorCount
    @subscriptions.add atom.packages.onDidActivatePackage @updateDeprecatedSelectorCount

  destroy: ->
    @subscriptions.dispose()
    @detach()

  attached: ->
    @update()
    @click ->
      workspaceElement = atom.views.getView(atom.workspace)
      atom.commands.dispatch workspaceElement, 'deprecation-cop:view'

  getDeprecatedSelectorCount: ->
    @deprecatedSelectorCount ?= getSelectorDeprecationsCount()

  getDeprecatedCallCount: ->
    Grim.getDeprecations().map((d) -> d.getStackCount()).reduce(((a, b) -> a + b), 0)

  updateDeprecatedSelectorCount: =>
    @deprecatedSelectorCount = null
    @update()

  update: =>
    length = @getDeprecatedCallCount() + @getDeprecatedSelectorCount()

    return if @lastLength == length

    @lastLength = length
    @deprecationNumber.text(length)
    @toolTipDisposable?.dispose()
    @toolTipDisposable = atom.tooltips.add @element, title: "#{_.pluralize(length, 'call')} to deprecated methods"

    if length == 0
      @hide()
    else
      @show()
<commit_msg>Update status bar counter when local config files change<commit_after>{CompositeDisposable, File} = require 'atom'
{$, $$, View} = require 'atom-space-pen-views'
_ = require 'underscore-plus'
Grim = require 'grim'

{getSelectorDeprecations, getSelectorDeprecationsCount} = require './helpers'

module.exports =
class DeprecationCopStatusBarView extends View
  @content: ->
    @div class: 'deprecation-cop-status inline-block text-warning', tabindex: -1, =>
      @span class: 'icon icon-alert'
      @span class: 'deprecation-number', outlet: 'deprecationNumber', '0'

  lastLength: null
  toolTipDisposable: null

  initialize: ->
    @subscriptions = new CompositeDisposable
    @subscriptions.add Grim.on 'updated', @update
    @subscriptions.add atom.packages.onDidLoadPackage @updateDeprecatedSelectorCount
    @subscriptions.add atom.packages.onDidUnloadPackage @updateDeprecatedSelectorCount
    @subscriptions.add atom.packages.onDidActivatePackage @updateDeprecatedSelectorCount
    
    @subscriptions.add atom.keymaps.onDidReloadKeymap (event) => 
      @updateDeprecatedSelectorCount() if event.path is atom.keymaps.getUserKeymapPath()
    
    try
      userStylesheetFile = new File(atom.styles.getUserStyleSheetPath())
      @subscriptions.add userStylesheetFile.onDidChange @updateDeprecatedSelectorCount
    catch
      

  destroy: ->
    @subscriptions.dispose()
    @detach()

  attached: ->
    @update()
    @click ->
      workspaceElement = atom.views.getView(atom.workspace)
      atom.commands.dispatch workspaceElement, 'deprecation-cop:view'

  getDeprecatedSelectorCount: ->
    @deprecatedSelectorCount ?= getSelectorDeprecationsCount()

  getDeprecatedCallCount: ->
    Grim.getDeprecations().map((d) -> d.getStackCount()).reduce(((a, b) -> a + b), 0)

  updateDeprecatedSelectorCount: =>
    @deprecatedSelectorCount = null
    @update()

  update: =>
    length = @getDeprecatedCallCount() + @getDeprecatedSelectorCount()

    return if @lastLength == length

    @lastLength = length
    @deprecationNumber.text(length)
    @toolTipDisposable?.dispose()
    @toolTipDisposable = atom.tooltips.add @element, title: "#{_.pluralize(length, 'call')} to deprecated methods"

    if length == 0
      @hide()
    else
      @show()

{'fraction_non_alphanumeric': 0.11787533349502789, 'fraction_numerical': 0.0019403347077370846, 'mean_word_length': 4.246819338422392, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 28, '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': '3388870', 'n_tokens_mistral': 1266, 'n_tokens_neox': 1214, 'n_words': 247}