   convertLineEndings: (editor) ->
     editorElement = atom.views.getView(editor)
     atom.commands.dispatch(editorElement, 'line-ending-selector:convert-to-LF')
-
 
   popupNoConnectionWarning: ->
     noConnectionPopup = document.createElement 'div'

    @workspaceView = atom.views.getView(atom.workspace)
    @projectPath = atom.project.getPaths()[0]
    @handleEvents()

  expandTreeView: ->
    atom.commands.dispatch(@workspaceView, 'tree-view:reveal-active-file')

    return unless inCodeDir

    @popupNoConnectionWarning() if @connectionState is 'closed'
    @sendLocalEvent @localSave(editor.project, file, buffer)

  onCoreConfirm: (event) ->
    @syncAdditions()
    @syncMoves()

  onTreeViewRemove: (event) ->
    {target} = event
    path = target.dataset.path || target.firstChild.dataset.path
    return if fs.existsSync(path)

    @sendLocalEvent @localRemove(path)

  onTreeViewAdd: (event) =>
    @recentTreeViewCommand = event.type
    @listTreeAtAdd = fs.listTreeSync(@projectPath)

  onTreeViewMove: (event) =>
    {target, type} = event
    @recentTreeViewCommand = type
    @listTreeAtMove = fs.listTreeSync(@projectPath)
    @pathAtMove = target.dataset.path || target.firstChild.dataset.path

  syncAdditions: ->
    prevEntries = @listTreeAtAdd
    @listTreeAtAdd = null

    return unless @recentTreeViewCommand.match(/tree-view:add/)
    @recentTreeViewCommand = null

    return unless prevEntries?

    newEntries = _.difference(fs.listTreeSync(@projectPath), prevEntries)
    return unless newEntries.length

    deepestPath = _.max(newEntries, (entry) -> entry.length)
    @sendLocalEvent @localAddFile(deepestPath) if fs.isFileSync(deepestPath)
    @sendLocalEvent @localAddFolder(deepestPath) if fs.isDirectorySync(deepestPath)

  syncMoves: ->
    prevPath = @pathAtMove
    prevEntries = @listTreeAtMove
    @pathAtMove = null
    @listTreeAtMove = null

    debugger
    return unless @recentTreeViewCommand is 'tree-view:move'
    @recentTreeViewCommand = null

    console.log '>>> 3'
    return unless prevPath? and prevEntries?

    console.log '>>> 2'
    newEntries = _.difference(fs.listTreeSync(@projectPath), prevEntries)
    return unless newEntries.length

    console.log '>>> 1'
    deepestPath = _.max(newEntries, (entry) -> entry.length)
    console.log "prev: #{prevPath} new: #{deepestPath}"
    @sendLocalEvent @localMove(prevPath, deepestPath)

  sendLocalEvent: (payload) ->
    ipc.send 'fs-local-event', JSON.stringify(payload)

  localAddFile: (path) ->
    action: 'local_add_file'
    project:
      path: @formatPath(@projectPath)
    file:
      path: @formatPath(path)

  localAddFolder: (path) ->
    action: 'local_add_folder'
    project:
      path: @formatPath(@projectPath)
    file:
      path: @formatPath(path)

  localSave: (project, file, buffer) ->
    action: 'local_save'
    project:
      path: @formatPath(project.getPaths()[0])
    file:
      path: @formatPath(file.path)
      digest: file.digest,
    buffer:
      content: window.btoa(unescape(encodeURIComponent(buffer.getText())))

  localRemove: (path) ->
    action: 'local_delete'
    project:
      path: @formatPath(@projectPath)
    file:
      path: @formatPath(path)

  localMove: (source, target) ->
    console.log '>>> 0'
    action: 'local_move'
    project:
      path: @formatPath(@projectPath)
    file:
      path: @formatPath(target)
    from: @formatPath(source)

  formatPath: (path) ->
    if path.match(/:\\/)
