<commit_before>{CompositeDisposable} = require 'atom'
{View} = require 'space-pen'

module.exports = class ToolBarButtonView extends View
  @content: ->
    @button class: 'btn btn-default tool-bar-btn'

  initialize: (options) ->
    @subscriptions = new CompositeDisposable

    @priority = options.priority

    if options.tooltip
      @prop 'title', options.tooltip
      toolbarPosition = atom.config.get('tool-bar.position')
      tooltipPlacement = (toolbarPosition is "Top")    and "bottom" or
                         (toolbarPosition is "Right")  and "left"   or
                         (toolbarPosition is "Bottom") and "top"    or
                         (toolbarPosition is "Left")   and "right"
      @subscriptions.add atom.tooltips.add(
        this,
        {
          title: options.tooltip
          placement: tooltipPlacement
        }
      )

    if options.iconset
      @addClass "#{options.iconset} #{options.iconset}-#{options.icon}"
    else
      @addClass "icon-#{options.icon}"

    @on 'click', =>
      if not @hasClass 'disabled'
        if typeof options.callback is 'string'
          atom.commands.dispatch @getPreviouslyFocusedElement(), options.callback
        else
          options.callback(options.data, @getPreviouslyFocusedElement())

    @on 'mouseover', =>
      @storeFocusedElement()

  setEnabled: (enabled) ->
    if enabled
      @removeClass 'disabled'
    else
      @addClass 'disabled'

  destroy: ->
    @subscriptions.dispose()

  getPreviouslyFocusedElement: ->
    if @previouslyFocusedElement and @previouslyFocusedElement.nodeName isnt 'BODY'
      @eventElement = @previouslyFocusedElement
    else
      @eventElement = atom.views.getView(atom.workspace)

  storeFocusedElement: ->
    if not document.activeElement.classList.contains 'tool-bar-btn'
      @previouslyFocusedElement = document.activeElement<commit_msg>Move tooltip placement deduction to a function<commit_after>{CompositeDisposable} = require 'atom'
{View} = require 'space-pen'

module.exports = class ToolBarButtonView extends View
  @content: ->
    @button class: 'btn btn-default tool-bar-btn'

  initialize: (options) ->
    @subscriptions = new CompositeDisposable

    @priority = options.priority

    if options.tooltip
      @prop 'title', options.tooltip
      @subscriptions.add atom.tooltips.add(this,
        title: options.tooltip
        placement: @getTooltipPlacement
      )

    if options.iconset
      @addClass "#{options.iconset} #{options.iconset}-#{options.icon}"
    else
      @addClass "icon-#{options.icon}"

    @on 'click', =>
      if not @hasClass 'disabled'
        if typeof options.callback is 'string'
          atom.commands.dispatch @getPreviouslyFocusedElement(), options.callback
        else
          options.callback(options.data, @getPreviouslyFocusedElement())

    @on 'mouseover', =>
      @storeFocusedElement()

  setEnabled: (enabled) ->
    if enabled
      @removeClass 'disabled'
    else
      @addClass 'disabled'

  destroy: ->
    @subscriptions.dispose()

  getPreviouslyFocusedElement: ->
    if @previouslyFocusedElement and @previouslyFocusedElement.nodeName isnt 'BODY'
      @eventElement = @previouslyFocusedElement
    else
      @eventElement = atom.views.getView(atom.workspace)

  storeFocusedElement: ->
    if not document.activeElement.classList.contains 'tool-bar-btn'
      @previouslyFocusedElement = document.activeElement

  getTooltipPlacement: ->
    toolbarPosition = atom.config.get 'tool-bar.position'
    return toolbarPosition is "Top"    and "bottom" or
           toolbarPosition is "Right"  and "left"   or
           toolbarPosition is "Bottom" and "top"    or
           toolbarPosition is "Left"   and "right"

{'fraction_non_alphanumeric': 0.10409419320310409, 'fraction_numerical': 0.0, 'mean_word_length': 2.8655635987590484, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 20, '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': '904095', 'n_tokens_mistral': 1067, 'n_tokens_neox': 1030, 'n_words': 246}