       if host is 'editor'
         new AtomPerl6EditorToolsView(editorId: pathname.substring(1))
       else
-        console.log "Not an editor?"
+        alert "Not an editor?"
 
     options =
       split: 'right'
+      
+    err = (err) ->
+      throw err if err 
+      console.log("It's saved!");
+    fs.writeFile 'Sample.pm6', editor.getText(), err
+
     atom.workspace.open("perl6-pod-preview://editor/#{editor.id}", options).then (podPreviewEditor) ->
-      podPreviewEditor.setText "Hello world!"
       #TODO File::Which perl6
       command = 'perl6'
       args    = ['--doc=HTML', 'Sample.pm6']
       stdout  = (output) ->
-        #console.log(output)
+        console.log(output)
+        atom.notifications.addSuccess(output)
         podPreviewEditor.setText output
-        #atom.notifications.addSuccess(output)
+        alert("Done!")
       exit    = (code) ->
         console.log("perl6 --doc exited with #{code}")
-        atom.notifications.addInfo("perl6 --doc exited with #{code}")
+        atom.notifications.addInfo("'#{command} #{args.join(" ")}' exited with #{code}")
       process = new BufferedProcess({command, args, stdout, exit})
 
 
-    if @modalPanel.isVisible()
-      @modalPanel.hide()
-    else
-      @modalPanel.show()
+    #if @modalPanel.isVisible()
+    #  @modalPanel.hide()
+    #else
+    #  @modalPanel.show()

AtomPerl6EditorToolsView = require './atom-perl6-editor-tools-view'
{CompositeDisposable}    = require 'atom'
{BufferedProcess}        = require 'atom'

module.exports = AtomPerl6EditorTools =
  atomPerl6EditorToolsView: null
  modalPanel: null
  subscriptions: null

  activate: (state) ->
    @atomPerl6EditorToolsView = new AtomPerl6EditorToolsView(state.atomPerl6EditorToolsViewState)
    @modalPanel = atom.workspace.addTopPanel(item: @atomPerl6EditorToolsView.getElement(), visible: false)

    # Events subscribed to in atom's system can be easily cleaned up with a CompositeDisposable
    @subscriptions = new CompositeDisposable

        return

      return unless protocol is 'perl6-pod-preview:'

      alert(pathname)
      
      try
        pathname = decodeURI(pathname) if pathname
