 
     @subscribe atom.workspaceView, 'pane-container:active-pane-item-changed', =>
       @selectActiveFile()
-    @subscribe atom.project, 'path-changed', => @updateRoot()
+    @subscribe atom.project, 'path-changed', =>
+      @updateRoot()
     @subscribe atom.config.observe 'tree-view.hideVcsIgnoredFiles', callNow: false, =>
       @updateRoot()
     @subscribe atom.config.observe 'tree-view.hideIgnoredNames', callNow: false, =>

      @updateRoot() if atom.config.get('tree-view.hideIgnoredNames')
    @subscribe atom.config.observe 'tree-view.showOnRightSide', callNow: false, (newValue) =>
      @onSideToggled(newValue)

    process.nextTick =>
      @onStylesheetsChanged()
      @subscribe atom.themes, 'stylesheets-changed', _.debounce(@onStylesheetsChanged, 100)

    @updateRoot(state.directoryExpansionStates)
    @selectEntry(@root) if @root?

    @selectEntryForPath(state.selectedPath) if state.selectedPath
    @focusAfterAttach = state.hasFocus
    @scrollTopAfterAttach = state.scrollTop if state.scrollTop
    @scrollLeftAfterAttach = state.scrollLeft if state.scrollLeft
    @attachAfterProjectPathSet = state.attached and not atom.project.getPath()
    @width(state.width) if state.width > 0
    @attach() if state.attached

  afterAttach: (onDom) ->
    @focus() if @focusAfterAttach
    @scroller.scrollLeft(@scrollLeftAfterAttach) if @scrollLeftAfterAttach > 0
    @scrollTop(@scrollTopAfterAttach) if @scrollTopAfterAttach > 0

  beforeRemove: ->
    @resizeStopped()

  serialize: ->
    directoryExpansionStates: @root?.directory.serializeExpansionStates()
    selectedPath: @selectedEntry()?.getPath()
    hasFocus: @hasFocus()
    attached: @hasParent()
    scrollLeft: @scroller.scrollLeft()
    scrollTop: @scrollTop()
    width: @width()

  deactivate: ->
    @remove()

  toggle: ->
    if @isVisible()

    scrollTopAfterAttach = -1
    selectedPath = null

    @handleEvents()

    process.nextTick =>
      @onStylesheetsChanged()
      @subscribe atom.themes, 'stylesheets-changed', _.debounce(@onStylesheetsChanged, 100)

    @updateRoot(state.directoryExpansionStates)
    @selectEntry(@root) if @root?

    @selectEntryForPath(state.selectedPath) if state.selectedPath
    @focusAfterAttach = state.hasFocus
    @scrollTopAfterAttach = state.scrollTop if state.scrollTop
    @scrollLeftAfterAttach = state.scrollLeft if state.scrollLeft
    @attachAfterProjectPathSet = state.attached and not atom.project.getPath()
    @width(state.width) if state.width > 0
    @attach() if state.attached

  afterAttach: (onDom) ->
    @focus() if @focusAfterAttach
    @scroller.scrollLeft(@scrollLeftAfterAttach) if @scrollLeftAfterAttach > 0
    @scrollTop(@scrollTopAfterAttach) if @scrollTopAfterAttach > 0

  beforeRemove: ->
    @resizeStopped()

  serialize: ->
    directoryExpansionStates: @root?.directory.serializeExpansionStates()
    selectedPath: @selectedEntry()?.getPath()
    hasFocus: @hasFocus()
    attached: @hasParent()
    scrollLeft: @scroller.scrollLeft()
    scrollTop: @scrollTop()
    width: @width()

  deactivate: ->
    @remove()

  handleEvents: ->
    @on 'dblclick', '.tree-view-resize-handle', =>
      @resizeToFitContent()
    @on 'click', '.entry', (e) =>
      @entryClicked(e) unless e.shiftKey or e.metaKey or e.ctrlKey
    @on 'mousedown', '.entry', (e) =>
      @onMouseDown(e)

    # turn off default scrolling behavior from ScrollView
    @off 'core:move-up'
