       watcher.destruct()
     delete @watchers
 
-    atom.workspaceView.off @renameCommand, @onRename
-    atom.workspaceView.off @doneCommand, @onDone
+    @disposables.dispose()
+    @disposables = null
 
   serialize: ->
 

Watcher = require './watcher'
ModuleManager = require './module_manager'
{ packages: packageManager } = atom
d = (require 'debug/browser') 'refactor'

module.exports =
new class Main

  renameCommand: 'refactor:rename'
  doneCommand: 'refactor:done'

  config:
    highlightError:

  activate: (state) ->
    d 'activate'
    @moduleManager = new ModuleManager
    @disposables = new CompositeDisposable
    @watchers = []

    @disposables.add atom.workspace.observeTextEditors @onCreated
    @disposables.add atom.commands.add 'atom-text-editor', 'refactor:rename', @onRename
    @disposables.add atom.commands.add 'atom-text-editor', 'refactor:done', @onDone

  deactivate: ->
    @moduleManager.destruct()
