 
   toggleDebugger: ->
     _debugger.toggle()
+
+  saveAll: ->
+    # code shamelessly copied from https://github.com/BrownBear2/atom-save-all/blob/master/lib/atom-save-all.coffee
+    current = atom.workspace?.getActiveEditor?()
+    current ?= atom.workspace?.getActiveTextEditor?()
+    if current? and current.getURI?()? and current.isModified?() and paneItem?.getPath?()? and (!fs.existsSync(paneItem.getPath()) or !fs.statSync(current.getPath()).isFile())
+      current.save()
+
+    for paneItem in atom.workspace.getPaneItems()
+      if paneItem.getURI?()? and paneItem.isModified?() and paneItem?.getPath?()? and fs.existsSync(paneItem.getPath()) and fs.statSync(paneItem.getPath()).isFile()
+        paneItem.save()

{Debugger} = require './debugger'
logger = require './logger'
os = require 'os'

processManager = null
_debugger = null

    @disposables.add _debugger.subscribeDisposable 'disconnected', ->
      #atom.notifications.addInfo('finish debugging : )')
    @disposables.add atom.commands.add('atom-workspace', {
      'node-debugger:start-resume': => @startOrResume()
      'node-debugger:start-active-file': => @startActiveFile()
      'node-debugger:stop': => @stop()
      'node-debugger:toggle-breakpoint': => @toggleBreakpoint()
      'node-debugger:step-next': => @stepNext()
      'node-debugger:step-in': => @stepIn()
      'node-debugger:step-out': => @stepOut()
      'node-debugger:attach': => @attach()
      'node-debugger:toggle-debugger': => @toggleDebugger()
    })

  startOrResume: ->
    if _debugger.isConnected()
      _debugger.reqContinue()
    else
      @saveAll()
      _debugger.start()

  attach: ->
    return if _debugger.isConnected()
    _debugger.attach()

  startActiveFile: ->
    return if _debugger.isConnected()
    @saveAll()
    _debugger.startActiveFile()

  toggleBreakpoint: ->
    editor = atom.workspace.getActiveTextEditor()
    path = editor.getPath()
    {row} = editor.getCursorBufferPosition()
    _debugger.breakpointManager.toggleBreakpoint editor, path, row

  stepNext: ->
    _debugger.step('next', 1) if _debugger.isConnected()

  stepIn: ->
    _debugger.step('in', 1) if _debugger.isConnected()

  stepOut: ->
    _debugger.step('out', 1) if _debugger.isConnected()

  stop: ->
    _debugger.cleanup()

  deactivate: ->
