<commit_before>{CompositeDisposable, Disposable} = require 'event-kit'
{AncestorsMethods, SpacePenDSL, EventsDelegation} = require 'atom-utils'

class FinderTool extends HTMLElement
  EventsDelegation.includeInto(this)
  SpacePenDSL.includeInto(this)

  debug: false
  nameWidth: 200
  sizeWidth: 80
  mdateWidth: 180

  @content: ->
    @tag 'atom-panel', class: 'tree-view-finder-tool tool-panel', =>
      @div outlet: 'toolBar', class: 'btn-group', =>
        @div class: 'btn disable', id: 'back', '<'
        @div class: 'btn disable', id: 'forth', '>'
        @div class: 'btn disable', id: 'home', 'Home'
        @div outlet: 'name', class: 'btn', id: 'name', ' '
        @div outlet: 'name-rsz', class: 'btn rsz', id: 'name-rsz', ''
        @div outlet: 'size', class: 'btn', id: 'size', 'Size'
        @div outlet: 'size-rsz', class: 'btn rsz', id: 'size-rsz', ''
        @div outlet: 'mdate', class: 'btn', id: 'mdate', 'Date Modified'
        @div outlet: 'mdate-rsz', class: 'btn rsz', id: 'mdate-rsz', ''

  initialize: (treeViewFinder) ->
    console.log "finder-tool: initialize", treeViewFinder if @debug
    @treeViewFinder = treeViewFinder
    @subscriptions = new CompositeDisposable

    @subscriptions.add @subscribeTo @toolBar, '.btn',
      'click': (e) =>
        console.log "finder-tool: click:", e.target.id, e if @debug

    state = treeViewFinder?.state?.finderTool
    if state
      console.log 'finde-tool: initiliaze: state =', state if @debug
      if state.nameWidth
        @nameWidth = state.nameWidth
      if state.sizeWidth
        @sizeWidth = state.sizeWidth
      if state.mdateWidth
        @mdateWidth = state.mdateWidth
      
    @name.style.width = @nameWidth + 'px'
    @size.style.width = @sizeWidth + 'px'
    @mdate.style.width = @mdateWidth + 'px'
    @toolBar.style.width = @nameWidth + @sizeWidth + @mdateWidth + 200 + 'px'

    drag = null

    @subscriptions.add @subscribeTo @toolBar, '.rsz',
      'mousedown': (e) =>
        console.log "finder-tool: drag:", e.target.id, e if @debug
        if e.target.id == 'name-rsz'
          target = @name
        if e.target.id == 'size-rsz'
          target = @size
        if e.target.id == 'mdate-rsz'
          target = @mdate
        return if not target
        drag = { 
          x: e.clientX, 
          y: e.clientY,
          target: target,
          originalWidth: target.offsetWidth,<commit_msg>Tweak tool bar total width and trivial refactoring.<commit_after>{CompositeDisposable, Disposable} = require 'event-kit'
{AncestorsMethods, SpacePenDSL, EventsDelegation} = require 'atom-utils'

class FinderTool extends HTMLElement
  EventsDelegation.includeInto(this)
  SpacePenDSL.includeInto(this)

  debug: false
  nameWidth: 200
  sizeWidth: 80
  mdateWidth: 180

  @content: ->
    @tag 'atom-panel', class: 'tree-view-finder-tool tool-panel', =>
      @div outlet: 'toolBar', class: 'btn-group', =>
        @div class: 'btn disable', id: 'back', '<'
        @div class: 'btn disable', id: 'forth', '>'
        @div class: 'btn disable', id: 'home', 'Home'
        @div outlet: 'name', class: 'btn', id: 'name', ' '
        @div outlet: 'name-rsz', class: 'btn rsz', id: 'name-rsz', ''
        @div outlet: 'size', class: 'btn', id: 'size', 'Size'
        @div outlet: 'size-rsz', class: 'btn rsz', id: 'size-rsz', ''
        @div outlet: 'mdate', class: 'btn', id: 'mdate', 'Date Modified'
        @div outlet: 'mdate-rsz', class: 'btn rsz', id: 'mdate-rsz', ''

  initialize: (treeViewFinder) ->
    console.log "finder-tool: initialize", treeViewFinder if @debug
    @treeViewFinder = treeViewFinder
    @subscriptions = new CompositeDisposable

    @subscriptions.add @subscribeTo @toolBar, '.btn',
      'click': (e) =>
        console.log "finder-tool: click:", e.target.id, e if @debug

    state = treeViewFinder?.state?.finderTool
    if state
      console.log 'finde-tool: initiliaze: state =', state if @debug
      if state.nameWidth
        @nameWidth = state.nameWidth
      if state.sizeWidth
        @sizeWidth = state.sizeWidth
      if state.mdateWidth
        @mdateWidth = state.mdateWidth
      
    @name.style.width = @nameWidth + 'px'
    @size.style.width = @sizeWidth + 'px'
    @mdate.style.width = @mdateWidth + 'px'
    @toolBar.style.width = @nameWidth + @sizeWidth + @mdateWidth + 106 + 'px'

    drag = null

    getTargetRsz = (e) =>
      return @name if e.target.id == 'name-rsz'
      return @size if e.target.id == 'size-rsz'
      return @mdate if e.target.id == 'mdate-rsz'
      return null
        
    @subscriptions.add @subscribeTo @toolBar, '.rsz',
      'dblclick': (e) =>
        console.log "finder-tool: double click:", e.target.id, e if @debug
        # XXX, you can invoke some function here...
      'mousedown': (e) =>
        console.log "finder-tool: drag:", e.target.id, e if @debug
        return if not target = getTargetRsz(e)
        drag = { 
          x: e.clientX, 
          y: e.clientY,
          target: target,
          originalWidth: target.offsetWidth,
{'fraction_non_alphanumeric': 0.1501686173378298, 'fraction_numerical': 0.004364213449712359, 'mean_word_length': 2.693772893772894, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 19, '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': '1965147', 'n_tokens_mistral': 1729, 'n_tokens_neox': 1671, 'n_words': 444}