 FileDialog = require("./file-dialog.coffee")
 
 fileLoadedBus = new Bacon.Bus()
-renameBus = new Bacon.Bus()
-
 initialApplication = if localStorage.application
     JSON.parse(localStorage.application)
   else

$ = window.$ = require("jquery")
Bacon = window.Bacon = require("baconjs")
_ = require("lodash")
$.fn.asEventStream = Bacon.$.asEventStream
examples = require("./examples.coffee")

storage = Storage(
  applicationP,
  menubar.itemClickE("file-save")
  renameE
)
storage.saveResultE.log() # TODO: replace with a feedback
storage.renameResultE.log() # TODO: replace with a feedback

promptNewName = (suggestion) ->
  newName = prompt("Enter new name", suggestion) || suggestion
  Bacon.once(newName)

forkE = menubar.itemClickE("file-fork")
  .map(applicationP)
  .flatMap (application) -> 
    promptNewName(application.name + " fork")
      .map (newName) ->
        application = _.clone(application)
        application.name = newName
        application

fileLoadedBus.plug(forkE)

