 
 ;; New document
 
-(defn new-document [app owner]
+(defn new-document-click [app]
+  (put! (:channel @app) [:new nil]))
+
+(defn new-button [app owner]
   (reify
     om/IRender
     (render [_]
-      (dom/span #js {:id "new-document"} "+"))))
+      (dom/span #js {:id "new-document"
+                     :onClick #(new-document-click app)} "+"))))
 
 ;; Left menu
 


;; The main app

(defn change-document [app title]
  (let [input (p/get-document title)]
    (om/update! app :input input)

  
(defn remove-document [app title]
  (p/remove-document title)
  (om/update! app :titles (p/get-all-titles))
  (when (= (:title @app) title)
    (reset-document-state! app)))

(defn dispatch [command params app]
  (case command
    :save   (save-document app)
    :rename (rename-document app params)
    :remove (remove-document app params)
    :change (change-document app params)
    :new    (new-document app)))

(defn listen [el type app]
  (events/listen el type
