   detach: ->
     @scrollTopAfterAttach = @scrollTop()
     super
+
+  hasFocus: ->
+    @is(':focus')
 
   entryClicked: (e) ->
     entry = $(e.currentTarget).view()

  serialize: ->
    directoryExpansionStates: @root?.serializeEntryExpansionStates()
    selectedPath: @selectedEntry()?.getPath()
    hasFocus: @is(':focus')
    attached: @hasParent()
    scrollTop: @scrollTop()


    @on 'tree-view:add', => @add()
    @on 'tree-view:remove', => @removeSelectedEntry()
    @on 'tree-view:directory-modified', =>
      if @hasFocus()
        @selectEntryForPath(@selectedPath) if @selectedPath
      else
        @selectActiveFile()
