   showDir: (dir) ->
     dirs = @shownDirs().concat dir
     Storage.set @shownDirStorageKey(), dirs
-    @watchDir dir
+    Watcher.watch dir, @watchDir
+
 
   hideDir: (dir) ->
     dirs = _.without @shownDirs(), dir
     Storage.set @shownDirStorageKey(), dirs
-    @unwatchDir dir
-    delete @watcherCallbacks[dir]
+    @unwatchDir dir, @watchDir

    @pane.show()

  shutdown: ->
    @unwatchDir dir for dir, callback of @watcherCallbacks

  shownDirStorageKey: ->
    @.constructor.name + ":" + atomController.path + ":shownDirs"

  watchDir: (dir) ->
    @watcherCallbacks[dir] = Watcher.watch dir, =>
      @pane.reload()

  unwatchDir: (dir) ->
    watcher.unwach dir, @watcherCallbacks[dir]


module.exports =
class Tree extends Extension
  constructor: ->
    KeyBinder.register "tree", @
    KeyBinder.load require.resolve "tree/key-bindings.coffee"

    # watch the root dir
    Watcher.watch atomController.path, @watchDir

    # Hide dirs that no longer exist, watch dirs that do.
    for dir in @shownDirs()
      if not fs.exists dir
        @hideDir dir
      else
        Watcher.watch dir, @watchDir

    @pane = new TreePane @

