 
   moveSelectionDown: ->
     @querySelector(".change.selected").nextElementSibling?.click()
+
+  stageAll: =>
+    paths = $(@).find('.unstaged .change').map( ->
+      this.dataset['path']
+    ).get()
+
+    @changes.stageAllPaths(paths).then =>
+      @renderChanges()
+    false
+
+  unstageAll: =>
+    paths = $(@).find('.staged .change').map( ->
+      this.dataset['path']
+    ).get()
+
+    @changes.unstageAllPaths(paths).then =>
+      @renderChanges()
+    false
 
   unwatch: ->
     if @watchSubscription?

class ChangesView extends HTMLElement
  createdCallback: ->
    atom.commands.add 'git-experiment-changes-view .data',
      'core:move-down': => @moveSelectionDown()
      'core:move-up': => @moveSelectionUp()

    @changes = new GitChanges()

    @innerHTML = BaseTemplate
    @unstagedChangesNode = @querySelector('.unstaged.files')
    @stagedChangesNode = @querySelector('.staged.files')
    @diffsNode = @querySelector('.diffs')

    $(@).on 'click', '.change', (e) =>
      el = e.currentTarget
      path = el.dataset['path']
      state = el.dataset['state']
      @renderChangeDetail(path, state)

    $(@).on 'click', '.change .btn', (e) =>
      el = $(e.target).closest('.change').get(0)

          @renderChanges()
        , 10)

  commit: ->
    commitPromise = @changes.commit(@commitMessageModel.getText()).then =>
      @commitMessageModel.setText('')
      @renderChanges()

module.exports = document.registerElement 'git-experiment-changes-view', prototype: ChangesView.prototype
