       file for file in @__files # returns copy of @__files
 
     add: (file) ->
-      @__files.push file
-      file.progress (progressInfo) =>
-        @__fileProgresses[file] = progressInfo.progress
-        @__singleFileDf.notify @__progressInfo()
+      if file
+        @__files.push file
+        file.progress (progressInfo) =>
+          @__fileProgresses[file] = progressInfo.progress
+          @__singleFileDf.notify @__progressInfo()
+        @onFileAdded.fire file
+
+    removeAll: ->
+      @remove(file) for file in @__files
+
+    # creates copy of group, but not finalized
+    newGroup: ->
+      gr = new ns.FileGroup
+      gr.add(file) for file in @__files
+      gr
 
     remove: (file) ->
-      if (index = files.indexOf(file)) isnt -1
-        file.splice(index, 1)
+      if (index = @__files.indexOf(file)) isnt -1
+        @__files.splice(index, 1)
         # TODO unsubsribe progress
+        @onFileRemoved.fire file
 
     save: ->
       @__finalize()

    constructor: (settings) ->
      @settings = utils.buildSettings settings
      @__files = []

      @__uploadDf = $.Deferred()
      @__infoDf = $.Deferred()

        cb(info)

    __finalize: ->
      unless @finalized
        @finalized = true
        @add = @remove = ->
          throw new Error("group can't be changed after save")
        $.when(@__files...)
          .then(@__uploadDf.resolve, @__uploadDf.reject)
        # if one file fails all fails
        @__uploadDf.fail @cancel

    __createGroup: ->
      # tmp
      return $.when({group_id: '123~4'})

      # df = $.Deferred()
      # @__fileInfos (infos...) ->
      #   data =
      #     pub_key: @settings.publicKey
      #   for info, i in infos
      #     data["file_id[#{i}]"] = info.fileId
      #   $.ajax("#{@settings.urlBase}/group/create/", {data, dataType: 'jsonp'})
      #     .then(df.resolve, df.reject)
      # return df.promise()


